merchant

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

commit 80e27a8c6b13b74887ab668397c68b619305cf08
parent fc42920ac83729a3181ff6a27c75b77c05dd1f76
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 22 Jul 2026 03:17:23 +0200

merchantdb: use get_ and iterate_

Diffstat:
Msrc/backend/taler-merchant-depositcheck.c | 14+++++++-------
Msrc/backend/taler-merchant-donaukeyupdate.c | 18+++++++++---------
Msrc/backend/taler-merchant-exchangekeyupdate.c | 10+++++-----
Msrc/backend/taler-merchant-httpd.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c | 38+++++++++++++++++++-------------------
Msrc/backend/taler-merchant-httpd_delete-private-transfers-TID.c | 8++++----
Msrc/backend/taler-merchant-httpd_exchanges.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-exchanges.c | 8++++----
Msrc/backend/taler-merchant-httpd_get-orders-ORDER_ID.c | 20++++++++++----------
Msrc/backend/taler-merchant-httpd_get-private-accounts-H_WIRE.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-accounts.c | 4++--
Msrc/backend/taler-merchant-httpd_get-private-categories-CATEGORY_ID.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_get-private-categories.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-donau.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-groups.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_get-private-incoming-ID.c | 40++++++++++++++++++++--------------------
Msrc/backend/taler-merchant-httpd_get-private-incoming.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_get-private-kyc.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c | 66+++++++++++++++++++++++++++++++++---------------------------------
Msrc/backend/taler-merchant-httpd_get-private-orders.c | 76++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/backend/taler-merchant-httpd_get-private-otp-devices-DEVICE_ID.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-otp-devices.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-pos.c | 20++++++++++----------
Msrc/backend/taler-merchant-httpd_get-private-pots-POT_ID.c | 16++++++++--------
Msrc/backend/taler-merchant-httpd_get-private-pots.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_get-private-products-PRODUCT_ID.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_get-private-products.c | 22+++++++++++-----------
Msrc/backend/taler-merchant-httpd_get-private-reports-REPORT_ID.c | 28++++++++++++++--------------
Msrc/backend/taler-merchant-httpd_get-private-reports.c | 14+++++++-------
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_get-private-templates-TEMPLATE_ID.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-templates.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-tokenfamilies-TOKEN_FAMILY_SLUG.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-tokenfamilies.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-tokens.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_get-private-transfers.c | 22+++++++++++-----------
Msrc/backend/taler-merchant-httpd_get-private-units-UNIT.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-units.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-private-webhooks.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_get-sessions-SESSION_ID.c | 26+++++++++++++-------------
Msrc/backend/taler-merchant-httpd_get-templates-TEMPLATE_ID.c | 32++++++++++++++++----------------
Msrc/backend/taler-merchant-httpd_helper.c | 44++++++++++++++++++++++----------------------
Msrc/backend/taler-merchant-httpd_mfa.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_patch-private-orders-ORDER_ID-forget.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_post-challenge-ID.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_post-management-instances-INSTANCE-auth.c | 8++++----
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-abort.c | 24++++++++++++------------
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-claim.c | 28++++++++++++++--------------
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c | 60++++++++++++++++++++++++++++++------------------------------
Msrc/backend/taler-merchant-httpd_post-orders-ORDER_ID-refund.c | 36++++++++++++++++++------------------
Msrc/backend/taler-merchant-httpd_post-private-accounts-H_WIRE-kycauth.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-private-accounts.c | 4++--
Msrc/backend/taler-merchant-httpd_post-private-categories.c | 12++++++------
Msrc/backend/taler-merchant-httpd_post-private-donau.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-private-orders-ORDER_ID-refund.c | 26+++++++++++++-------------
Msrc/backend/taler-merchant-httpd_post-private-orders.c | 68++++++++++++++++++++++++++++++++++----------------------------------
Msrc/backend/taler-merchant-httpd_post-private-otp-devices.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-private-products-PRODUCT_ID-lock.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_post-private-templates.c | 20++++++++++----------
Msrc/backend/taler-merchant-httpd_post-private-tokenfamilies.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-private-webhooks.c | 10+++++-----
Msrc/backend/taler-merchant-httpd_post-reports-REPORT_ID.c | 14+++++++-------
Msrc/backend/taler-merchant-httpd_post-templates-TEMPLATE_ID.c | 24++++++++++++------------
Msrc/backend/taler-merchant-kyccheck.c | 28++++++++++++++--------------
Msrc/backend/taler-merchant-reconciliation.c | 42+++++++++++++++++++++---------------------
Msrc/backend/taler-merchant-report-generator.c | 8++++----
Msrc/backend/taler-merchant-webhook.c | 16++++++++--------
Msrc/backend/taler-merchant-wirewatch.c | 8++++----
Dsrc/backenddb/check_donau_instance.c | 58----------------------------------------------------------
Dsrc/backenddb/check_money_pots.c | 69---------------------------------------------------------------------
Dsrc/backenddb/check_report.c | 61-------------------------------------------------------------
Dsrc/backenddb/check_transfer_exists.c | 53-----------------------------------------------------
Asrc/backenddb/get_account.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_account_by_uri.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_account_serial.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_category.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_category_by_name.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_contract_terms.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_contract_terms_pos.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_contract_terms_status.c | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_donau_instance_by_serial.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_donau_keys.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_exchange_keys.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_exists_donau_instance.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_exists_transfer.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_expected_transfer.c | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_instance_auth.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_login_token.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_mfa_challenge.c | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_missing_money_pot.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_money_pot.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order.c | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order_by_fulfillment.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order_charity.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order_status.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order_status_by_serial.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_order_summary.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_otp.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_otp_serial.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_product.c | 196+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_product_image_by_hash.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_refund_proof.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_report.c | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_report_by_token.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/check_report.sql -> src/backenddb/get_report_by_token.sql | 0
Asrc/backenddb/get_template.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_token_family.c | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_token_family_key.c | 168+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_tos_accepted_early.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_unit.c | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_webhook.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/get_wire_fee.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_accounts.c | 170+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_accounts_by_exchange.c | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_accounts_by_instance.c | 175+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_all_donau_instances.c | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/select_all_donau_instances.sql -> src/backenddb/iterate_all_donau_instances.sql | 0
Asrc/backenddb/iterate_all_products.c | 227+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_all_webhooks.c | 165+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_categories.c | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_categories_by_ids.c | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_custom_units_by_names.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_deposits.c | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_deposits_by_contract_and_coin.c | 318+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_deposits_by_order.c | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_donau_instances.c | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_donau_instances_filtered.c | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_exchanges.c | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_expected_transfers.c | 272+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_instances.c | 283+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_inventory_products.c | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_inventory_products_filtered.c | 240+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_login_tokens.c | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_money_pots.c | 171+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_open_transfers.c | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/select_open_transfers.sql -> src/backenddb/iterate_open_transfers.sql | 0
Asrc/backenddb/iterate_order_blinded_sigs.c | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_orders.c | 269+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_otp_devices.c | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_pending_deposits.c | 178+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/lookup_pending_deposits.sql -> src/backenddb/iterate_pending_deposits.sql | 0
Asrc/backenddb/iterate_pending_webhooks.c | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_product_groups.c | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_products.c | 195+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_reconciliation_details.c | 173+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_refunds.c | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_refunds_detailed.c | 180+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_reports.c | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_reports_pending.c | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/lookup_reports_pending.sql -> src/backenddb/iterate_reports_pending.sql | 0
Asrc/backenddb/iterate_spent_tokens_by_order.c | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistics_amount_by_bucket.c | 221+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistics_amount_by_bucket_range.c | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistics_amount_by_interval.c | 239+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/lookup_statistics_amount_by_interval.sql -> src/backenddb/iterate_statistics_amount_by_interval.sql | 0
Asrc/backenddb/iterate_statistics_counter_by_bucket.c | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistics_counter_by_bucket_range.c | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_statistics_counter_by_interval.c | 210+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/lookup_statistics_counter_by_interval.sql -> src/backenddb/iterate_statistics_counter_by_interval.sql | 0
Asrc/backenddb/iterate_templates.c | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_token_families.c | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_token_family_keys.c | 224+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_transfer_details.c | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_transfer_details_by_order.c | 237+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_transfer_summary.c | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_transfers.c | 239+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_units.c | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_webhooks.c | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_webhooks_by_event.c | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/backenddb/iterate_wirewatch_accounts.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/backenddb/select_wirewatch_accounts.sql -> src/backenddb/iterate_wirewatch_accounts.sql | 0
Dsrc/backenddb/lookup_account.c | 57---------------------------------------------------------
Dsrc/backenddb/lookup_all_products.c | 227-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_all_webhooks.c | 165-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_categories.c | 143-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_categories_by_ids.c | 140-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_contract_terms.c | 73-------------------------------------------------------------------------
Dsrc/backenddb/lookup_contract_terms_pos.c | 90-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_contract_terms_status.c | 102-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_custom_units_by_names.c | 139-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_deposits.c | 163-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_deposits_by_contract_and_coin.c | 318-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_deposits_by_order.c | 161-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_donau_keys.c | 71-----------------------------------------------------------------------
Dsrc/backenddb/lookup_expected_transfer.c | 98-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_expected_transfers.c | 272-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_instance_auth.c | 56--------------------------------------------------------
Dsrc/backenddb/lookup_instances.c | 283-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_inventory_products.c | 219-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_inventory_products_filtered.c | 240-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_login_tokens.c | 177-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_mfa_challenge.c | 110-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_order.c | 91-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_order_by_fulfillment.c | 73-------------------------------------------------------------------------
Dsrc/backenddb/lookup_order_charity.c | 83-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_order_status.c | 63---------------------------------------------------------------
Dsrc/backenddb/lookup_order_status_by_serial.c | 65-----------------------------------------------------------------
Dsrc/backenddb/lookup_order_summary.c | 66------------------------------------------------------------------
Dsrc/backenddb/lookup_orders.c | 269-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_otp_devices.c | 128-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_pending_deposits.c | 178-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_pending_webhooks.c | 198-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_product.c | 196-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_product_image_by_hash.c | 58----------------------------------------------------------
Dsrc/backenddb/lookup_products.c | 195-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_reconciliation_details.c | 173-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_refund_proof.c | 60------------------------------------------------------------
Dsrc/backenddb/lookup_refunds.c | 141-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_refunds_detailed.c | 180-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_reports_pending.c | 174-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_spent_tokens_by_order.c | 158-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_amount_by_bucket.c | 221-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_amount_by_bucket_range.c | 163-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_amount_by_interval.c | 239-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_counter_by_bucket.c | 159-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_counter_by_bucket_range.c | 185-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_statistics_counter_by_interval.c | 210-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_template.c | 77-----------------------------------------------------------------------------
Dsrc/backenddb/lookup_templates.c | 128-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_token_families.c | 157-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_token_family.c | 119-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_token_family_key.c | 168-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_token_family_keys.c | 224-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_tos_accepted_early.c | 56--------------------------------------------------------
Dsrc/backenddb/lookup_transfer_details.c | 153-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_transfer_details_by_order.c | 237-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_transfer_summary.c | 149-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_transfers.c | 239-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_units.c | 144-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_webhook.c | 88-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_webhook_by_event.c | 154-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_webhooks.c | 128-------------------------------------------------------------------------------
Dsrc/backenddb/lookup_wire_fee.c | 79-------------------------------------------------------------------------------
Msrc/backenddb/meson.build | 182++++++++++++++++++++++++++++++++++++++++----------------------------------------
Dsrc/backenddb/select_account.c | 79-------------------------------------------------------------------------------
Dsrc/backenddb/select_account_by_uri.c | 77-----------------------------------------------------------------------------
Dsrc/backenddb/select_accounts.c | 170-------------------------------------------------------------------------------
Dsrc/backenddb/select_accounts_by_exchange.c | 142-------------------------------------------------------------------------------
Dsrc/backenddb/select_accounts_by_instance.c | 175-------------------------------------------------------------------------------
Dsrc/backenddb/select_all_donau_instances.c | 165-------------------------------------------------------------------------------
Dsrc/backenddb/select_category.c | 77-----------------------------------------------------------------------------
Dsrc/backenddb/select_category_by_name.c | 61-------------------------------------------------------------
Dsrc/backenddb/select_donau_instance_by_serial.c | 59-----------------------------------------------------------
Dsrc/backenddb/select_donau_instances.c | 179-------------------------------------------------------------------------------
Dsrc/backenddb/select_donau_instances_filtered.c | 123-------------------------------------------------------------------------------
Dsrc/backenddb/select_exchange_keys.c | 71-----------------------------------------------------------------------
Dsrc/backenddb/select_exchanges.c | 150-------------------------------------------------------------------------------
Dsrc/backenddb/select_login_token.c | 60------------------------------------------------------------
Dsrc/backenddb/select_money_pot.c | 69---------------------------------------------------------------------
Dsrc/backenddb/select_money_pots.c | 171-------------------------------------------------------------------------------
Dsrc/backenddb/select_open_transfers.c | 151------------------------------------------------------------------------------
Dsrc/backenddb/select_order_blinded_sigs.c | 127-------------------------------------------------------------------------------
Dsrc/backenddb/select_otp.c | 69---------------------------------------------------------------------
Dsrc/backenddb/select_otp_serial.c | 56--------------------------------------------------------
Dsrc/backenddb/select_product_groups.c | 160-------------------------------------------------------------------------------
Dsrc/backenddb/select_report.c | 103-------------------------------------------------------------------------------
Dsrc/backenddb/select_reports.c | 162-------------------------------------------------------------------------------
Dsrc/backenddb/select_unit.c | 110-------------------------------------------------------------------------------
Dsrc/backenddb/select_wirewatch_accounts.c | 139-------------------------------------------------------------------------------
Msrc/backenddb/sql-schema/meson.build | 16++++++++--------
Msrc/backenddb/test_merchantdb.c | 520++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/merchant-database/all.h | 182++++++++++++++++++++++++++++++++++++++++----------------------------------------
Dsrc/include/merchant-database/check_donau_instance.h | 45---------------------------------------------
Dsrc/include/merchant-database/check_money_pots.h | 52----------------------------------------------------
Dsrc/include/merchant-database/check_report.h | 52----------------------------------------------------
Dsrc/include/merchant-database/check_transfer_exists.h | 45---------------------------------------------
Msrc/include/merchant-database/delete_tos_accepted_early.h | 2+-
Asrc/include/merchant-database/get_account.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_account_by_uri.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_account_serial.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_category.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_category_by_name.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_contract_terms.h | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_contract_terms_pos.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_contract_terms_status.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_donau_instance_by_serial.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_donau_keys.h | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_exchange_keys.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_exists_donau_instance.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_exists_transfer.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_expected_transfer.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_instance_auth.h | 42++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_login_token.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_mfa_challenge.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_missing_money_pot.h | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_money_pot.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order_by_fulfillment.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order_charity.h | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order_status.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order_status_by_serial.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_order_summary.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_otp.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_otp_serial.h | 44++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_product.h | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_product_image_by_hash.h | 34++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_refund_proof.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_report.h | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_report_by_token.h | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_template.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_token_family.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_token_family_key.h | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_tos_accepted_early.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_unit.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_webhook.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/get_wire_fee.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_accounts.h | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_accounts_by_exchange.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_accounts_by_instance.h | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_all_donau_instances.h | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_all_products.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_all_webhooks.h | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_categories.h | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_categories_by_ids.h | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_custom_units_by_names.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_deposits.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_deposits_by_contract_and_coin.h | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_deposits_by_order.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_donau_instances.h | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_donau_instances_filtered.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_exchanges.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_expected_transfers.h | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_instances.h | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_inventory_products.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_inventory_products_filtered.h | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_login_tokens.h | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_money_pots.h | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_open_transfers.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_order_blinded_sigs.h | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_orders.h | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_otp_devices.h | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_pending_deposits.h | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_pending_webhooks.h | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_product_groups.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_products.h | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_reconciliation_details.h | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_refunds.h | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_refunds_detailed.h | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_reports.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_reports_pending.h | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_spent_tokens_by_order.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_amount_by_bucket.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_amount_by_bucket_range.h | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_amount_by_interval.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_counter_by_bucket.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_counter_by_bucket_range.h | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_statistics_counter_by_interval.h | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_templates.h | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_token_families.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_token_family_keys.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_transfer_details.h | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_transfer_details_by_order.h | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_transfer_summary.h | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_transfers.h | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_units.h | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_webhooks.h | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_webhooks_by_event.h | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/include/merchant-database/iterate_wirewatch_accounts.h | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/include/merchant-database/lookup_account.h | 45---------------------------------------------
Dsrc/include/merchant-database/lookup_all_products.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/lookup_all_webhooks.h | 73-------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_categories.h | 63---------------------------------------------------------------
Dsrc/include/merchant-database/lookup_categories_by_ids.h | 64----------------------------------------------------------------
Dsrc/include/merchant-database/lookup_contract_terms.h | 49-------------------------------------------------
Dsrc/include/merchant-database/lookup_contract_terms_pos.h | 56--------------------------------------------------------
Dsrc/include/merchant-database/lookup_contract_terms_status.h | 60------------------------------------------------------------
Dsrc/include/merchant-database/lookup_custom_units_by_names.h | 62--------------------------------------------------------------
Dsrc/include/merchant-database/lookup_deposits.h | 71-----------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_deposits_by_contract_and_coin.h | 80-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_deposits_by_order.h | 68--------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_donau_keys.h | 49-------------------------------------------------
Dsrc/include/merchant-database/lookup_expected_transfer.h | 60------------------------------------------------------------
Dsrc/include/merchant-database/lookup_expected_transfers.h | 93-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_instance_auth.h | 42------------------------------------------
Dsrc/include/merchant-database/lookup_instances.h | 78------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_inventory_products.h | 62--------------------------------------------------------------
Dsrc/include/merchant-database/lookup_inventory_products_filtered.h | 70----------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_login_tokens.h | 69---------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_mfa_challenge.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/lookup_order.h | 51---------------------------------------------------
Dsrc/include/merchant-database/lookup_order_by_fulfillment.h | 51---------------------------------------------------
Dsrc/include/merchant-database/lookup_order_charity.h | 63---------------------------------------------------------------
Dsrc/include/merchant-database/lookup_order_status.h | 47-----------------------------------------------
Dsrc/include/merchant-database/lookup_order_status_by_serial.h | 50--------------------------------------------------
Dsrc/include/merchant-database/lookup_order_summary.h | 47-----------------------------------------------
Dsrc/include/merchant-database/lookup_orders.h | 121-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_otp_devices.h | 60------------------------------------------------------------
Dsrc/include/merchant-database/lookup_pending_deposits.h | 80-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_pending_webhooks.h | 88-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_product.h | 51---------------------------------------------------
Dsrc/include/merchant-database/lookup_product_image_by_hash.h | 34----------------------------------
Dsrc/include/merchant-database/lookup_products.h | 91-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_reconciliation_details.h | 66------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_refund_proof.h | 45---------------------------------------------
Dsrc/include/merchant-database/lookup_refunds.h | 61-------------------------------------------------------------
Dsrc/include/merchant-database/lookup_refunds_detailed.h | 73-------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_reports_pending.h | 79-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_spent_tokens_by_order.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_amount_by_bucket.h | 68--------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_amount_by_bucket_range.h | 93-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_amount_by_interval.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_counter_by_bucket.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_counter_by_bucket_range.h | 71-----------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_statistics_counter_by_interval.h | 82-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_template.h | 46----------------------------------------------
Dsrc/include/merchant-database/lookup_templates.h | 59-----------------------------------------------------------
Dsrc/include/merchant-database/lookup_token_families.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_token_family.h | 47-----------------------------------------------
Dsrc/include/merchant-database/lookup_token_family_key.h | 92-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_token_family_keys.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/lookup_tos_accepted_early.h | 54------------------------------------------------------
Dsrc/include/merchant-database/lookup_transfer_details.h | 63---------------------------------------------------------------
Dsrc/include/merchant-database/lookup_transfer_details_by_order.h | 73-------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_transfer_summary.h | 62--------------------------------------------------------------
Dsrc/include/merchant-database/lookup_transfers.h | 88-------------------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_units.h | 59-----------------------------------------------------------
Dsrc/include/merchant-database/lookup_webhook.h | 46----------------------------------------------
Dsrc/include/merchant-database/lookup_webhook_by_event.h | 68--------------------------------------------------------------------
Dsrc/include/merchant-database/lookup_webhooks.h | 58----------------------------------------------------------
Dsrc/include/merchant-database/lookup_wire_fee.h | 54------------------------------------------------------
Dsrc/include/merchant-database/select_account.h | 45---------------------------------------------
Dsrc/include/merchant-database/select_account_by_uri.h | 45---------------------------------------------
Dsrc/include/merchant-database/select_accounts.h | 57---------------------------------------------------------
Dsrc/include/merchant-database/select_accounts_by_exchange.h | 65-----------------------------------------------------------------
Dsrc/include/merchant-database/select_accounts_by_instance.h | 58----------------------------------------------------------
Dsrc/include/merchant-database/select_all_donau_instances.h | 75---------------------------------------------------------------------------
Dsrc/include/merchant-database/select_category.h | 50--------------------------------------------------
Dsrc/include/merchant-database/select_category_by_name.h | 47-----------------------------------------------
Dsrc/include/merchant-database/select_donau_instance_by_serial.h | 47-----------------------------------------------
Dsrc/include/merchant-database/select_donau_instances.h | 76----------------------------------------------------------------------------
Dsrc/include/merchant-database/select_donau_instances_filtered.h | 61-------------------------------------------------------------
Dsrc/include/merchant-database/select_exchange_keys.h | 46----------------------------------------------
Dsrc/include/merchant-database/select_exchanges.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/select_login_token.h | 48------------------------------------------------
Dsrc/include/merchant-database/select_money_pot.h | 51---------------------------------------------------
Dsrc/include/merchant-database/select_money_pots.h | 66------------------------------------------------------------------
Dsrc/include/merchant-database/select_open_transfers.h | 71-----------------------------------------------------------------------
Dsrc/include/merchant-database/select_order_blinded_sigs.h | 61-------------------------------------------------------------
Dsrc/include/merchant-database/select_otp.h | 46----------------------------------------------
Dsrc/include/merchant-database/select_otp_serial.h | 44--------------------------------------------
Dsrc/include/merchant-database/select_product_groups.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/select_report.h | 66------------------------------------------------------------------
Dsrc/include/merchant-database/select_reports.h | 67-------------------------------------------------------------------
Dsrc/include/merchant-database/select_unit.h | 45---------------------------------------------
Dsrc/include/merchant-database/select_wirewatch_accounts.h | 64----------------------------------------------------------------
449 files changed, 19265 insertions(+), 19262 deletions(-)

diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c @@ -30,8 +30,8 @@ struct ExchangeInteraction; #include "taler/taler_merchant_util.h" #include "merchantdb_lib.h" #include "merchant-database/event_listen.h" -#include "merchant-database/lookup_pending_deposits.h" -#include "merchant-database/select_exchange_keys.h" +#include "merchant-database/iterate_pending_deposits.h" +#include "merchant-database/get_exchange_keys.h" #include "merchant-database/preflight.h" #include "merchant-database/insert_kyc_failure.h" #include "merchant-database/set_instance.h" @@ -778,7 +778,7 @@ select_work (void *cls) TALER_MERCHANTDB_preflight (pg); if (retry) limit = 1; - qs = TALER_MERCHANTDB_lookup_pending_deposits ( + qs = TALER_MERCHANTDB_iterate_pending_deposits ( pg, exchange_url, limit, @@ -1031,10 +1031,10 @@ update_exchange_keys (void *cls, TALER_EXCHANGE_keys_decref (keys); keys = NULL; } - qs = TALER_MERCHANTDB_select_exchange_keys (pg, - exchange_url, - &earliest_retry, - &keys); + qs = TALER_MERCHANTDB_get_exchange_keys (pg, + exchange_url, + &earliest_retry, + &keys); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-donaukeyupdate.c b/src/backend/taler-merchant-donaukeyupdate.c @@ -30,8 +30,8 @@ #include "merchantdb_lib.h" #include "merchantdb_lib.h" #include "taler/taler_merchant_bank_lib.h" -#include "merchant-database/select_all_donau_instances.h" -#include "merchant-database/select_donau_instance_by_serial.h" +#include "merchant-database/iterate_all_donau_instances.h" +#include "merchant-database/get_donau_instance_by_serial.h" #include "merchant-database/update_donau_instance.h" #include "merchant-database/upsert_donau_keys.h" #include "merchant-database/event_listen.h" @@ -794,10 +794,10 @@ force_donau_charity_id (void *cls, extra, sizeof(uint64_t)); di_serial = GNUNET_ntohll (di_serial); - qs = TALER_MERCHANTDB_select_donau_instance_by_serial (pg, - di_serial, - &donau_url, - &charity_id); + qs = TALER_MERCHANTDB_get_donau_instance_by_serial (pg, + di_serial, + &donau_url, + &charity_id); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { @@ -1150,9 +1150,9 @@ run (void *cls, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_all_donau_instances (pg, - &accept_donau, - NULL); + qs = TALER_MERCHANTDB_iterate_all_donau_instances (pg, + &accept_donau, + NULL); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-exchangekeyupdate.c b/src/backend/taler-merchant-exchangekeyupdate.c @@ -39,7 +39,7 @@ struct Exchange; #include "merchant-database/event_notify.h" #include "merchant-database/event_listen.h" #include "merchant-database/insert_exchange_account.h" -#include "merchant-database/select_exchange_keys.h" +#include "merchant-database/get_exchange_keys.h" #include "merchant-database/store_wire_fee_by_exchange.h" /** @@ -909,10 +909,10 @@ accept_exchanges (void *cls, enum GNUNET_DB_QueryStatus qs; struct TALER_EXCHANGE_Keys *keys = NULL; - qs = TALER_MERCHANTDB_select_exchange_keys (pg, - url, - &e->first_retry, - &keys); + qs = TALER_MERCHANTDB_get_exchange_keys (pg, + url, + &e->first_retry, + &keys); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -51,9 +51,9 @@ #include "taler-merchant-httpd_post-orders-ORDER_ID-pay.h" #include "taler-merchant-httpd_post-orders-ORDER_ID-refund.h" #include "taler-merchant-httpd_post-private-accounts-H_WIRE-kycauth.h" -#include "merchant-database/lookup_instances.h" +#include "merchant-database/iterate_instances.h" #include "merchant-database/set_instance.h" -#include "merchant-database/select_accounts_by_instance.h" +#include "merchant-database/iterate_accounts_by_instance.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" @@ -942,7 +942,7 @@ add_instance_cb (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - qs = TALER_MERCHANTDB_select_accounts_by_instance ( + qs = TALER_MERCHANTDB_iterate_accounts_by_instance ( TMH_db, mi->settings.id, &add_account_cb, @@ -992,10 +992,10 @@ load_instances (void *cls, id); if (NULL == extra) { - qs = TALER_MERCHANTDB_lookup_instances (TMH_db, - false, - &add_instance_cb, - NULL); + qs = TALER_MERCHANTDB_iterate_instances (TMH_db, + false, + &add_instance_cb, + NULL); } else { @@ -1011,11 +1011,11 @@ load_instances (void *cls, &mi->h_instance, mi); } - qs = TALER_MERCHANTDB_lookup_instances_by_id (TMH_db, - id, - false, - &add_instance_cb, - NULL); + qs = TALER_MERCHANTDB_iterate_instances_by_id (TMH_db, + id, + false, + &add_instance_cb, + NULL); } if (0 > qs) { diff --git a/src/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_delete-private-orders-ORDER_ID.c @@ -24,8 +24,8 @@ #include <taler/taler_json_lib.h> #include "merchant-database/delete_contract_terms.h" #include "merchant-database/delete_order.h" -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_order.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/get_order.h" /** @@ -82,25 +82,25 @@ TMH_private_delete_orders_ID (const struct TMH_RequestHandler *rh, bool matches = false; int16_t choice_index; - qs = TALER_MERCHANTDB_lookup_order (TMH_db, - mi->settings.id, - hc->infix, - NULL, - &unused, - NULL); + qs = TALER_MERCHANTDB_get_order (TMH_db, + mi->settings.id, + hc->infix, + NULL, + &unused, + NULL); if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { - qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, - mi->settings.id, - hc->infix, - NULL, - NULL, - &order_serial, - &paid, - &wired, - &matches, - NULL, - &choice_index); + qs = TALER_MERCHANTDB_get_contract_terms_status (TMH_db, + mi->settings.id, + hc->infix, + NULL, + NULL, + &order_serial, + &paid, + &wired, + &matches, + NULL, + &choice_index); } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) return TALER_MHD_reply_with_error (connection, diff --git a/src/backend/taler-merchant-httpd_delete-private-transfers-TID.c b/src/backend/taler-merchant-httpd_delete-private-transfers-TID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_delete-private-transfers-TID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/check_transfer_exists.h" +#include "merchant-database/get_exists_transfer.h" #include "merchant-database/delete_transfer.h" @@ -65,9 +65,9 @@ TMH_private_delete_transfers_ID (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, "delete_transfer"); case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - qs = TALER_MERCHANTDB_check_transfer_exists (TMH_db, - mi->settings.id, - serial); + qs = TALER_MERCHANTDB_get_exists_transfer (TMH_db, + mi->settings.id, + serial); if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) return TALER_MHD_reply_with_error (connection, MHD_HTTP_NOT_FOUND, diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd.h" #include "merchant-database/get_kyc_limits.h" #include "merchant-database/set_instance.h" -#include "merchant-database/select_exchange_keys.h" +#include "merchant-database/get_exchange_keys.h" #include "merchant-database/event_listen.h" #include "merchant-database/event_notify.h" @@ -920,10 +920,10 @@ reload_exchange_keys (struct TMH_Exchange *exchange) struct TALER_EXCHANGE_Keys *keys; struct GNUNET_TIME_Absolute first_retry; - qs = TALER_MERCHANTDB_select_exchange_keys (TMH_db, - exchange->url, - &first_retry, - &keys); + qs = TALER_MERCHANTDB_get_exchange_keys (TMH_db, + exchange->url, + &first_retry, + &keys); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-exchanges.c b/src/backend/taler-merchant-httpd_get-exchanges.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd_get-exchanges.h" #include "taler-merchant-httpd_mhd.h" #include "taler-merchant-httpd_get-exchanges.h" -#include "merchant-database/select_exchanges.h" +#include "merchant-database/iterate_exchanges.h" /** @@ -126,9 +126,9 @@ MH_handler_exchanges (const struct TMH_RequestHandler *rh, exchanges = json_array (); GNUNET_assert (NULL != exchanges); - qs = TALER_MERCHANTDB_select_exchanges (TMH_db, - &add_exchange, - exchanges); + qs = TALER_MERCHANTDB_iterate_exchanges (TMH_db, + &add_exchange, + exchanges); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_get-orders-ORDER_ID.c @@ -35,11 +35,11 @@ #include "taler/taler_error_codes.h" #include "taler/taler_util.h" #include "taler/taler_merchant_util.h" -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_order.h" -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "merchant-database/lookup_order_status.h" -#include "merchant-database/lookup_refunds_detailed.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/get_order.h" +#include "merchant-database/get_order_by_fulfillment.h" +#include "merchant-database/get_order_status.h" +#include "merchant-database/iterate_refunds_detailed.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" @@ -648,7 +648,7 @@ phase_lookup_terms (struct GetOrderData *god) bool paid; bool wired; bool session_matches; - qs = TALER_MERCHANTDB_lookup_contract_terms_status ( + qs = TALER_MERCHANTDB_get_contract_terms_status ( TMH_db, god->hc->instance->settings.id, god->order_id, @@ -739,7 +739,7 @@ phase_lookup_terms (struct GetOrderData *god) struct TALER_MerchantPostDataHashP unused; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_order ( + qs = TALER_MERCHANTDB_get_order ( TMH_db, god->hc->instance->settings.id, god->order_id, @@ -1203,7 +1203,7 @@ phase_check_paid (struct GetOrderData *god) struct TALER_PrivateContractHashP h_contract; god->paid = false; - qs = TALER_MERCHANTDB_lookup_order_status ( + qs = TALER_MERCHANTDB_get_order_status ( TMH_db, god->hc->instance->settings.id, god->order_id, @@ -1252,7 +1252,7 @@ phase_redirect_to_paid_order (struct GetOrderData *god) "Running re-purchase detection for %s/%s\n", god->session_id, god->ct->fulfillment_url); - qs = TALER_MERCHANTDB_lookup_order_by_fulfillment ( + qs = TALER_MERCHANTDB_get_order_by_fulfillment ( TMH_db, god->hc->instance->settings.id, god->ct->fulfillment_url, @@ -1456,7 +1456,7 @@ phase_check_refunded (struct GetOrderData *god) GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (refund_currency, &god->refund_taken)); - qs = TALER_MERCHANTDB_lookup_refunds_detailed ( + qs = TALER_MERCHANTDB_iterate_refunds_detailed ( TMH_db, god->hc->instance->settings.id, &god->h_contract_terms, diff --git a/src/backend/taler-merchant-httpd_get-private-accounts-H_WIRE.c b/src/backend/taler-merchant-httpd_get-private-accounts-H_WIRE.c @@ -22,7 +22,7 @@ #include "taler-merchant-httpd_get-private-accounts-H_WIRE.h" #include <taler/taler_json_lib.h> #include <taler/taler_templating_lib.h> -#include "merchant-database/select_account.h" +#include "merchant-database/get_account.h" /** @@ -64,10 +64,10 @@ TMH_private_get_accounts_ID (const struct TMH_RequestHandler *rh, TALER_EC_MERCHANT_GENERIC_H_WIRE_MALFORMED, h_wire_s); } - qs = TALER_MERCHANTDB_select_account (TMH_db, - mi->settings.id, - &h_wire, - &tp); + qs = TALER_MERCHANTDB_get_account (TMH_db, + mi->settings.id, + &h_wire, + &tp); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-accounts.c b/src/backend/taler-merchant-httpd_get-private-accounts.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-accounts.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_accounts_by_instance.h" +#include "merchant-database/iterate_accounts_by_instance.h" /** @@ -62,7 +62,7 @@ TMH_private_get_accounts (const struct TMH_RequestHandler *rh, pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_select_accounts_by_instance ( + qs = TALER_MERCHANTDB_iterate_accounts_by_instance ( TMH_db, hc->instance->settings.id, &add_account, diff --git a/src/backend/taler-merchant-httpd_get-private-categories-CATEGORY_ID.c b/src/backend/taler-merchant-httpd_get-private-categories-CATEGORY_ID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-categories-CATEGORY_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_category.h" +#include "merchant-database/get_category.h" /** @@ -61,12 +61,12 @@ TMH_private_get_categories_ID ( "category_id must be a number"); } - qs = TALER_MERCHANTDB_select_category (TMH_db, - mi->settings.id, - cnum, - &cd, - &num_products, - &products); + qs = TALER_MERCHANTDB_get_category (TMH_db, + mi->settings.id, + cnum, + &cd, + &num_products, + &products); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-categories.c b/src/backend/taler-merchant-httpd_get-private-categories.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-categories.h" -#include "merchant-database/lookup_categories.h" +#include "merchant-database/iterate_categories.h" /** @@ -71,10 +71,10 @@ TMH_private_get_categories (const struct TMH_RequestHandler *rh, pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_lookup_categories (TMH_db, - hc->instance->settings.id, - &add_category, - pa); + qs = TALER_MERCHANTDB_iterate_categories (TMH_db, + hc->instance->settings.id, + &add_category, + pa); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-donau.c b/src/backend/taler-merchant-httpd_get-private-donau.c @@ -25,7 +25,7 @@ #include <taler/taler_dbevents.h> #include "taler/taler_merchant_service.h" #include "taler-merchant-httpd_get-private-donau.h" -#include "merchant-database/select_donau_instances.h" +#include "merchant-database/iterate_donau_instances.h" #include "merchant-database/preflight.h" @@ -101,10 +101,10 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus qs; TALER_MERCHANTDB_preflight (TMH_db); - qs = TALER_MERCHANTDB_select_donau_instances (TMH_db, - hc->instance->settings.id, - &add_donau_instance, - json_donau_instances); + qs = TALER_MERCHANTDB_iterate_donau_instances (TMH_db, + hc->instance->settings.id, + &add_donau_instance, + json_donau_instances); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-groups.c b/src/backend/taler-merchant-httpd_get-private-groups.c @@ -23,7 +23,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-groups.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_product_groups.h" +#include "merchant-database/iterate_product_groups.h" /** * Sensible bound on the number of results to return @@ -98,12 +98,12 @@ TMH_private_get_groups (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_product_groups (TMH_db, - hc->instance->settings.id, - limit, - offset, - &add_group, - groups); + qs = TALER_MERCHANTDB_iterate_product_groups (TMH_db, + hc->instance->settings.id, + limit, + offset, + &add_group, + groups); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-incoming-ID.c b/src/backend/taler-merchant-httpd_get-private-incoming-ID.c @@ -22,9 +22,9 @@ #include <jansson.h> #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_get-private-incoming-ID.h" -#include "merchant-database/lookup_expected_transfer.h" -#include "merchant-database/lookup_reconciliation_details.h" -#include "merchant-database/lookup_wire_fee.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/preflight.h" @@ -99,17 +99,17 @@ TMH_private_get_incoming_ID (const struct TMH_RequestHandler *rh, struct TALER_MasterPublicKeyP master_pub; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_expected_transfer (TMH_db, - hc->instance->settings.id, - serial_id, - &expected_time, - &expected_credit_amount, - &wtid, - &payto_uri, - &exchange_url, - &execution_time, - &confirmed, - &master_pub); + qs = TALER_MERCHANTDB_get_expected_transfer (TMH_db, + hc->instance->settings.id, + serial_id, + &expected_time, + &expected_credit_amount, + &wtid, + &payto_uri, + &exchange_url, + &execution_time, + &confirmed, + &master_pub); if (0 > qs) { /* Simple select queries should not cause serialization issues */ @@ -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_lookup_wire_fee ( + qs = TALER_MERCHANTDB_get_wire_fee ( TMH_db, &master_pub, method, @@ -176,11 +176,11 @@ TMH_private_get_incoming_ID (const struct TMH_RequestHandler *rh, rd = json_array (); GNUNET_assert (NULL != rd); - qs = TALER_MERCHANTDB_lookup_reconciliation_details (TMH_db, - hc->instance->settings.id, - serial_id, - &reconciliation_cb, - rd); + qs = TALER_MERCHANTDB_iterate_reconciliation_details (TMH_db, + hc->instance->settings.id, + serial_id, + &reconciliation_cb, + rd); if (0 > qs) { /* Simple select queries should not cause serialization issues */ diff --git a/src/backend/taler-merchant-httpd_get-private-incoming.c b/src/backend/taler-merchant-httpd_get-private-incoming.c @@ -22,7 +22,7 @@ #include <jansson.h> #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_get-private-incoming.h" -#include "merchant-database/lookup_expected_transfers.h" +#include "merchant-database/iterate_expected_transfers.h" #include "merchant-database/preflight.h" @@ -161,17 +161,17 @@ TMH_private_get_incoming (const struct TMH_RequestHandler *rh, ja = json_array (); GNUNET_assert (NULL != ja); - qs = TALER_MERCHANTDB_lookup_expected_transfers (TMH_db, - hc->instance->settings.id, - payto_uri, - before, - after, - limit, - offset, - confirmed, - verified, - &incoming_cb, - ja); + qs = TALER_MERCHANTDB_iterate_expected_transfers (TMH_db, + hc->instance->settings.id, + payto_uri, + before, + after, + limit, + offset, + confirmed, + verified, + &incoming_cb, + ja); GNUNET_free (payto_uri.full_payto); if (0 > qs) { diff --git a/src/backend/taler-merchant-httpd_get-private-kyc.c b/src/backend/taler-merchant-httpd_get-private-kyc.c @@ -34,7 +34,7 @@ #include "merchant-database/iterate_kyc_statuses.h" #include "merchant-database/event_listen.h" #include "merchant-database/set_instance.h" -#include "merchant-database/lookup_tos_accepted_early.h" +#include "merchant-database/get_tos_accepted_early.h" /** * Information we keep per /kyc request. @@ -941,10 +941,10 @@ ekr_expand_response (struct ExchangeKycRequest *ekr) } else { - qs = TALER_MERCHANTDB_lookup_tos_accepted_early (TMH_db, - kc->mi->settings.id, - ekr->exchange_url, - &tos_accepted_early); + qs = TALER_MERCHANTDB_get_tos_accepted_early (TMH_db, + kc->mi->settings.id, + ekr->exchange_url, + &tos_accepted_early); GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance ( TMH_db, diff --git a/src/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c b/src/backend/taler-merchant-httpd_get-private-orders-ORDER_ID.c @@ -32,12 +32,12 @@ #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_get-private-orders.h" #include "taler-merchant-httpd_get-private-orders-ORDER_ID.h" -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_deposits_by_order.h" -#include "merchant-database/lookup_order.h" -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "merchant-database/lookup_refunds_detailed.h" -#include "merchant-database/lookup_transfer_details_by_order.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/iterate_deposits_by_order.h" +#include "merchant-database/get_order.h" +#include "merchant-database/get_order_by_fulfillment.h" +#include "merchant-database/iterate_refunds_detailed.h" +#include "merchant-database/iterate_transfer_details_by_order.h" #include "merchant-database/mark_order_wired.h" #include "merchant-database/preflight.h" #include "merchant-database/event_listen.h" @@ -696,17 +696,17 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc) gorc->order_only = false; } TALER_MERCHANTDB_preflight (TMH_db); - qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, - hc->instance->settings.id, - hc->infix, - gorc->session_id, - &gorc->contract_terms_json, - &gorc->order_serial, - &gorc->paid, - &gorc->wired, - &gorc->paid_session_matches, - &gorc->claim_token, - &gorc->choice_index); + qs = TALER_MERCHANTDB_get_contract_terms_status (TMH_db, + hc->instance->settings.id, + hc->infix, + gorc->session_id, + &gorc->contract_terms_json, + &gorc->order_serial, + &gorc->paid, + &gorc->wired, + &gorc->paid_session_matches, + &gorc->claim_token, + &gorc->choice_index); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "lookup_contract_terms (%s) returned %d\n", hc->infix, @@ -745,12 +745,12 @@ phase_fetch_contract (struct GetOrderRequestContext *gorc) /* We need the order for two cases: Either when the contract doesn't exist yet, * or when the order is claimed but unpaid, and we need the claim token. */ - qs = TALER_MERCHANTDB_lookup_order (TMH_db, - hc->instance->settings.id, - hc->infix, - &gorc->claim_token, - &unused, - &gorc->contract_terms_json); + qs = TALER_MERCHANTDB_get_order (TMH_db, + hc->instance->settings.id, + hc->infix, + &gorc->claim_token, + &unused, + &gorc->contract_terms_json); } if (0 > qs) { @@ -1094,7 +1094,7 @@ phase_check_repurchase (struct GetOrderRequestContext *gorc) "Running re-purchase detection for %s/%s\n", gorc->session_id, gorc->ct->fulfillment_url); - qs = TALER_MERCHANTDB_lookup_order_by_fulfillment ( + qs = TALER_MERCHANTDB_get_order_by_fulfillment ( TMH_db, hc->instance->settings.id, gorc->ct->fulfillment_url, @@ -1359,10 +1359,10 @@ phase_check_deposits (struct GetOrderRequestContext *gorc) GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (gorc->contract_amount.currency, &gorc->deposit_fees_refunded_total)); - TALER_MERCHANTDB_lookup_deposits_by_order (TMH_db, - gorc->order_serial, - &deposit_cb, - gorc); + TALER_MERCHANTDB_iterate_deposits_by_order (TMH_db, + gorc->order_serial, + &deposit_cb, + gorc); gorc->phase++; } @@ -1477,7 +1477,7 @@ phase_check_refunds (struct GetOrderRequestContext *gorc) TALER_amount_set_zero (gorc->contract_amount.currency, &gorc->refund_amount)); json_array_clear (gorc->refund_details); - qs = TALER_MERCHANTDB_lookup_refunds_detailed ( + qs = TALER_MERCHANTDB_iterate_refunds_detailed ( TMH_db, hc->instance->settings.id, &gorc->h_contract_terms, @@ -1610,10 +1610,10 @@ phase_check_local_transfers (struct GetOrderRequestContext *gorc) GNUNET_assert (NULL != gorc->wire_details); /* We may be running again due to long-polling, clear state first */ json_array_clear (gorc->wire_details); - qs = TALER_MERCHANTDB_lookup_transfer_details_by_order (TMH_db, - gorc->order_serial, - &process_transfer_details, - gorc); + qs = TALER_MERCHANTDB_iterate_transfer_details_by_order (TMH_db, + gorc->order_serial, + &process_transfer_details, + gorc); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-orders.c b/src/backend/taler-merchant-httpd_get-private-orders.c @@ -25,12 +25,12 @@ #include <taler/taler_merchant_util.h> #include <taler/taler_json_lib.h> #include <taler/taler_dbevents.h> -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_order.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/get_order.h" #include "merchant-database/set_instance.h" -#include "merchant-database/lookup_order_status_by_serial.h" -#include "merchant-database/lookup_orders.h" -#include "merchant-database/lookup_refunds_detailed.h" +#include "merchant-database/get_order_status_by_serial.h" +#include "merchant-database/iterate_orders.h" +#include "merchant-database/iterate_refunds_detailed.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" @@ -500,12 +500,12 @@ add_order (void *cls, po->result = TALER_EC_GENERIC_DB_FETCH_FAILED; return; } - qs = TALER_MERCHANTDB_lookup_order_status_by_serial (TMH_db, - po->instance_id, - order_serial, - &order_id, - &h_contract_terms, - &paid); + qs = TALER_MERCHANTDB_get_order_status_by_serial (TMH_db, + po->instance_id, + order_serial, + &order_id, + &h_contract_terms, + &paid); if (qs < 0) { GNUNET_break (0); @@ -534,17 +534,17 @@ add_order (void *cls, uint64_t os; bool session_matches; - qs = TALER_MERCHANTDB_lookup_contract_terms_status (TMH_db, - po->instance_id, - order_id, - NULL, - &terms, - &os, - &paid, - &wired, - &session_matches, - NULL, - &choice_index); + qs = TALER_MERCHANTDB_get_contract_terms_status (TMH_db, + po->instance_id, + order_id, + NULL, + &terms, + &os, + &paid, + &wired, + &session_matches, + NULL, + &choice_index); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { GNUNET_break (os == order_serial); @@ -565,12 +565,12 @@ add_order (void *cls, paid = false; wired = false; - qs = TALER_MERCHANTDB_lookup_order (TMH_db, - po->instance_id, - order_id, - NULL, - &unused, - &terms); + qs = TALER_MERCHANTDB_get_order (TMH_db, + po->instance_id, + order_id, + NULL, + &unused, + &terms); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { order = TALER_MERCHANT_order_parse (terms); @@ -630,11 +630,11 @@ add_order (void *cls, TALER_amount_set_zero (brutto->currency, &prc.pending_refund_amount)); - qs = TALER_MERCHANTDB_lookup_refunds_detailed (TMH_db, - po->instance_id, - &h_contract_terms, - &process_refunds_cb, - &prc); + qs = TALER_MERCHANTDB_iterate_refunds_detailed (TMH_db, + po->instance_id, + &h_contract_terms, + &process_refunds_cb, + &prc); if (0 > qs) { GNUNET_break (0); @@ -1570,11 +1570,11 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, po->of.timeout = GNUNET_TIME_absolute_get_remaining (po->long_poll_timeout); - qs = TALER_MERCHANTDB_lookup_orders (TMH_db, - po->instance_id, - &po->of, - &add_order, - po); + qs = TALER_MERCHANTDB_iterate_orders (TMH_db, + po->instance_id, + &po->of, + &add_order, + po); if (0 > qs) { GNUNET_break (0); 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/select_otp.h" +#include "merchant-database/get_otp.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_select_otp (TMH_db, - mi->settings.id, - hc->infix, - &tp); + qs = TALER_MERCHANTDB_get_otp (TMH_db, + mi->settings.id, + hc->infix, + &tp); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-otp-devices.c b/src/backend/taler-merchant-httpd_get-private-otp-devices.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-otp-devices.h" -#include "merchant-database/lookup_otp_devices.h" +#include "merchant-database/iterate_otp_devices.h" /** @@ -58,10 +58,10 @@ TMH_private_get_otp_devices (const struct TMH_RequestHandler *rh, pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_lookup_otp_devices (TMH_db, - hc->instance->settings.id, - &add_otp, - pa); + qs = TALER_MERCHANTDB_iterate_otp_devices (TMH_db, + hc->instance->settings.id, + &add_otp, + pa); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-pos.c b/src/backend/taler-merchant-httpd_get-private-pos.c @@ -22,8 +22,8 @@ #include "taler-merchant-httpd_get-private-pos.h" #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_helper.h" -#include "merchant-database/lookup_all_products.h" -#include "merchant-database/lookup_categories.h" +#include "merchant-database/iterate_all_products.h" +#include "merchant-database/iterate_categories.h" /** * Closure for add_product(). @@ -195,10 +195,10 @@ TMH_private_get_pos (const struct TMH_RequestHandler *rh, 0), GNUNET_JSON_pack_string ("name", "default")))); - qs = TALER_MERCHANTDB_lookup_categories (TMH_db, - hc->instance->settings.id, - &add_category, - &ctx); + qs = TALER_MERCHANTDB_iterate_categories (TMH_db, + hc->instance->settings.id, + &add_category, + &ctx); if (0 > qs) { GNUNET_break (0); @@ -209,10 +209,10 @@ TMH_private_get_pos (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_FETCH_FAILED, NULL); } - qs = TALER_MERCHANTDB_lookup_all_products (TMH_db, - hc->instance->settings.id, - &add_product, - &ctx); + qs = TALER_MERCHANTDB_iterate_all_products (TMH_db, + hc->instance->settings.id, + &add_product, + &ctx); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-pots-POT_ID.c b/src/backend/taler-merchant-httpd_get-private-pots-POT_ID.c @@ -23,7 +23,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-pots-POT_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_money_pot.h" +#include "merchant-database/get_money_pot.h" enum MHD_Result @@ -52,13 +52,13 @@ TMH_private_get_pot (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_PARAMETER_MALFORMED, "pot_id"); } - qs = TALER_MERCHANTDB_select_money_pot (TMH_db, - hc->instance->settings.id, - pot_id, - &pot_name, - &description, - &pot_total_len, - &pot_totals); + qs = TALER_MERCHANTDB_get_money_pot (TMH_db, + hc->instance->settings.id, + pot_id, + &pot_name, + &description, + &pot_total_len, + &pot_totals); if (qs < 0) { diff --git a/src/backend/taler-merchant-httpd_get-private-pots.c b/src/backend/taler-merchant-httpd_get-private-pots.c @@ -23,7 +23,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-pots.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_money_pots.h" +#include "merchant-database/iterate_money_pots.h" /** @@ -104,12 +104,12 @@ TMH_private_get_pots (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_money_pots (TMH_db, - hc->instance->settings.id, - limit, - offset, - &add_pot, - pots); + qs = TALER_MERCHANTDB_iterate_money_pots (TMH_db, + hc->instance->settings.id, + limit, + offset, + &add_pot, + pots); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-products-PRODUCT_ID.c b/src/backend/taler-merchant-httpd_get-private-products-PRODUCT_ID.c @@ -23,7 +23,7 @@ #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_helper.h" #include <taler/taler_util.h> -#include "merchant-database/lookup_product.h" +#include "merchant-database/get_product.h" /** * Handle a GET "/products/$ID" request. @@ -47,12 +47,12 @@ TMH_private_get_products_ID ( json_t *jcategories; GNUNET_assert (NULL != mi); - qs = TALER_MERCHANTDB_lookup_product (TMH_db, - mi->settings.id, - hc->infix, - &pd, - &num_categories, - &categories); + qs = TALER_MERCHANTDB_get_product (TMH_db, + mi->settings.id, + hc->infix, + &pd, + &num_categories, + &categories); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-products.c b/src/backend/taler-merchant-httpd_get-private-products.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-products.h" -#include "merchant-database/lookup_products.h" +#include "merchant-database/iterate_products.h" /** @@ -123,16 +123,16 @@ TMH_private_get_products (const struct TMH_RequestHandler *rh, "description_filter")); pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_lookup_products (TMH_db, - hc->instance->settings.id, - offset, - limit, - category_filter, - name_filter, - description_filter, - product_group_id_filter, - &add_product, - pa); + qs = TALER_MERCHANTDB_iterate_products (TMH_db, + hc->instance->settings.id, + offset, + limit, + category_filter, + name_filter, + description_filter, + product_group_id_filter, + &add_product, + pa); GNUNET_free (category_filter); GNUNET_free (name_filter); GNUNET_free (description_filter); diff --git a/src/backend/taler-merchant-httpd_get-private-reports-REPORT_ID.c b/src/backend/taler-merchant-httpd_get-private-reports-REPORT_ID.c @@ -23,7 +23,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-reports-REPORT_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/select_report.h" +#include "merchant-database/get_report.h" enum MHD_Result @@ -63,19 +63,19 @@ TMH_private_get_report (const struct TMH_RequestHandler *rh, } } - qs = TALER_MERCHANTDB_select_report (TMH_db, - hc->instance->settings.id, - (uint64_t) report_id, - &report_program_section, - &report_description, - &mime_type, - &data_source, - &target_address, - &frequency, - &frequency_shift, - &next_transmission, - &last_error_code, - &last_error_detail); + qs = TALER_MERCHANTDB_get_report (TMH_db, + hc->instance->settings.id, + (uint64_t) report_id, + &report_program_section, + &report_description, + &mime_type, + &data_source, + &target_address, + &frequency, + &frequency_shift, + &next_transmission, + &last_error_code, + &last_error_detail); if (qs < 0) { diff --git a/src/backend/taler-merchant-httpd_get-private-reports.c b/src/backend/taler-merchant-httpd_get-private-reports.c @@ -24,7 +24,7 @@ #include "taler-merchant-httpd_get-private-reports.h" #include <taler/taler_json_lib.h> #include <taler/taler_dbevents.h> -#include "merchant-database/select_reports.h" +#include "merchant-database/iterate_reports.h" /** @@ -97,12 +97,12 @@ TMH_private_get_reports (const struct TMH_RequestHandler *rh, reports = json_array (); GNUNET_assert (NULL != reports); - qs = TALER_MERCHANTDB_select_reports (TMH_db, - hc->instance->settings.id, - limit, - offset, - &add_report, - reports); + qs = TALER_MERCHANTDB_iterate_reports (TMH_db, + hc->instance->settings.id, + limit, + offset, + &add_report, + reports); if (qs < 0) { json_decref (reports); 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/lookup_statistics_amount_by_bucket.h" -#include "merchant-database/lookup_statistics_amount_by_interval.h" +#include "merchant-database/iterate_statistics_amount_by_bucket.h" +#include "merchant-database/iterate_statistics_amount_by_interval.h" /** @@ -209,7 +209,7 @@ TMH_private_get_statistics_amount_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_statistics_amount_by_bucket ( + qs = TALER_MERCHANTDB_iterate_statistics_amount_by_bucket ( 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_lookup_statistics_amount_by_interval ( + qs = TALER_MERCHANTDB_iterate_statistics_amount_by_interval ( 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/lookup_statistics_counter_by_bucket.h" -#include "merchant-database/lookup_statistics_counter_by_interval.h" +#include "merchant-database/iterate_statistics_counter_by_bucket.h" +#include "merchant-database/iterate_statistics_counter_by_interval.h" /** @@ -182,7 +182,7 @@ TMH_private_get_statistics_counter_SLUG (const struct TMH_RequestHandler *rh, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_statistics_counter_by_bucket ( + qs = TALER_MERCHANTDB_iterate_statistics_counter_by_bucket ( 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_lookup_statistics_counter_by_interval ( + qs = TALER_MERCHANTDB_iterate_statistics_counter_by_interval ( 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/lookup_statistics_amount_by_bucket_range.h" -#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" +#include "merchant-database/iterate_statistics_amount_by_bucket_range.h" +#include "merchant-database/iterate_statistics_counter_by_bucket_range.h" /** @@ -311,7 +311,7 @@ make_transaction_volume_report (struct ResponseContext *rctx, rctx->data_groups = json_array (); GNUNET_assert (NULL != rctx->data_groups); - qs = TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range ( + qs = TALER_MERCHANTDB_iterate_statistics_amount_by_bucket_range ( TMH_db, rctx->hc->instance->settings.id, bucket_name, @@ -464,7 +464,7 @@ make_transaction_count_report (struct ResponseContext *rctx, rctx->data_groups = json_array (); GNUNET_assert (NULL != rctx->data_groups); - qs = TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( + qs = TALER_MERCHANTDB_iterate_statistics_counter_by_bucket_range ( TMH_db, rctx->hc->instance->settings.id, prefix, /* prefix to match against bucket name */ diff --git a/src/backend/taler-merchant-httpd_get-private-templates-TEMPLATE_ID.c b/src/backend/taler-merchant-httpd_get-private-templates-TEMPLATE_ID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-templates-TEMPLATE_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_template.h" +#include "merchant-database/get_template.h" enum MHD_Result @@ -35,10 +35,10 @@ TMH_private_get_templates_ID ( enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != mi); - qs = TALER_MERCHANTDB_lookup_template (TMH_db, - mi->settings.id, - hc->infix, - &tp); + qs = TALER_MERCHANTDB_get_template (TMH_db, + mi->settings.id, + hc->infix, + &tp); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-templates.c b/src/backend/taler-merchant-httpd_get-private-templates.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-templates.h" -#include "merchant-database/lookup_templates.h" +#include "merchant-database/iterate_templates.h" /** @@ -57,10 +57,10 @@ TMH_private_get_templates (const struct TMH_RequestHandler *rh, pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_lookup_templates (TMH_db, - hc->instance->settings.id, - &add_template, - pa); + qs = TALER_MERCHANTDB_iterate_templates (TMH_db, + hc->instance->settings.id, + &add_template, + pa); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-tokenfamilies-TOKEN_FAMILY_SLUG.c b/src/backend/taler-merchant-httpd_get-private-tokenfamilies-TOKEN_FAMILY_SLUG.c @@ -22,7 +22,7 @@ #include "taler-merchant-httpd_get-private-tokenfamilies-TOKEN_FAMILY_SLUG.h" #include <gnunet/gnunet_json_lib.h> #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_token_family.h" +#include "merchant-database/get_token_family.h" /** @@ -43,10 +43,10 @@ TMH_private_get_tokenfamilies_SLUG (const struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus status; GNUNET_assert (NULL != mi); - status = TALER_MERCHANTDB_lookup_token_family (TMH_db, - mi->settings.id, - hc->infix, - &details); + status = TALER_MERCHANTDB_get_token_family (TMH_db, + mi->settings.id, + hc->infix, + &details); if (0 > status) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-tokenfamilies.c b/src/backend/taler-merchant-httpd_get-private-tokenfamilies.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-tokenfamilies.h" -#include "merchant-database/lookup_token_families.h" +#include "merchant-database/iterate_token_families.h" /** @@ -80,10 +80,10 @@ TMH_private_get_tokenfamilies (const struct TMH_RequestHandler *rh, families = json_array (); GNUNET_assert (NULL != families); - qs = TALER_MERCHANTDB_lookup_token_families (TMH_db, - hc->instance->settings.id, - &add_token_family, - families); + qs = TALER_MERCHANTDB_iterate_token_families (TMH_db, + hc->instance->settings.id, + &add_token_family, + families); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-tokens.c b/src/backend/taler-merchant-httpd_get-private-tokens.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_auth.h" #include "taler-merchant-httpd_get-private-tokens.h" -#include "merchant-database/lookup_login_tokens.h" +#include "merchant-database/iterate_login_tokens.h" /** @@ -94,12 +94,12 @@ TMH_private_get_instances_ID_tokens (const struct TMH_RequestHandler *rh, &offset); ta = json_array (); GNUNET_assert (NULL != ta); - qs = TALER_MERCHANTDB_lookup_login_tokens (TMH_db, - hc->instance->settings.id, - offset, - limit, - &add_token, - ta); + qs = TALER_MERCHANTDB_iterate_login_tokens (TMH_db, + hc->instance->settings.id, + offset, + limit, + &add_token, + ta); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_get-private-transfers.c b/src/backend/taler-merchant-httpd_get-private-transfers.c @@ -23,7 +23,7 @@ #include <jansson.h> #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_get-private-transfers.h" -#include "merchant-database/lookup_transfers.h" +#include "merchant-database/iterate_transfers.h" #include "merchant-database/preflight.h" @@ -153,16 +153,16 @@ TMH_private_get_transfers (const struct TMH_RequestHandler *rh, ja = json_array (); GNUNET_assert (NULL != ja); - qs = TALER_MERCHANTDB_lookup_transfers (TMH_db, - hc->instance->settings.id, - payto_uri, - before, - after, - limit, - offset, - expected, - &transfer_cb, - ja); + qs = TALER_MERCHANTDB_iterate_transfers (TMH_db, + hc->instance->settings.id, + payto_uri, + before, + after, + limit, + offset, + expected, + &transfer_cb, + ja); GNUNET_free (payto_uri.full_payto); if (0 > qs) { diff --git a/src/backend/taler-merchant-httpd_get-private-units-UNIT.c b/src/backend/taler-merchant-httpd_get-private-units-UNIT.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-units-UNIT.h" -#include "merchant-database/select_unit.h" +#include "merchant-database/get_unit.h" enum MHD_Result @@ -34,10 +34,10 @@ TMH_private_get_units_ID (const struct TMH_RequestHandler *rh, (void) rh; GNUNET_assert (NULL != hc->infix); - qs = TALER_MERCHANTDB_select_unit (TMH_db, - hc->instance->settings.id, - hc->infix, - &ud); + qs = TALER_MERCHANTDB_get_unit (TMH_db, + hc->instance->settings.id, + hc->infix, + &ud); switch (qs) { case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: diff --git a/src/backend/taler-merchant-httpd_get-private-units.c b/src/backend/taler-merchant-httpd_get-private-units.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-units.h" -#include "merchant-database/lookup_units.h" +#include "merchant-database/iterate_units.h" static void @@ -69,10 +69,10 @@ TMH_private_get_units (const struct TMH_RequestHandler *rh, (void) rh; ua = json_array (); GNUNET_assert (NULL != ua); - qs = TALER_MERCHANTDB_lookup_units (TMH_db, - hc->instance->settings.id, - &add_unit, - ua); + qs = TALER_MERCHANTDB_iterate_units (TMH_db, + hc->instance->settings.id, + &add_unit, + ua); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.c b/src/backend/taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.c @@ -21,7 +21,7 @@ #include "platform.h" #include "taler-merchant-httpd_get-private-webhooks-WEBHOOK_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_webhook.h" +#include "merchant-database/get_webhook.h" /** @@ -42,10 +42,10 @@ TMH_private_get_webhooks_ID (const struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != mi); - qs = TALER_MERCHANTDB_lookup_webhook (TMH_db, - mi->settings.id, - hc->infix, - &wb); + qs = TALER_MERCHANTDB_get_webhook (TMH_db, + mi->settings.id, + hc->infix, + &wb); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-private-webhooks.c b/src/backend/taler-merchant-httpd_get-private-webhooks.c @@ -20,7 +20,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_get-private-webhooks.h" -#include "merchant-database/lookup_webhooks.h" +#include "merchant-database/iterate_webhooks.h" /** @@ -58,10 +58,10 @@ TMH_private_get_webhooks (const struct TMH_RequestHandler *rh, pa = json_array (); GNUNET_assert (NULL != pa); - qs = TALER_MERCHANTDB_lookup_webhooks (TMH_db, - hc->instance->settings.id, - &add_webhook, - pa); + qs = TALER_MERCHANTDB_iterate_webhooks (TMH_db, + hc->instance->settings.id, + &add_webhook, + pa); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c b/src/backend/taler-merchant-httpd_get-products-IMAGE_HASH-image.c @@ -22,7 +22,7 @@ #include "taler-merchant-httpd_get-products-IMAGE_HASH-image.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_error_codes.h> -#include "merchant-database/lookup_product_image_by_hash.h" +#include "merchant-database/get_product_image_by_hash.h" enum MHD_Result @@ -54,10 +54,10 @@ TMH_get_products_image (const struct TMH_RequestHandler *rh, "image_hash"); } - qs = TALER_MERCHANTDB_lookup_product_image_by_hash (TMH_db, - mi->settings.id, - image_hash, - &image); + qs = TALER_MERCHANTDB_get_product_image_by_hash (TMH_db, + mi->settings.id, + image_hash, + &image); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-sessions-SESSION_ID.c b/src/backend/taler-merchant-httpd_get-sessions-SESSION_ID.c @@ -22,8 +22,8 @@ #include "taler-merchant-httpd_get-sessions-SESSION_ID.h" #include <taler/taler_json_lib.h> #include <taler/taler_dbevents.h> -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "merchant-database/lookup_order_status.h" +#include "merchant-database/get_order_by_fulfillment.h" +#include "merchant-database/get_order_status.h" #include "merchant-database/event_listen.h" @@ -227,12 +227,12 @@ TMH_get_sessions_ID ( { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_order_by_fulfillment (TMH_db, - mi->settings.id, - gsc->fulfillment_url, - hc->infix, - false, - &order_id); + qs = TALER_MERCHANTDB_get_order_by_fulfillment (TMH_db, + mi->settings.id, + gsc->fulfillment_url, + hc->infix, + false, + &order_id); if (0 > qs) { GNUNET_break (0); @@ -259,11 +259,11 @@ TMH_get_sessions_ID ( enum GNUNET_DB_QueryStatus qs; struct TALER_PrivateContractHashP h_contract_terms; - qs = TALER_MERCHANTDB_lookup_order_status (TMH_db, - mi->settings.id, - order_id, - &h_contract_terms, - &paid); + qs = TALER_MERCHANTDB_get_order_status (TMH_db, + mi->settings.id, + order_id, + &h_contract_terms, + &paid); if (0 >= qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_get-templates-TEMPLATE_ID.c b/src/backend/taler-merchant-httpd_get-templates-TEMPLATE_ID.c @@ -22,11 +22,11 @@ #include "taler-merchant-httpd_get-templates-TEMPLATE_ID.h" #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_categories_by_ids.h" -#include "merchant-database/lookup_custom_units_by_names.h" -#include "merchant-database/lookup_inventory_products.h" -#include "merchant-database/lookup_inventory_products_filtered.h" -#include "merchant-database/lookup_template.h" +#include "merchant-database/iterate_categories_by_ids.h" +#include "merchant-database/iterate_custom_units_by_names.h" +#include "merchant-database/iterate_inventory_products.h" +#include "merchant-database/iterate_inventory_products_filtered.h" +#include "merchant-database/get_template.h" /** @@ -364,10 +364,10 @@ handle_get_templates_inventory ( { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_inventory_products (TMH_db, - mi->settings.id, - &add_inventory_product, - &ipc); + qs = TALER_MERCHANTDB_iterate_inventory_products (TMH_db, + mi->settings.id, + &add_inventory_product, + &ipc); if (0 > qs) { GNUNET_break (0); @@ -384,7 +384,7 @@ handle_get_templates_inventory ( { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_inventory_products_filtered ( + qs = TALER_MERCHANTDB_iterate_inventory_products_filtered ( TMH_db, mi->settings.id, product_ids, @@ -415,7 +415,7 @@ handle_get_templates_inventory ( { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_categories_by_ids ( + qs = TALER_MERCHANTDB_iterate_categories_by_ids ( TMH_db, mi->settings.id, ipc.category_set.ids, @@ -440,7 +440,7 @@ handle_get_templates_inventory ( { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_custom_units_by_names ( + qs = TALER_MERCHANTDB_iterate_custom_units_by_names ( TMH_db, mi->settings.id, (const char *const *) ipc.unit_set.units, @@ -515,10 +515,10 @@ TMH_get_templates_ID ( enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != mi); - qs = TALER_MERCHANTDB_lookup_template (TMH_db, - mi->settings.id, - hc->infix, - &tp); + qs = TALER_MERCHANTDB_get_template (TMH_db, + mi->settings.id, + hc->infix, + &tp); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c @@ -26,10 +26,10 @@ #include <taler/taler_templating_lib.h> #include <taler/taler_dbevents.h> #include "merchant-database/insert_pending_webhook.h" -#include "merchant-database/lookup_webhook_by_event.h" -#include "merchant-database/select_accounts_by_exchange.h" -#include "merchant-database/select_login_token.h" -#include "merchant-database/select_unit.h" +#include "merchant-database/iterate_webhooks_by_event.h" +#include "merchant-database/iterate_accounts_by_exchange.h" +#include "merchant-database/get_login_token.h" +#include "merchant-database/get_unit.h" #include "merchant-database/event_notify.h" @@ -67,10 +67,10 @@ TMH_unit_defaults_for_instance (const struct TMH_MerchantInstance *mi, GNUNET_assert (NULL != allow_fractional); GNUNET_assert (NULL != precision_level); - qs = TALER_MERCHANTDB_select_unit (TMH_db, - mi->settings.id, - unit, - &ud); + qs = TALER_MERCHANTDB_get_unit (TMH_db, + mi->settings.id, + unit, + &ud); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -632,11 +632,11 @@ TMH_check_token (const char *token, GNUNET_break_op (0); return TALER_EC_GENERIC_TOKEN_MALFORMED; } - qs = TALER_MERCHANTDB_select_login_token (TMH_db, - instance_id, - &btoken, - &expiration, - (uint32_t*) &scope); + qs = TALER_MERCHANTDB_get_login_token (TMH_db, + instance_id, + &btoken, + &expiration, + (uint32_t*) &scope); if (qs < 0) { GNUNET_break (0); @@ -877,11 +877,11 @@ TMH_trigger_webhook (const char *instance, }; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_webhook_by_event (TMH_db, - instance, - event, - &trigger_webhook_cb, - &t); + qs = TALER_MERCHANTDB_iterate_webhooks_by_event (TMH_db, + instance, + event, + &trigger_webhook_cb, + &t); if (qs < 0) return qs; return t.rv; @@ -1122,10 +1122,10 @@ TMH_exchange_accounts_by_method ( enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != emc.accounts); - qs = TALER_MERCHANTDB_select_accounts_by_exchange (TMH_db, - master_pub, - &add_matching_account, - &emc); + qs = TALER_MERCHANTDB_iterate_accounts_by_exchange (TMH_db, + master_pub, + &add_matching_account, + &emc); if (qs < 0) { json_decref (emc.accounts); diff --git a/src/backend/taler-merchant-httpd_mfa.c b/src/backend/taler-merchant-httpd_mfa.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd.h" #include "taler-merchant-httpd_mfa.h" #include "merchant-database/create_mfa_challenge.h" -#include "merchant-database/lookup_mfa_challenge.h" +#include "merchant-database/get_mfa_challenge.h" /** @@ -150,17 +150,17 @@ mfa_challenge_check ( *solved = false; *channel = TALER_MERCHANT_MFA_CHANNEL_NONE; *retry_counter = UINT_MAX; - qs = TALER_MERCHANTDB_lookup_mfa_challenge (TMH_db, - challenge_serial, - &x_h_body, - &salt, - target_address, - &xop, - &confirmation_date, - &retransmission_date, - retry_counter, - channel, - &instance_id); + qs = TALER_MERCHANTDB_get_mfa_challenge (TMH_db, + challenge_serial, + &x_h_body, + &salt, + target_address, + &xop, + &confirmation_date, + &retransmission_date, + retry_counter, + channel, + &instance_id); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_patch-private-orders-ORDER_ID-forget.c b/src/backend/taler-merchant-httpd_patch-private-orders-ORDER_ID-forget.c @@ -24,7 +24,7 @@ #include "platform.h" #include "taler-merchant-httpd_patch-private-orders-ORDER_ID-forget.h" #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_contract_terms.h" +#include "merchant-database/get_contract_terms.h" #include "merchant-database/update_contract_terms.h" #include "merchant-database/start.h" @@ -108,12 +108,12 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_START_FAILED, NULL); } - qs = TALER_MERCHANTDB_lookup_contract_terms (TMH_db, - hc->instance->settings.id, - order_id, - &contract_terms, - &order_serial, - NULL); + qs = TALER_MERCHANTDB_get_contract_terms (TMH_db, + hc->instance->settings.id, + order_id, + &contract_terms, + &order_serial, + NULL); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-challenge-ID.c b/src/backend/taler-merchant-httpd_post-challenge-ID.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd.h" #include "taler-merchant-httpd_mfa.h" #include "taler-merchant-httpd_post-challenge-ID.h" -#include "merchant-database/lookup_mfa_challenge.h" +#include "merchant-database/get_mfa_challenge.h" #include "merchant-database/update_mfa_challenge.h" @@ -607,17 +607,17 @@ phase_lookup (struct MfaState *mfa) struct GNUNET_TIME_Absolute retransmission_date; struct TALER_MERCHANT_MFA_BodySalt salt; - qs = TALER_MERCHANTDB_lookup_mfa_challenge (TMH_db, - mfa->challenge_id, - &mfa->h_body, - &salt, - &mfa->required_address, - &mfa->op, - &confirmation_date, - &retransmission_date, - &retry_counter, - &mfa->channel, - &mfa->instance_id); + qs = TALER_MERCHANTDB_get_mfa_challenge (TMH_db, + mfa->challenge_id, + &mfa->h_body, + &salt, + &mfa->required_address, + &mfa->op, + &confirmation_date, + &retransmission_date, + &retry_counter, + &mfa->channel, + &mfa->instance_id); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-management-instances-INSTANCE-auth.c b/src/backend/taler-merchant-httpd_post-management-instances-INSTANCE-auth.c @@ -29,7 +29,7 @@ #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_mfa.h" #include <taler/taler_json_lib.h> -#include "merchant-database/lookup_instance_auth.h" +#include "merchant-database/get_instance_auth.h" #include "merchant-database/update_instance_auth.h" #include "merchant-database/start.h" @@ -188,9 +188,9 @@ post_instances_ID_auth (struct TMH_MerchantInstance *mi, struct TALER_MERCHANTDB_InstanceAuthSettings db_ias; enum TALER_ErrorCode ec; - qs = TALER_MERCHANTDB_lookup_instance_auth (TMH_db, - mi->settings.id, - &db_ias); + qs = TALER_MERCHANTDB_get_instance_auth (TMH_db, + mi->settings.id, + &db_ias); switch (qs) { diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-abort.c @@ -32,8 +32,8 @@ struct RefundDetails; #include "taler-merchant-httpd_get-exchanges.h" #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_post-orders-ORDER_ID-abort.h" -#include "merchant-database/lookup_deposits.h" -#include "merchant-database/lookup_order_status.h" +#include "merchant-database/iterate_deposits.h" +#include "merchant-database/get_order_status.h" #include "merchant-database/refund_coin.h" #include "merchant-database/preflight.h" #include "merchant-database/start.h" @@ -781,11 +781,11 @@ begin_transaction (struct AbortContext *ac) struct TALER_PrivateContractHashP h_contract_terms; bool paid; - qs = TALER_MERCHANTDB_lookup_order_status (TMH_db, - ac->hc->instance->settings.id, - ac->hc->infix, - &h_contract_terms, - &paid); + qs = TALER_MERCHANTDB_get_order_status (TMH_db, + ac->hc->instance->settings.id, + ac->hc->infix, + &h_contract_terms, + &paid); switch (qs) { case GNUNET_DB_STATUS_SOFT_ERROR: @@ -840,11 +840,11 @@ begin_transaction (struct AbortContext *ac) /* Mark all deposits we have in our database for the order as refunded. */ ac->row_qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - qs = TALER_MERCHANTDB_lookup_deposits (TMH_db, - ac->hc->instance->settings.id, - &ac->h_contract_terms, - &refund_coins, - ac); + qs = TALER_MERCHANTDB_iterate_deposits (TMH_db, + ac->hc->instance->settings.id, + &ac->h_contract_terms, + &refund_coins, + ac); if (0 > qs) { TALER_MERCHANTDB_rollback (TMH_db); diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-claim.c @@ -31,8 +31,8 @@ #include "taler-merchant-httpd_get-private-orders.h" #include "taler-merchant-httpd_post-orders-ORDER_ID-claim.h" #include "merchant-database/insert_contract_terms.h" -#include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_order.h" +#include "merchant-database/get_contract_terms.h" +#include "merchant-database/get_order.h" #include "merchant-database/event_notify.h" #include "merchant-database/preflight.h" #include "merchant-database/start.h" @@ -78,12 +78,12 @@ claim_order (struct TMH_HandlerContext *hc, GNUNET_break (0); return GNUNET_DB_STATUS_HARD_ERROR; } - qs = TALER_MERCHANTDB_lookup_contract_terms (TMH_db, - instance_id, - order_id, - contract_terms, - &order_serial, - NULL); + qs = TALER_MERCHANTDB_get_contract_terms (TMH_db, + instance_id, + order_id, + contract_terms, + &order_serial, + NULL); if (0 > qs) { TALER_MERCHANTDB_rollback (TMH_db); @@ -141,12 +141,12 @@ claim_order (struct TMH_HandlerContext *hc, }; /* see if we have this order in our table of unclaimed orders */ - qs = TALER_MERCHANTDB_lookup_order (TMH_db, - instance_id, - order_id, - &order_ct, - &unused, - contract_terms); + qs = TALER_MERCHANTDB_get_order (TMH_db, + instance_id, + order_id, + &order_ct, + &unused, + contract_terms); if (0 >= qs) { TALER_MERCHANTDB_rollback (TMH_db); diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-pay.c @@ -58,16 +58,16 @@ struct ExchangeGroup; #include "merchant-database/insert_issued_token.h" #include "merchant-database/insert_order_blinded_sigs.h" #include "merchant-database/insert_spent_token.h" -#include "merchant-database/lookup_contract_terms_pos.h" -#include "merchant-database/lookup_deposits.h" -#include "merchant-database/lookup_deposits_by_order.h" -#include "merchant-database/lookup_order_charity.h" -#include "merchant-database/lookup_refunds.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/iterate_refunds.h" #include "merchant-database/set_instance.h" -#include "merchant-database/lookup_spent_tokens_by_order.h" -#include "merchant-database/lookup_token_family_key.h" +#include "merchant-database/iterate_spent_tokens_by_order.h" +#include "merchant-database/get_token_family_key.h" #include "merchant-database/mark_contract_paid.h" -#include "merchant-database/select_order_blinded_sigs.h" +#include "merchant-database/iterate_order_blinded_sigs.h" #include "merchant-database/start.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" @@ -3050,11 +3050,11 @@ phase_execute_pay_transaction (struct PayContext *pc) enum GNUNET_DB_QueryStatus qs; /* Check if some of these coins already succeeded for _this_ contract. */ - qs = TALER_MERCHANTDB_lookup_deposits (TMH_db, - instance_id, - &pc->check_contract.h_contract_terms, - &check_coin_paid, - pc); + qs = TALER_MERCHANTDB_iterate_deposits (TMH_db, + instance_id, + &pc->check_contract.h_contract_terms, + &check_coin_paid, + pc); if (0 > qs) { TALER_MERCHANTDB_rollback (TMH_db); @@ -3088,11 +3088,11 @@ phase_execute_pay_transaction (struct PayContext *pc) enum GNUNET_DB_QueryStatus qs; /* Check if we refunded some of the coins */ - qs = TALER_MERCHANTDB_lookup_refunds (TMH_db, - instance_id, - &pc->check_contract.h_contract_terms, - &check_coin_refunded, - pc); + qs = TALER_MERCHANTDB_iterate_refunds (TMH_db, + instance_id, + &pc->check_contract.h_contract_terms, + &check_coin_refunded, + pc); if (0 > qs) { TALER_MERCHANTDB_rollback (TMH_db); @@ -3720,7 +3720,7 @@ handle_output_token (struct PayContext *pc, /* Fetch the private key from the DB for the merchant instance and * this particular family/time interval. */ - qs = TALER_MERCHANTDB_lookup_token_family_key ( + qs = TALER_MERCHANTDB_get_token_family_key ( TMH_db, pc->hc->instance->settings.id, family->slug, @@ -4351,10 +4351,10 @@ phase_contract_paid (struct PayContext *pc) { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_deposits_by_order (TMH_db, - pc->check_contract.order_serial, - &deposit_paid_check, - pc); + qs = TALER_MERCHANTDB_iterate_deposits_by_order (TMH_db, + pc->check_contract.order_serial, + &deposit_paid_check, + pc); /* Since orders with choices can have a price of zero, 0 is also a valid query state */ if (qs < 0) @@ -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_lookup_spent_tokens_by_order (TMH_db, - pc->check_contract.order_serial, - &input_tokens_paid_check, - pc); + qs = TALER_MERCHANTDB_iterate_spent_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_select_order_blinded_sigs ( + qs = TALER_MERCHANTDB_iterate_order_blinded_sigs ( TMH_db, pc->order_id, &append_output_token_sig, @@ -4512,7 +4512,7 @@ phase_check_contract (struct PayContext *pc) TALER_MERCHANT_contract_free (pc->check_contract.contract_terms); pc->check_contract.contract_terms = NULL; } - qs = TALER_MERCHANTDB_lookup_contract_terms_pos ( + qs = TALER_MERCHANTDB_get_contract_terms_pos ( TMH_db, pc->hc->instance->settings.id, pc->order_id, @@ -4882,7 +4882,7 @@ phase_parse_wallet_data (struct PayContext *pc) { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_order_charity ( + qs = TALER_MERCHANTDB_get_order_charity ( TMH_db, pc->hc->instance->settings.id, donau_url_tmp, diff --git a/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-refund.c b/src/backend/taler-merchant-httpd_post-orders-ORDER_ID-refund.c @@ -34,10 +34,10 @@ struct CoinRefund; #include "taler-merchant-httpd_get-exchanges.h" #include "taler-merchant-httpd_post-orders-ORDER_ID-refund.h" #include "merchant-database/insert_refund_proof.h" -#include "merchant-database/lookup_contract_terms.h" +#include "merchant-database/get_contract_terms.h" #include "merchant-database/set_instance.h" -#include "merchant-database/lookup_refund_proof.h" -#include "merchant-database/lookup_refunds_detailed.h" +#include "merchant-database/get_refund_proof.h" +#include "merchant-database/iterate_refunds_detailed.h" #include "merchant-database/event_notify.h" #include "merchant-database/preflight.h" @@ -616,12 +616,12 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh, json_t *contract_terms = NULL; uint64_t order_serial; - qs = TALER_MERCHANTDB_lookup_contract_terms (TMH_db, - hc->instance->settings.id, - hc->infix, - &contract_terms, - &order_serial, - NULL); + qs = TALER_MERCHANTDB_get_contract_terms (TMH_db, + hc->instance->settings.id, + hc->infix, + &contract_terms, + &order_serial, + NULL); if (0 > qs) { /* single, read-only SQL statements should never cause @@ -702,11 +702,11 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh, NULL); } - qs = TALER_MERCHANTDB_lookup_refunds_detailed (TMH_db, - hc->instance->settings.id, - &prd->h_contract_terms, - &process_refunds_cb, - prd); + qs = TALER_MERCHANTDB_iterate_refunds_detailed (TMH_db, + hc->instance->settings.id, + &prd->h_contract_terms, + &process_refunds_cb, + prd); if (0 > qs) { GNUNET_break (0); @@ -733,10 +733,10 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh, NULL != cr; cr = cr->next) { - qs = TALER_MERCHANTDB_lookup_refund_proof (TMH_db, - cr->refund_serial, - &cr->exchange_sig, - &cr->exchange_pub); + qs = TALER_MERCHANTDB_get_refund_proof (TMH_db, + cr->refund_serial, + &cr->exchange_sig, + &cr->exchange_pub); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-accounts-H_WIRE-kycauth.c b/src/backend/taler-merchant-httpd_post-private-accounts-H_WIRE-kycauth.c @@ -28,7 +28,7 @@ #include "taler-merchant-httpd.h" #include "taler-merchant-httpd_exchanges.h" #include "taler-merchant-httpd_post-private-accounts-H_WIRE-kycauth.h" -#include "merchant-database/select_account.h" +#include "merchant-database/get_account.h" #include "taler/taler_util.h" @@ -600,10 +600,10 @@ phase_parse (struct KycAuthContext *kac) struct TALER_MERCHANTDB_AccountDetails ad = { 0 }; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_account (TMH_db, - kac->hc->instance->settings.id, - &h_wire, - &ad); + qs = TALER_MERCHANTDB_get_account (TMH_db, + kac->hc->instance->settings.id, + &h_wire, + &ad); if (0 > qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_post-private-accounts.c b/src/backend/taler-merchant-httpd_post-private-accounts.c @@ -31,7 +31,7 @@ #include "taler-merchant-httpd_mfa.h" #include <regex.h> #include "merchant-database/activate_account.h" -#include "merchant-database/select_accounts_by_instance.h" +#include "merchant-database/iterate_accounts_by_instance.h" #include "merchant-database/preflight.h" /** @@ -299,7 +299,7 @@ TMH_private_post_account (const struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus qs; TALER_MERCHANTDB_preflight (TMH_db); - qs = TALER_MERCHANTDB_select_accounts_by_instance ( + qs = TALER_MERCHANTDB_iterate_accounts_by_instance ( TMH_db, mi->settings.id, &account_cb, diff --git a/src/backend/taler-merchant-httpd_post-private-categories.c b/src/backend/taler-merchant-httpd_post-private-categories.c @@ -26,7 +26,7 @@ #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> #include "merchant-database/insert_category.h" -#include "merchant-database/select_category_by_name.h" +#include "merchant-database/get_category_by_name.h" #include "merchant-database/start.h" /** @@ -94,11 +94,11 @@ TMH_private_post_categories (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_START_FAILED, NULL); } - qs = TALER_MERCHANTDB_select_category_by_name (TMH_db, - mi->settings.id, - category_name, - &xcategory_name_i18n, - &category_id); + qs = TALER_MERCHANTDB_get_category_by_name (TMH_db, + mi->settings.id, + category_name, + &xcategory_name_i18n, + &category_id); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-donau.c b/src/backend/taler-merchant-httpd_post-private-donau.c @@ -27,7 +27,7 @@ #include <taler/taler_dbevents.h> #include "taler/taler_merchant_service.h" #include "taler-merchant-httpd_post-private-donau.h" -#include "merchant-database/check_donau_instance.h" +#include "merchant-database/get_exists_donau_instance.h" #include "merchant-database/insert_donau_instance.h" #include "merchant-database/event_listen.h" #include "merchant-database/event_notify.h" @@ -306,10 +306,10 @@ TMH_private_post_donau_instance (const struct TMH_RequestHandler *rh, : MHD_NO; } } - qs = TALER_MERCHANTDB_check_donau_instance (TMH_db, - &hc->instance->merchant_pub, - pdc->donau_url, - pdc->charity_id); + qs = TALER_MERCHANTDB_get_exists_donau_instance (TMH_db, + &hc->instance->merchant_pub, + pdc->donau_url, + pdc->charity_id); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-orders-ORDER_ID-refund.c b/src/backend/taler-merchant-httpd_post-private-orders-ORDER_ID-refund.c @@ -30,8 +30,8 @@ #include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_get-exchanges.h" #include "merchant-database/increase_refund.h" -#include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_order_summary.h" +#include "merchant-database/get_contract_terms.h" +#include "merchant-database/get_order_summary.h" #include "merchant-database/start.h" #include "merchant-database/preflight.h" #include "merchant-database/event_notify.h" @@ -203,12 +203,12 @@ TMH_private_post_orders_ID_refund ( struct GNUNET_TIME_Timestamp refund_deadline; struct GNUNET_TIME_Timestamp wire_deadline; - qs = TALER_MERCHANTDB_lookup_contract_terms (TMH_db, - hc->instance->settings.id, - hc->infix, - &contract_terms, - &order_serial, - NULL); + qs = TALER_MERCHANTDB_get_contract_terms (TMH_db, + hc->instance->settings.id, + hc->infix, + &contract_terms, + &order_serial, + NULL); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { if (qs < 0) @@ -428,11 +428,11 @@ TMH_private_post_orders_ID_refund ( uint64_t order_serial; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_order_summary (TMH_db, - hc->instance->settings.id, - hc->infix, - &timestamp, - &order_serial); + qs = TALER_MERCHANTDB_get_order_summary (TMH_db, + hc->instance->settings.id, + hc->infix, + &timestamp, + &order_serial); if (0 >= qs) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_post-private-orders.c b/src/backend/taler-merchant-httpd_post-private-orders.c @@ -52,17 +52,17 @@ #include "merchant-database/event_notify.h" #include "merchant-database/preflight.h" #include "merchant-database/expire_locks.h" -#include "merchant-database/check_money_pots.h" +#include "merchant-database/get_missing_money_pot.h" #include "merchant-database/insert_order.h" #include "merchant-database/insert_order_lock.h" #include "merchant-database/insert_token_family_key.h" -#include "merchant-database/lookup_order.h" -#include "merchant-database/lookup_order_summary.h" -#include "merchant-database/lookup_product.h" -#include "merchant-database/lookup_token_family_key.h" -#include "merchant-database/lookup_token_family_keys.h" -#include "merchant-database/select_donau_instances_filtered.h" -#include "merchant-database/select_otp.h" +#include "merchant-database/get_order.h" +#include "merchant-database/get_order_summary.h" +#include "merchant-database/get_product.h" +#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/unlock_inventory.h" @@ -949,12 +949,12 @@ execute_transaction (struct OrderContext *oc) json_t *contract_terms; struct TALER_MerchantPostDataHashP orig_post; - qs = TALER_MERCHANTDB_lookup_order (TMH_db, - oc->hc->instance->settings.id, - oc->parse_order.order->order_id, - &oc->execute_order.token, - &orig_post, - &contract_terms); + qs = TALER_MERCHANTDB_get_order (TMH_db, + oc->hc->instance->settings.id, + oc->parse_order.order->order_id, + &oc->execute_order.token, + &orig_post, + &contract_terms); /* If yes, check for idempotency */ if (0 > qs) { @@ -1042,7 +1042,7 @@ execute_transaction (struct OrderContext *oc) /* Get the order serial and timestamp for the order we just created to update long-poll clients. */ - qs = TALER_MERCHANTDB_lookup_order_summary ( + qs = TALER_MERCHANTDB_get_order_summary ( TMH_db, oc->hc->instance->settings.id, oc->parse_order.order->order_id, @@ -1222,7 +1222,7 @@ phase_execute_order (struct OrderContext *oc) memset (&pd, 0, sizeof (pd)); - qs = TALER_MERCHANTDB_lookup_product ( + qs = TALER_MERCHANTDB_get_product ( TMH_db, oc->hc->instance->settings.id, ip->product_id, @@ -1629,7 +1629,7 @@ add_input_token_family (struct OrderContext *oc, enum TALER_ErrorCode ec = TALER_EC_INVALID; /* make compiler happy */ unsigned int http_status = 0; /* make compiler happy */ - qs = TALER_MERCHANTDB_lookup_token_family_keys ( + qs = TALER_MERCHANTDB_iterate_token_family_keys ( TMH_db, oc->hc->instance->settings.id, slug, @@ -1773,7 +1773,7 @@ add_output_token_family (struct OrderContext *oc, valid_at, key_index)) ) return GNUNET_OK; - qs = TALER_MERCHANTDB_lookup_token_family_key ( + qs = TALER_MERCHANTDB_get_token_family_key ( TMH_db, oc->hc->instance->settings.id, slug, @@ -3242,11 +3242,11 @@ phase_merge_inventory (struct OrderContext *oc) enum GNUNET_DB_QueryStatus qs; uint64_t pot_missing; - qs = TALER_MERCHANTDB_check_money_pots (TMH_db, - oc->hc->instance->settings.id, - pots_off, - pots, - &pot_missing); + qs = TALER_MERCHANTDB_get_missing_money_pot (TMH_db, + oc->hc->instance->settings.id, + pots_off, + pots, + &pot_missing); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -3291,12 +3291,12 @@ phase_merge_inventory (struct OrderContext *oc) size_t num_categories = 0; uint64_t *categories = NULL; - qs = TALER_MERCHANTDB_lookup_product (TMH_db, - oc->hc->instance->settings.id, - ip->product_id, - &pd, - &num_categories, - &categories); + qs = TALER_MERCHANTDB_get_product (TMH_db, + oc->hc->instance->settings.id, + ip->product_id, + &pd, + &num_categories, + &categories); if (qs <= 0) { enum TALER_ErrorCode ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE; @@ -3477,7 +3477,7 @@ add_donau_output (struct OrderContext *oc, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_donau_instances_filtered ( + qs = TALER_MERCHANTDB_iterate_donau_instances_filtered ( TMH_db, output->details.donation_receipt.amount.currency, &add_donau_url, @@ -4063,10 +4063,10 @@ phase_parse_request (struct OrderContext *oc) memset (&td, 0, sizeof (td)); - qs = TALER_MERCHANTDB_select_otp (TMH_db, - oc->hc->instance->settings.id, - otp_id, - &td); + qs = TALER_MERCHANTDB_get_otp (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 @@ -27,7 +27,7 @@ #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> #include "merchant-database/insert_otp.h" -#include "merchant-database/select_otp.h" +#include "merchant-database/get_otp.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_select_otp (TMH_db, - mi->settings.id, - device_id, - &etp); + qs = TALER_MERCHANTDB_get_otp (TMH_db, + mi->settings.id, + device_id, + &etp); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-products-PRODUCT_ID-lock.c b/src/backend/taler-merchant-httpd_post-private-products-PRODUCT_ID-lock.c @@ -28,7 +28,7 @@ #include <taler/taler_json_lib.h> #include "merchant-database/expire_locks.h" #include "merchant-database/lock_product.h" -#include "merchant-database/lookup_product.h" +#include "merchant-database/get_product.h" enum MHD_Result @@ -101,12 +101,12 @@ TMH_private_post_products_ID_lock ( "quantity"); } - qs = TALER_MERCHANTDB_lookup_product (TMH_db, - mi->settings.id, - product_id, - &pd, - &num_categories, - &categories); + qs = TALER_MERCHANTDB_get_product (TMH_db, + mi->settings.id, + product_id, + &pd, + &num_categories, + &categories); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-templates.c b/src/backend/taler-merchant-httpd_post-private-templates.c @@ -27,8 +27,8 @@ #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> #include "merchant-database/insert_template.h" -#include "merchant-database/lookup_template.h" -#include "merchant-database/select_otp_serial.h" +#include "merchant-database/get_template.h" +#include "merchant-database/get_otp_serial.h" /** @@ -148,10 +148,10 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, if (NULL != tp.otp_id) { - qs = TALER_MERCHANTDB_select_otp_serial (TMH_db, - mi->settings.id, - tp.otp_id, - &otp_serial); + qs = TALER_MERCHANTDB_get_otp_serial (TMH_db, + mi->settings.id, + tp.otp_id, + &otp_serial); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -203,10 +203,10 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, /* Test if a template of this id is known */ struct TALER_MERCHANTDB_TemplateDetails etp; - qs = TALER_MERCHANTDB_lookup_template (TMH_db, - mi->settings.id, - template_id, - &etp); + qs = TALER_MERCHANTDB_get_template (TMH_db, + mi->settings.id, + template_id, + &etp); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-private-tokenfamilies.c b/src/backend/taler-merchant-httpd_post-private-tokenfamilies.c @@ -28,7 +28,7 @@ #include <gnunet/gnunet_time_lib.h> #include <taler/taler_json_lib.h> #include "merchant-database/insert_token_family.h" -#include "merchant-database/lookup_token_family.h" +#include "merchant-database/get_token_family.h" #include "merchant-database/preflight.h" #include "merchant-database/start.h" @@ -287,10 +287,10 @@ TMH_private_post_token_families (const struct TMH_RequestHandler *rh, TALER_MERCHANTDB_rollback (TMH_db); break; case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - qs = TALER_MERCHANTDB_lookup_token_family (TMH_db, - mi->settings.id, - details.slug, - &existing); + qs = TALER_MERCHANTDB_get_token_family (TMH_db, + mi->settings.id, + details.slug, + &existing); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "lookup_token_family returned %d\n", (int) qs); diff --git a/src/backend/taler-merchant-httpd_post-private-webhooks.c b/src/backend/taler-merchant-httpd_post-private-webhooks.c @@ -27,7 +27,7 @@ #include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> #include "merchant-database/insert_webhook.h" -#include "merchant-database/lookup_webhook.h" +#include "merchant-database/get_webhook.h" #include "merchant-database/start.h" /** @@ -131,10 +131,10 @@ TMH_private_post_webhooks (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_START_FAILED, NULL); } - qs = TALER_MERCHANTDB_lookup_webhook (TMH_db, - mi->settings.id, - webhook_id, - &ewb); + qs = TALER_MERCHANTDB_get_webhook (TMH_db, + mi->settings.id, + webhook_id, + &ewb); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-httpd_post-reports-REPORT_ID.c b/src/backend/taler-merchant-httpd_post-reports-REPORT_ID.c @@ -24,7 +24,7 @@ #include "taler-merchant-httpd_dispatcher.h" #include "taler-merchant-httpd_post-reports-REPORT_ID.h" #include <taler/taler_json_lib.h> -#include "merchant-database/check_report.h" +#include "merchant-database/get_report_by_token.h" enum MHD_Result @@ -82,12 +82,12 @@ TMH_post_reports_ID ( MHD_HTTP_HEADER_ACCEPT); if (NULL == mime_type) mime_type = "application/json"; - qs = TALER_MERCHANTDB_check_report (TMH_db, - report_id, - &report_token, - mime_type, - &instance_id, - &data_source); + qs = TALER_MERCHANTDB_get_report_by_token (TMH_db, + report_id, + &report_token, + mime_type, + &instance_id, + &data_source); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-httpd_post-templates-TEMPLATE_ID.c b/src/backend/taler-merchant-httpd_post-templates-TEMPLATE_ID.c @@ -32,8 +32,8 @@ #include "taler/taler_merchant_util.h" #include <taler/taler_json_lib.h> #include <regex.h> -#include "merchant-database/lookup_product.h" -#include "merchant-database/lookup_template.h" +#include "merchant-database/get_product.h" +#include "merchant-database/get_template.h" /** @@ -637,10 +637,10 @@ handle_phase_lookup_template ( const char *template_id = uc->hc->infix; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_template (TMH_db, - mi->settings.id, - template_id, - &uc->lookup_template.etp); + qs = TALER_MERCHANTDB_get_template (TMH_db, + mi->settings.id, + template_id, + &uc->lookup_template.etp); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -751,12 +751,12 @@ handle_phase_db_fetch (struct UseContext *uc) &uc->parse_request.inventory.items[i]; enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_lookup_product (TMH_db, - mi->settings.id, - item->product_id, - &item->pd, - &item->num_categories, - &item->categories); + qs = TALER_MERCHANTDB_get_product (TMH_db, + mi->settings.id, + item->product_id, + &item->pd, + &item->num_categories, + &item->categories); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-kyccheck.c b/src/backend/taler-merchant-kyccheck.c @@ -40,10 +40,10 @@ struct Inquiry; #include "merchant-database/insert_kyc_status.h" #include "merchant-database/delete_tos_accepted_early.h" #include "merchant-database/get_kyc_status.h" -#include "merchant-database/lookup_tos_accepted_early.h" +#include "merchant-database/get_tos_accepted_early.h" #include "merchant-database/set_instance.h" -#include "merchant-database/select_accounts.h" -#include "merchant-database/select_exchange_keys.h" +#include "merchant-database/iterate_accounts.h" +#include "merchant-database/get_exchange_keys.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" #include "merchant-database/start.h" @@ -865,10 +865,10 @@ check_early_tos_acceptance (struct Inquiry *i, GNUNET_SCHEDULER_shutdown (); return; } - qs = TALER_MERCHANTDB_lookup_tos_accepted_early (pg, - i->a->instance_id, - i->e->keys->exchange_url, - &tos_version); + qs = TALER_MERCHANTDB_get_tos_accepted_early (pg, + i->a->instance_id, + i->e->keys->exchange_url, + &tos_version); GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance (pg, NULL)); @@ -1558,9 +1558,9 @@ find_accounts (void *cls) (void) cls; account_task = NULL; database_gen++; - qs = TALER_MERCHANTDB_select_accounts (pg, - &account_cb, - NULL); + qs = TALER_MERCHANTDB_iterate_accounts (pg, + &account_cb, + NULL); if (qs < 0) { GNUNET_break (0); @@ -1627,10 +1627,10 @@ find_keys (const char *exchange_url) struct Exchange *e; struct GNUNET_TIME_Absolute first_retry; - qs = TALER_MERCHANTDB_select_exchange_keys (pg, - exchange_url, - &first_retry, - &keys); + qs = TALER_MERCHANTDB_get_exchange_keys (pg, + exchange_url, + &first_retry, + &keys); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-reconciliation.c b/src/backend/taler-merchant-reconciliation.c @@ -32,10 +32,10 @@ struct Inquiry; #include "merchantdb_lib.h" #include "merchant-database/finalize_transfer_status.h" #include "merchant-database/insert_transfer_details.h" -#include "merchant-database/lookup_deposits_by_contract_and_coin.h" -#include "merchant-database/lookup_wire_fee.h" -#include "merchant-database/select_exchange_keys.h" -#include "merchant-database/select_open_transfers.h" +#include "merchant-database/iterate_deposits_by_contract_and_coin.h" +#include "merchant-database/get_wire_fee.h" +#include "merchant-database/get_exchange_keys.h" +#include "merchant-database/iterate_open_transfers.h" #include "merchant-database/set_instance.h" #include "merchant-database/update_transfer_status.h" #include "merchant-database/event_listen.h" @@ -348,10 +348,10 @@ sync_keys (struct Exchange *e) struct TALER_EXCHANGE_Keys *keys; struct GNUNET_TIME_Absolute first_retry; - qs = TALER_MERCHANTDB_select_exchange_keys (pg, - e->exchange_url, - &first_retry, - &keys); + qs = TALER_MERCHANTDB_get_exchange_keys (pg, + e->exchange_url, + &first_retry, + &keys); if (qs < 0) { GNUNET_break (0); @@ -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_lookup_wire_fee (pg, - &keys->master_pub, - wire_method, - execution_time, - &fees, - &start_date, - &end_date, - &master_sig); + qs = TALER_MERCHANTDB_get_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: @@ -871,7 +871,7 @@ wire_transfer_cb (struct Inquiry *w, ctc.current_detail = ttd; /* Set the coin as "never seen" before. */ ctc.check_transfer_result = GNUNET_NO; - qs = TALER_MERCHANTDB_lookup_deposits_by_contract_and_coin ( + qs = TALER_MERCHANTDB_iterate_deposits_by_contract_and_coin ( pg, w->instance_id, &ttd->h_contract_terms, @@ -1132,10 +1132,10 @@ find_work (void *cls) return; } at_limit = false; - qs = TALER_MERCHANTDB_select_open_transfers (pg, - limit, - &start_inquiry, - NULL); + qs = TALER_MERCHANTDB_iterate_open_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/lookup_reports_pending.h" +#include "merchant-database/iterate_reports_pending.h" #include "merchant-database/update_report_status.h" #include "merchant-database/set_instance.h" #include "merchant-database/event_listen.h" @@ -729,9 +729,9 @@ 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_lookup_reports_pending (pg, - &process_pending_report, - &next); + qs = TALER_MERCHANTDB_iterate_reports_pending (pg, + &process_pending_report, + &next); if (qs < 0) { GNUNET_break (0); diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c @@ -28,7 +28,7 @@ #include "merchantdb_lib.h" #include <taler/taler_dbevents.h> #include "merchant-database/delete_pending_webhook.h" -#include "merchant-database/lookup_pending_webhooks.h" +#include "merchant-database/iterate_pending_webhooks.h" #include "merchant-database/update_pending_webhook.h" #include "merchant-database/event_listen.h" #include "merchant-database/preflight.h" @@ -479,10 +479,10 @@ select_work (void *cls) return; } TALER_MERCHANTDB_preflight (pg); - qs = TALER_MERCHANTDB_lookup_pending_webhooks (pg, - limit, - &pending_webhooks_cb, - NULL); + qs = TALER_MERCHANTDB_iterate_pending_webhooks (pg, + limit, + &pending_webhooks_cb, + NULL); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -498,9 +498,9 @@ select_work (void *cls) GNUNET_SCHEDULER_shutdown (); return; } - qs = TALER_MERCHANTDB_lookup_pending_webhooks_next (pg, - &future_webhook_cb, - NULL); + qs = TALER_MERCHANTDB_iterate_pending_webhooks_next (pg, + &future_webhook_cb, + NULL); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c @@ -30,7 +30,7 @@ #include "merchantdb_lib.h" #include "merchant-database/insert_transfer.h" #include "merchant-database/set_instance.h" -#include "merchant-database/select_wirewatch_accounts.h" +#include "merchant-database/iterate_wirewatch_accounts.h" #include "merchant-database/update_wirewatch_progress.h" #include "merchant-database/event_listen.h" @@ -671,9 +671,9 @@ run (void *cls, { enum GNUNET_DB_QueryStatus qs; - qs = TALER_MERCHANTDB_select_wirewatch_accounts (pg, - &start_watch, - NULL); + qs = TALER_MERCHANTDB_iterate_wirewatch_accounts (pg, + &start_watch, + NULL); if (qs < 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/backenddb/check_donau_instance.c b/src/backenddb/check_donau_instance.c @@ -1,58 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/check_donau_instance.c - * @brief Implementation of the check_donau_instance function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/check_donau_instance.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_donau_instance ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *donau_url, - uint64_t charity_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (donau_url), - GNUNET_PQ_query_param_uint64 (&charity_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == - GNUNET_memcmp (merchant_pub, - &pg->current_merchant_pub)); - TMH_PQ_prepare_anon (pg, - "SELECT 1" - " FROM merchant_donau_instances" - " WHERE donau_url=$1" - " AND charity_id=$2"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/check_money_pots.c b/src/backenddb/check_money_pots.c @@ -1,69 +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/check_money_pots.c - * @brief Implementation of the check_money_pots function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/check_money_pots.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_money_pots ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - unsigned int pots_len, - uint64_t pots[static pots_len], - uint64_t *pot_missing) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_array_uint64 (pots_len, - pots, - pg->conn), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("out_missing", - pot_missing), - GNUNET_PQ_result_spec_end - }; - 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 n AS out_missing" - " FROM UNNEST($1::INT8[]) AS n" - " WHERE NOT EXISTS (" - " SELECT 1" - " FROM merchant_money_pots mmp" - " WHERE mmp.money_pot_serial=n" - " )" - " LIMIT 1;"); - qs = GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - return qs; -} diff --git a/src/backenddb/check_report.c b/src/backenddb/check_report.c @@ -1,61 +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/check_report.c - * @brief Implementation of the check_report function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/check_report.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_report ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t report_id, - const struct TALER_MERCHANT_ReportToken *report_token, - const char *mime_type, - char **instance_id, - char **data_source) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&report_id), - GNUNET_PQ_query_param_auto_from_type (report_token), - GNUNET_PQ_query_param_string (mime_type), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("out_merchant_id", - instance_id), - GNUNET_PQ_result_spec_string ("out_data_source", - data_source), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "check_report", - "SELECT" - " out_merchant_id" - " ,out_data_source" - " FROM merchant.check_report($1, $2, $3)"); - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "check_report", - params, - rs); -} diff --git a/src/backenddb/check_transfer_exists.c b/src/backenddb/check_transfer_exists.c @@ -1,53 +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/check_transfer_exists.c - * @brief Implementation of the check_transfer_exists function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/check_transfer_exists.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_transfer_exists ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t transfer_serial_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&transfer_serial_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - 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" - " 1" - " FROM merchant_transfers" - " WHERE credit_serial=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/get_account.c b/src/backenddb/get_account.c @@ -0,0 +1,79 @@ +/* + This file is part of TALER + Copyright (C) 2023, 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_account.c + * @brief Implementation of the get_account function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_account.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + const struct TALER_MerchantWireHashP *h_wire, + struct TALER_MERCHANTDB_AccountDetails *ad) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_wire), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("salt", + &ad->salt), + GNUNET_PQ_result_spec_string ("payto_uri", + &ad->payto_uri.full_payto), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("credit_facade_url", + &ad->credit_facade_url), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("credit_facade_credentials", + &ad->credit_facade_credentials), + NULL), + GNUNET_PQ_result_spec_bool ("active", + &ad->active), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata", + &ad->extra_wire_subject_metadata), + NULL), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (id, + pg->current_merchant_id)); + ad->h_wire = *h_wire; + ad->instance_id = id; + TMH_PQ_prepare_anon (pg, + "SELECT" + " salt" + ",payto_uri" + ",credit_facade_url" + ",credit_facade_credentials::TEXT" + ",active" + ",extra_wire_subject_metadata" + " FROM merchant_accounts" + " WHERE h_wire=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_account_by_uri.c b/src/backenddb/get_account_by_uri.c @@ -0,0 +1,77 @@ +/* + 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_account_by_uri.c + * @brief Implementation of the get_account_by_uri function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_account_by_uri.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account_by_uri ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + struct TALER_FullPayto payto_uri, + struct TALER_MERCHANTDB_AccountDetails *ad) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (payto_uri.full_payto), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("salt", + &ad->salt), + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &ad->h_wire), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("credit_facade_url", + &ad->credit_facade_url), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("credit_facade_credentials", + &ad->credit_facade_credentials), + NULL), + GNUNET_PQ_result_spec_bool ("active", + &ad->active), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (id, + pg->current_merchant_id)); + ad->credit_facade_url = NULL; + ad->credit_facade_credentials = NULL; + ad->payto_uri.full_payto + = GNUNET_strdup (payto_uri.full_payto); + ad->instance_id = id; + TMH_PQ_prepare_anon (pg, + "SELECT" + " salt" + ",h_wire" + ",credit_facade_url" + ",credit_facade_credentials::TEXT" + ",active" + " FROM merchant_accounts" + " WHERE payto_uri = $1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_account_serial.c b/src/backenddb/get_account_serial.c @@ -0,0 +1,57 @@ +/* + This file is part of TALER + Copyright (C) 2023, 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_account_serial.c + * @brief Implementation of the get_account_serial function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_account_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + uint64_t *account_serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (payto_uri.full_payto), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("account_serial", + account_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" + " account_serial" + " FROM merchant_accounts" + " WHERE REGEXP_REPLACE(payto_uri,'\\?.*','')" + " =REGEXP_REPLACE($1,'\\?.*','')"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_category.c b/src/backenddb/get_category.c @@ -0,0 +1,77 @@ +/* + 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/get_category.c + * @brief Implementation of the get_category function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_category.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_category ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t category_id, + struct TALER_MERCHANTDB_CategoryDetails *cd, + size_t *num_products, + char **products) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&category_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("category_name", + &cd->category_name), + TALER_PQ_result_spec_json ("category_name_i18n", + &cd->category_name_i18n), + GNUNET_PQ_result_spec_array_string (pg->conn, + "products", + num_products, + products), + 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" + " category_name" + ",category_name_i18n::TEXT" + ",t.product_array AS products" + " FROM merchant_categories mc" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT " + " mi.product_id AS product_id" + " FROM merchant_product_categories mpc" + " JOIN merchant_inventory mi" + " USING (product_serial)" + " WHERE mpc.category_serial = mc.category_serial" + " ) AS product_array" + " ) t" + " WHERE mc.category_serial=$1"); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_category_by_name.c b/src/backenddb/get_category_by_name.c @@ -0,0 +1,61 @@ +/* + 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/get_category_by_name.c + * @brief Implementation of the get_category_by_name function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_category_by_name.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_category_by_name ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *category_name, + json_t **name_i18n, + uint64_t *category_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (category_name), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("category_serial", + category_id), + TALER_PQ_result_spec_json ("category_name_i18n", + name_i18n), + 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" + " category_serial" + ",category_name_i18n::TEXT" + " FROM merchant_categories" + " WHERE category_name=$1"); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_contract_terms.c b/src/backenddb/get_contract_terms.c @@ -0,0 +1,73 @@ +/* + This file is part of TALER + Copyright (C) 2022-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/get_contract_terms.c + * @brief Implementation of the get_contract_terms function for Postgres + * @author Iván Ávalos + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_contract_terms.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + struct TALER_ClaimTokenP *claim_token) +{ + enum GNUNET_DB_QueryStatus qs; + struct TALER_ClaimTokenP ct; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",order_serial" + ",claim_token" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); + if (NULL != claim_token) + *claim_token = ct; + return qs; +} diff --git a/src/backenddb/get_contract_terms_pos.c b/src/backenddb/get_contract_terms_pos.c @@ -0,0 +1,90 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_contract_terms_pos.c + * @brief Implementation of the get_contract_terms_pos function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_contract_terms_pos.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms_pos ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + struct TALER_ClaimTokenP *claim_token, + char **pos_key, + enum TALER_MerchantConfirmationAlgorithm *pos_algorithm) +{ + enum GNUNET_DB_QueryStatus qs; + struct TALER_ClaimTokenP ct; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + uint32_t pos32 = TALER_MCA_NONE; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_bool ("paid", + paid), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("pos_key", + pos_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("pos_algorithm", + &pos32), + NULL), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",order_serial" + ",claim_token" + ",paid" + ",pos_key" + ",pos_algorithm" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); + *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; + if (NULL != claim_token) + *claim_token = ct; + return qs; +} diff --git a/src/backenddb/get_contract_terms_status.c b/src/backenddb/get_contract_terms_status.c @@ -0,0 +1,102 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_contract_terms_status.c + * @brief Implementation of the get_contract_terms_status function for Postgres + * @author Iván Ávalos + * @author Christian Grothoff + */ +#include "platform.h" +#include <sys/types.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_contract_terms_status.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + const char *session_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + bool *wired, + bool *session_matches, + struct TALER_ClaimTokenP *claim_token, + int16_t *choice_index) +{ + enum GNUNET_DB_QueryStatus qs; + struct TALER_ClaimTokenP ct; + uint16_t ci = 0; + bool choice_index_null = false; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + NULL == session_id + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_bool ("paid", + paid), + GNUNET_PQ_result_spec_bool ("wired", + wired), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_bool ("session_matches", + session_matches), + NULL), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint16 ("choice_index", + &ci), + &choice_index_null), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + *session_matches = false; + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",order_serial" + ",claim_token" + ",paid" + ",wired" + ",(session_id=$2) AS session_matches" + ",choice_index" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); + if (NULL != claim_token) + *claim_token = ct; + *choice_index = (choice_index_null) ? -1 : (int16_t) ci; + return qs; +} diff --git a/src/backenddb/get_donau_instance_by_serial.c b/src/backenddb/get_donau_instance_by_serial.c @@ -0,0 +1,59 @@ +/* + 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/get_donau_instance_by_serial.c + * @brief Implementation of the get_donau_instance_by_serial function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_donau_instance_by_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_instance_by_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t serial, + char **donau_url, + uint64_t *charity_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&serial), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("donau_url", + donau_url), + GNUNET_PQ_result_spec_uint64 ("charity_id", + charity_id), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "SELECT donau_url" + " ,charity_id" + " FROM merchant_donau_instances" + " WHERE donau_instances_serial = $1"); + + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_donau_keys.c b/src/backenddb/get_donau_keys.c @@ -0,0 +1,71 @@ +/* + 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/get_donau_keys.c + * @brief Implementation of the get_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "donau/donau_service.h" +#include "merchant-database/get_donau_keys.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_keys ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *donau_url, + struct GNUNET_TIME_Absolute *first_retry, + struct DONAU_Keys **keys) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (donau_url), + GNUNET_PQ_query_param_end + }; + json_t *jkeys; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_absolute_time ("first_retry", + first_retry), + TALER_PQ_result_spec_json ("keys_json", + &jkeys), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_donau_keys", + "SELECT" + " first_retry" + ",keys_json::TEXT" + " FROM merchant_donau_keys" + " WHERE donau_url=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_donau_keys", + params, + rs); + if (qs <= 0) + return qs; + *keys = DONAU_keys_from_json (jkeys); + json_decref (jkeys); + if (NULL == *keys) + { + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + return qs; +} diff --git a/src/backenddb/get_exchange_keys.c b/src/backenddb/get_exchange_keys.c @@ -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/backenddb/get_exchange_keys.c + * @brief Implementation of the get_exchange_keys function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include <taler/taler_exchange_service.h> +#include "merchant-database/get_exchange_keys.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exchange_keys ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + struct GNUNET_TIME_Absolute *first_retry, + struct TALER_EXCHANGE_Keys **keys) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_end + }; + json_t *jkeys = NULL; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_absolute_time ("first_retry", + first_retry), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("keys_json", + &jkeys), + NULL), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + *keys = NULL; + PREPARE (pg, + "select_exchange_keys", + "SELECT" + " first_retry" + ",keys_json::TEXT" + " FROM merchant.merchant_exchange_keys" + " WHERE exchange_url=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "select_exchange_keys", + params, + rs); + if (qs <= 0) + return qs; + if (NULL != jkeys) + { + *keys = TALER_EXCHANGE_keys_from_json (jkeys); + json_decref (jkeys); + } + return qs; +} diff --git a/src/backenddb/get_exists_donau_instance.c b/src/backenddb/get_exists_donau_instance.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_exists_donau_instance.c + * @brief Implementation of the get_exists_donau_instance function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_exists_donau_instance.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exists_donau_instance ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const char *donau_url, + uint64_t charity_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (donau_url), + GNUNET_PQ_query_param_uint64 (&charity_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == + GNUNET_memcmp (merchant_pub, + &pg->current_merchant_pub)); + TMH_PQ_prepare_anon (pg, + "SELECT 1" + " FROM merchant_donau_instances" + " WHERE donau_url=$1" + " AND charity_id=$2"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_exists_transfer.c b/src/backenddb/get_exists_transfer.c @@ -0,0 +1,53 @@ +/* + 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_exists_transfer.c + * @brief Implementation of the get_exists_transfer function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_exists_transfer.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exists_transfer ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t transfer_serial_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&transfer_serial_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + 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" + " 1" + " FROM merchant_transfers" + " WHERE credit_serial=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_expected_transfer.c b/src/backenddb/get_expected_transfer.c @@ -0,0 +1,98 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_expected_transfer.c + * @brief Implementation of the get_expected_transfer function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_expected_transfer.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_expected_transfer ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t expected_incoming_serial, + struct GNUNET_TIME_Timestamp *expected_time, + struct TALER_Amount *expected_credit_amount, + struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto *payto_uri, + char **exchange_url, + struct GNUNET_TIME_Timestamp *execution_time, + bool *confirmed, + struct TALER_MasterPublicKeyP *master_pub) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_timestamp ("expected_time", + expected_time), + GNUNET_PQ_result_spec_bool ("confirmed", + confirmed), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", + expected_credit_amount), + NULL), + GNUNET_PQ_result_spec_string ("exchange_url", + exchange_url), + GNUNET_PQ_result_spec_auto_from_type ("wtid", + wtid), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto_uri->full_payto), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("execution_time", + execution_time), + NULL), + GNUNET_PQ_result_spec_auto_from_type ("master_pub", + master_pub), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + *execution_time = GNUNET_TIME_UNIT_ZERO_TS; + memset (expected_credit_amount, + 0, + sizeof (*expected_credit_amount)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " met.expected_time" + " ,met.confirmed" + " ,met.expected_credit_amount" + " ,met.exchange_url" + " ,met.wtid" + " ,ma.payto_uri" + " ,mts.execution_time" + " ,esk.master_pub" + " FROM merchant_expected_transfers met" + " JOIN merchant.merchant_exchange_signing_keys esk" + " USING (signkey_serial)" + " JOIN merchant_accounts ma" + " USING (account_serial)" + " LEFT JOIN merchant_transfer_signatures mts" + " USING (expected_credit_serial)" + " WHERE met.expected_credit_serial=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_instance_auth.c b/src/backenddb/get_instance_auth.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_instance_auth.c + * @brief Implementation of the get_instance_auth function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_instance_auth.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_instance_auth ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_MERCHANTDB_InstanceAuthSettings *ias) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("auth_hash", + &ias->auth_hash), + GNUNET_PQ_result_spec_auto_from_type ("auth_salt", + &ias->auth_salt), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "lookup_instance_auth", + "SELECT" + " auth_hash" + ",auth_salt" + " FROM merchant.merchant_instances" + " WHERE merchant_id=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_instance_auth", + params, + rs); +} diff --git a/src/backenddb/get_login_token.c b/src/backenddb/get_login_token.c @@ -0,0 +1,60 @@ +/* + 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_login_token.c + * @brief Implementation of the get_login_token function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_login_token.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_login_token ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + const struct TALER_MERCHANTDB_LoginTokenP *token, + struct GNUNET_TIME_Timestamp *expiration_time, + uint32_t *validity_scope) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (token), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_timestamp ("expiration_time", + expiration_time), + GNUNET_PQ_result_spec_uint32 ("validity_scope", + validity_scope), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " expiration_time" + ",validity_scope" + " FROM merchant_login_tokens" + " WHERE token=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_mfa_challenge.c b/src/backenddb/get_mfa_challenge.c @@ -0,0 +1,110 @@ +/* + 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_mfa_challenge.c + * @brief Implementation of the get_mfa_challenge function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "taler/taler_merchant_util.h" +#include "merchantdb_lib.h" +#include "merchant-database/get_mfa_challenge.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_mfa_challenge ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t challenge_id, + const struct TALER_MERCHANT_MFA_BodyHash *h_body, + struct TALER_MERCHANT_MFA_BodySalt *salt, + char **required_address, + enum TALER_MERCHANT_MFA_CriticalOperation *op, + struct GNUNET_TIME_Absolute *confirmation_date, + struct GNUNET_TIME_Absolute *retransmission_date, + uint32_t *retry_counter, + enum TALER_MERCHANT_MFA_Channel *tan_channel, + char **instance_name) +{ + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&challenge_id), + GNUNET_PQ_query_param_auto_from_type (h_body), + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_end + }; + char *op_str; + char *chan_str; + bool no_conf; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("op", + &op_str), + GNUNET_PQ_result_spec_auto_from_type ("salt", + salt), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_absolute_time ("confirmation_date", + confirmation_date), + &no_conf), + GNUNET_PQ_result_spec_absolute_time ("retransmission_date", + retransmission_date), + GNUNET_PQ_result_spec_uint32 ("retry_counter", + retry_counter), + GNUNET_PQ_result_spec_string ("tan_channel", + &chan_str), + GNUNET_PQ_result_spec_string ("required_address", + required_address), + GNUNET_PQ_result_spec_string ("instance_name", + instance_name), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_mfa_challenge", + "SELECT " + " op::TEXT" + " ,salt" + " ,confirmation_date" + " ,retransmission_date" + " ,retry_counter" + " ,required_address" + " ,tan_channel::TEXT" + " ,instance_name" + " FROM merchant.tan_challenges" + " WHERE (challenge_id = $1)" + " AND (h_body = $2)" + " AND (expiration_date > $3)"); + /* Initialize to conservative values in case qs ends up <= 0 */ + *tan_channel = TALER_MERCHANT_MFA_CHANNEL_NONE; + *op = TALER_MERCHANT_MFA_CO_NONE; + *instance_name = NULL; + *required_address = NULL; + *retry_counter = 0; + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_mfa_challenge", + params, + rs); + if (qs <= 0) + return qs; + if (no_conf) + *confirmation_date = GNUNET_TIME_UNIT_FOREVER_ABS; + *tan_channel = TALER_MERCHANT_MFA_channel_from_string (chan_str); + *op = TALER_MERCHANT_MFA_co_from_string (op_str); + GNUNET_free (chan_str); + GNUNET_free (op_str); + return qs; +} diff --git a/src/backenddb/get_missing_money_pot.c b/src/backenddb/get_missing_money_pot.c @@ -0,0 +1,69 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_missing_money_pot.c + * @brief Implementation of the get_missing_money_pot function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_missing_money_pot.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_missing_money_pot ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + unsigned int pots_len, + uint64_t pots[static pots_len], + uint64_t *pot_missing) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_array_uint64 (pots_len, + pots, + pg->conn), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_missing", + pot_missing), + GNUNET_PQ_result_spec_end + }; + 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 n AS out_missing" + " FROM UNNEST($1::INT8[]) AS n" + " WHERE NOT EXISTS (" + " SELECT 1" + " FROM merchant_money_pots mmp" + " WHERE mmp.money_pot_serial=n" + " )" + " LIMIT 1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + return qs; +} diff --git a/src/backenddb/get_money_pot.c b/src/backenddb/get_money_pot.c @@ -0,0 +1,69 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_money_pot.c + * @brief Implementation of the get_money_pot function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_money_pot.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_money_pot ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t money_pot_id, + char **name, + char **description, + size_t *pot_total_len, + struct TALER_Amount **pot_totals) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&money_pot_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("money_pot_name", + name), + GNUNET_PQ_result_spec_string ("money_pot_description", + description), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "pot_totals", + pot_total_len, + pot_totals), + 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" + " money_pot_name" + " ,money_pot_description" + " ,pot_totals" + " FROM merchant_money_pots" + " WHERE money_pot_serial=$1;"); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_order.c b/src/backenddb/get_order.c @@ -0,0 +1,91 @@ +/* + 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_order.c + * @brief Implementation of the get_order function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_order.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct TALER_ClaimTokenP *claim_token, + struct TALER_MerchantPostDataHashP *h_post_data, + json_t **contract_terms) +{ + json_t *j; + struct TALER_ClaimTokenP ct; + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_json ("contract_terms", + &j), + GNUNET_PQ_result_spec_auto_from_type ("claim_token", + &ct), + GNUNET_PQ_result_spec_auto_from_type ("h_post_data", + h_post_data), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Finding contract term, order_id: '%s', instance_id: '%s'.\n", + order_id, + instance_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " contract_terms::TEXT" + ",claim_token" + ",h_post_data" + " FROM merchant_orders" + " WHERE order_id=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + if (NULL != contract_terms) + *contract_terms = j; + else + json_decref (j); + if (NULL != claim_token) + *claim_token = ct; + } + else + { + /* just to be safe: NULL it */ + if (NULL != contract_terms) + *contract_terms = NULL; + if (NULL != claim_token) + memset (claim_token, + 0, + sizeof (struct TALER_ClaimTokenP)); + } + return qs; +} diff --git a/src/backenddb/get_order_by_fulfillment.c b/src/backenddb/get_order_by_fulfillment.c @@ -0,0 +1,73 @@ +/* + 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_order_by_fulfillment.c + * @brief Implementation of the get_order_by_fulfillment function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_order_by_fulfillment.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_by_fulfillment ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *fulfillment_url, + const char *session_id, + bool allow_refunded_for_repurchase, + char **order_id) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (fulfillment_url), + GNUNET_PQ_query_param_string (session_id), + GNUNET_PQ_query_param_bool (allow_refunded_for_repurchase), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("order_id", + order_id), + 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" + " mct.order_id" + " FROM merchant_contract_terms mct" + " LEFT JOIN merchant_refunds mref" + " USING (order_serial)" + " WHERE fulfillment_url=$1" + " AND session_id=$2" + " AND ((CAST($3 AS BOOL)) OR" + " mref.refund_serial IS NULL)" + /* Theoretically, multiple paid orders + for the same fulfillment URL could + exist for this session_id -- if a + wallet was broken and did multiple + payments without repurchase detection. + So we need to limit to 1 when returning! */ + " ORDER BY order_id DESC" + " LIMIT 1;"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_order_charity.c b/src/backenddb/get_order_charity.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_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_order_status.c b/src/backenddb/get_order_status.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/get_order_status.c + * @brief Implementation of the get_order_status function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_order_status.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct TALER_PrivateContractHashP *h_contract_terms, + bool *paid) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + h_contract_terms), + GNUNET_PQ_result_spec_bool ("paid", + paid), + 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" + " h_contract_terms" + ",paid" + " FROM merchant_contract_terms" + " WHERE order_id=$1"); + *paid = false; + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_order_status_by_serial.c b/src/backenddb/get_order_status_by_serial.c @@ -0,0 +1,65 @@ +/* + 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/get_order_status_by_serial.c + * @brief Implementation of the get_order_status_by_serial function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_order_status_by_serial.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_status_by_serial ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t order_serial, + char **order_id, + struct TALER_PrivateContractHashP *h_contract_terms, + bool *paid) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&order_serial), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + h_contract_terms), + GNUNET_PQ_result_spec_string ("order_id", + order_id), + GNUNET_PQ_result_spec_bool ("paid", + paid), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + *paid = false; /* just to be safe(r) */ + TMH_PQ_prepare_anon (pg, + "SELECT" + " h_contract_terms" + ",order_id" + ",paid" + " FROM merchant_contract_terms" + " WHERE order_serial=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_order_summary.c b/src/backenddb/get_order_summary.c @@ -0,0 +1,66 @@ +/* + 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_order_summary.c + * @brief Implementation of the get_order_summary function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_order_summary.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_summary ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct GNUNET_TIME_Timestamp *timestamp, + uint64_t *order_serial) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (order_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_timestamp ("creation_time", + timestamp), + 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" + " creation_time" + ",order_serial" + " FROM merchant_contract_terms" + " WHERE order_id=$1)" + "UNION" + "(SELECT" + " creation_time" + ",order_serial" + " FROM merchant_orders" + " WHERE order_id=$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 @@ -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.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_serial.c b/src/backenddb/get_otp_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_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_product.c b/src/backenddb/get_product.c @@ -0,0 +1,196 @@ +/* + 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/get_product.c + * @brief Implementation of the get_product function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_product.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_product ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *product_id, + struct TALER_MERCHANTDB_ProductDetails *pd, + size_t *num_categories, + uint64_t **categories) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (product_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, + "SELECT" + " mi.description" + ",mi.description_i18n::TEXT" + ",mi.product_name" + ",mi.unit" + ",mi.price_array" + ",mi.taxes::TEXT" + ",mi.total_stock" + ",mi.total_stock_frac" + ",mi.allow_fractional_quantity" + ",mi.fractional_precision_level" + ",mi.total_sold" + ",mi.total_sold_frac" + ",mi.total_lost" + ",mi.total_lost_frac" + ",mi.total_locked" + ",mi.total_locked_frac" + ",mi.image" + ",mi.address::TEXT" + ",mi.next_restock" + ",mi.minimum_age" + ",mi.product_group_serial" + ",mi.money_pot_serial" + ",mi.price_is_net" + ",t.category_array AS categories" + " FROM merchant_inventory mi" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT mpc.category_serial" + " FROM merchant_product_categories mpc" + " WHERE mpc.product_serial = mi.product_serial" + " ) AS category_array" + " ) t" + " WHERE mi.product_id=$1" + ); + if (NULL == pd) // FIXME: is this case needed? For now yes: delete-private-products-PRODUCT_ID uses it! + { + struct GNUNET_PQ_ResultSpec rs_null[] = { + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs_null); + } + else + { + char *my_name = NULL; + char *my_description = NULL; + json_t *my_description_i18n = NULL; + char *my_unit = NULL; + char *my_image = NULL; + json_t *my_address = NULL; + json_t *my_taxes = NULL; + uint64_t *my_categories = NULL; + struct TALER_Amount *my_price_array = NULL; + size_t my_price_array_length = 0; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("description", + &my_description), + TALER_PQ_result_spec_json ("description_i18n", + &my_description_i18n), + GNUNET_PQ_result_spec_string ("product_name", + &my_name), + GNUNET_PQ_result_spec_string ("unit", + &my_unit), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "price_array", + &my_price_array_length, + &my_price_array), + TALER_PQ_result_spec_json ("taxes", + &my_taxes), + GNUNET_PQ_result_spec_uint64 ("total_stock", + &pd->total_stock), + GNUNET_PQ_result_spec_uint32 ("total_stock_frac", + &pd->total_stock_frac), + GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", + &pd->allow_fractional_quantity), + GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", + &pd->fractional_precision_level), + GNUNET_PQ_result_spec_uint64 ("total_sold", + &pd->total_sold), + GNUNET_PQ_result_spec_uint32 ("total_sold_frac", + &pd->total_sold_frac), + GNUNET_PQ_result_spec_uint64 ("total_lost", + &pd->total_lost), + GNUNET_PQ_result_spec_uint32 ("total_lost_frac", + &pd->total_lost_frac), + GNUNET_PQ_result_spec_uint64 ("total_locked", + &pd->total_locked), + GNUNET_PQ_result_spec_uint32 ("total_locked_frac", + &pd->total_locked_frac), + GNUNET_PQ_result_spec_string ("image", + &my_image), + TALER_PQ_result_spec_json ("address", + &my_address), + GNUNET_PQ_result_spec_timestamp ("next_restock", + &pd->next_restock), + GNUNET_PQ_result_spec_uint32 ("minimum_age", + &pd->minimum_age), + GNUNET_PQ_result_spec_array_uint64 (pg->conn, + "categories", + num_categories, + &my_categories), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint64 ("product_group_serial", + &pd->product_group_id), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint64 ("money_pot_serial", + &pd->money_pot_id), + NULL), + GNUNET_PQ_result_spec_bool ("price_is_net", + &pd->price_is_net), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_DB_QueryStatus qs; + + pd->product_group_id = 0; + pd->money_pot_id = 0; + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + pd->product_name = my_name; + pd->description = my_description; + pd->description_i18n = my_description_i18n; + pd->unit = my_unit; + pd->taxes = my_taxes; + pd->image = my_image; + pd->image_hash = NULL; + pd->address = my_address; + pd->price_array = my_price_array; + pd->price_array_length = my_price_array_length; + *categories = my_categories; + /* Clear original pointers to that cleanup_result doesn't squash them */ + my_name = NULL; + my_description = NULL; + my_description_i18n = NULL; + my_unit = NULL; + my_taxes = NULL; + my_image = NULL; + my_address = NULL; + my_price_array = NULL; + my_price_array_length = 0; + my_categories = NULL; + GNUNET_PQ_cleanup_result (rs); + return qs; + } +} diff --git a/src/backenddb/get_product_image_by_hash.c b/src/backenddb/get_product_image_by_hash.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_product_image_by_hash.c + * @brief Implementation of the get_product_image_by_hash function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "merchantdb_lib.h" +#include "merchant-database/get_product_image_by_hash.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_product_image_by_hash ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *image_hash, + char **image) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (image_hash), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("image", + image), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon ( + pg, + "SELECT" + " mi.image" + " FROM merchant_inventory mi" + " WHERE mi.image_hash=$1"); + *image = NULL; + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_refund_proof.c b/src/backenddb/get_refund_proof.c @@ -0,0 +1,60 @@ +/* + 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_refund_proof.c + * @brief Implementation of the get_refund_proof function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_refund_proof.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_refund_proof ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t refund_serial, + struct TALER_ExchangeSignatureP *exchange_sig, + struct TALER_ExchangePublicKeyP *exchange_pub) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&refund_serial), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", + exchange_sig), + GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", + exchange_pub), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " merchant.merchant_exchange_signing_keys.exchange_pub" + ",exchange_sig" + " FROM merchant_refund_proofs" + " JOIN merchant.merchant_exchange_signing_keys" + " USING (signkey_serial)" + " WHERE" + " refund_serial=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_report.c b/src/backenddb/get_report.c @@ -0,0 +1,103 @@ +/* + 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_report.c + * @brief Implementation of the get_report function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_report.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_report ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t report_id, + char **report_program_section, + char **report_description, + char **mime_type, + char **data_source, + char **target_address, + struct GNUNET_TIME_Relative *frequency, + struct GNUNET_TIME_Relative *frequency_shift, + struct GNUNET_TIME_Absolute *next_transmission, + enum TALER_ErrorCode *last_error_code, + char **last_error_detail) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&report_id), + GNUNET_PQ_query_param_end + }; + uint32_t code; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("report_program_section", + report_program_section), + GNUNET_PQ_result_spec_string ("report_description", + report_description), + GNUNET_PQ_result_spec_string ("mime_type", + mime_type), + GNUNET_PQ_result_spec_string ("data_source", + data_source), + GNUNET_PQ_result_spec_string ("target_address", + target_address), + GNUNET_PQ_result_spec_relative_time ("frequency", + frequency), + GNUNET_PQ_result_spec_relative_time ("frequency_shift", + frequency_shift), + GNUNET_PQ_result_spec_absolute_time ("next_transmission", + next_transmission), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("last_error_code", + &code), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("last_error_detail", + last_error_detail), + NULL), + 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)); + *last_error_detail = NULL; + code = TALER_EC_NONE; + TMH_PQ_prepare_anon (pg, + "SELECT" + " report_program_section" + " ,report_description" + " ,mime_type" + " ,data_source" + " ,target_address" + " ,frequency" + " ,frequency_shift" + " ,next_transmission" + " ,last_error_code" + " ,last_error_detail" + " FROM merchant_reports" + " WHERE report_serial=$1;"); + qs = GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "", + params, + rs); + *last_error_code = (enum TALER_ErrorCode) code; + return qs; +} diff --git a/src/backenddb/get_report_by_token.c b/src/backenddb/get_report_by_token.c @@ -0,0 +1,61 @@ +/* + 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_report_by_token.c + * @brief Implementation of the get_report_by_token function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_report_by_token.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_report_by_token ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t report_id, + const struct TALER_MERCHANT_ReportToken *report_token, + const char *mime_type, + char **instance_id, + char **data_source) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&report_id), + GNUNET_PQ_query_param_auto_from_type (report_token), + GNUNET_PQ_query_param_string (mime_type), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("out_merchant_id", + instance_id), + GNUNET_PQ_result_spec_string ("out_data_source", + data_source), + GNUNET_PQ_result_spec_end + }; + + PREPARE (pg, + "check_report", + "SELECT" + " out_merchant_id" + " ,out_data_source" + " FROM merchant.check_report($1, $2, $3)"); + return GNUNET_PQ_eval_prepared_singleton_select ( + pg->conn, + "check_report", + params, + rs); +} diff --git a/src/backenddb/check_report.sql b/src/backenddb/get_report_by_token.sql diff --git a/src/backenddb/get_template.c b/src/backenddb/get_template.c @@ -0,0 +1,77 @@ +/* + This file is part of TALER + Copyright (C) 2022, 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/get_template.c + * @brief Implementation of the get_template function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_template.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_template ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *template_id, + struct TALER_MERCHANTDB_TemplateDetails *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (template_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("template_description", + &td->template_description), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("otp_id", + &td->otp_id), + NULL), + TALER_PQ_result_spec_json ("template_contract", + &td->template_contract), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("editable_defaults", + &td->editable_defaults), + NULL), + 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" + " mt.template_description" + ",mod.otp_id" + ",mt.template_contract::TEXT" + ",mt.editable_defaults::TEXT" + " FROM merchant_template mt" + " LEFT JOIN merchant_otp_devices mod" + " ON (mod.otp_serial = mt.otp_device_id)" + " WHERE mt.template_id=$1"); + memset (td, + 0, + sizeof (*td)); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + GNUNET_PQ_cleanup_query_params_closures (params); + return qs; +} diff --git a/src/backenddb/get_token_family.c b/src/backenddb/get_token_family.c @@ -0,0 +1,119 @@ +/* + This file is part of TALER + Copyright (C) 2023, 2024, 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_token_family.c + * @brief Implementation of the get_token_family function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_token_family.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_token_family ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct TALER_MERCHANTDB_TokenFamilyDetails *details) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (token_family_slug), + GNUNET_PQ_query_param_end + }; + char *kind; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("slug", + &details->slug), + GNUNET_PQ_result_spec_string ("name", + &details->name), + GNUNET_PQ_result_spec_string ("cipher_choice", + &details->cipher_spec), + GNUNET_PQ_result_spec_string ("description", + &details->description), + TALER_PQ_result_spec_json ("description_i18n", + &details->description_i18n), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("extra_data", + &details->extra_data), + NULL), + GNUNET_PQ_result_spec_timestamp ("valid_after", + &details->valid_after), + GNUNET_PQ_result_spec_timestamp ("valid_before", + &details->valid_before), + GNUNET_PQ_result_spec_relative_time ("duration", + &details->duration), + GNUNET_PQ_result_spec_relative_time ("validity_granularity", + &details->validity_granularity), + GNUNET_PQ_result_spec_relative_time ("start_offset", + &details->start_offset), + GNUNET_PQ_result_spec_string ("kind", + &kind), + GNUNET_PQ_result_spec_uint64 ("issued", + &details->issued), + GNUNET_PQ_result_spec_uint64 ("used", + &details->used), + 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" + " slug" + ",name" + ",cipher_choice" + ",description" + ",description_i18n::TEXT" + ",extra_data::TEXT" + ",valid_after" + ",valid_before" + ",duration" + ",validity_granularity" + ",start_offset" + ",kind" + ",issued" + ",used" + " FROM merchant_token_families" + " WHERE slug=$1"); + memset (details, + 0, + sizeof (*details)); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + if (0 == strcmp (kind, + "discount")) + details->kind = TALER_MERCHANTDB_TFK_Discount; + else if (0 == strcmp (kind, + "subscription")) + details->kind = TALER_MERCHANTDB_TFK_Subscription; + else + { + GNUNET_break (0); + GNUNET_PQ_cleanup_result (rs); + return GNUNET_DB_STATUS_HARD_ERROR; + } + GNUNET_free (kind); + } + return qs; +} diff --git a/src/backenddb/get_token_family_key.c b/src/backenddb/get_token_family_key.c @@ -0,0 +1,168 @@ +/* + 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/get_token_family_key.c + * @brief Implementation of the get_token_family_key function for Postgres + * @author Christian Blättler + */ +#include "platform.h" +#include <gnunet/gnunet_pq_lib.h> +#include <gnunet/gnunet_time_lib.h> +#include <string.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_token_family_key.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_token_family_key ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct GNUNET_TIME_Timestamp valid_at, + struct GNUNET_TIME_Timestamp sign_until, + struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (token_family_slug), + GNUNET_PQ_query_param_timestamp (&valid_at), + GNUNET_PQ_query_param_timestamp (&sign_until), + GNUNET_PQ_query_param_end + }; + char *kind; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_blind_sign_pub ("pub", + &details->pub.public_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_blind_sign_priv ("priv", + &details->priv.private_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("signature_validity_start", + &details->signature_validity_start), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("signature_validity_end", + &details->signature_validity_end), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("private_key_deleted_at", + &details->private_key_deleted_at), + NULL), + GNUNET_PQ_result_spec_string ("slug", + &details->token_family.slug), + GNUNET_PQ_result_spec_string ("name", + &details->token_family.name), + GNUNET_PQ_result_spec_string ("cipher_choice", + &details->token_family.cipher_spec), + GNUNET_PQ_result_spec_string ("description", + &details->token_family.description), + TALER_PQ_result_spec_json ("description_i18n", + &details->token_family.description_i18n), + GNUNET_PQ_result_spec_timestamp ("valid_after", + &details->token_family.valid_after), + GNUNET_PQ_result_spec_timestamp ("valid_before", + &details->token_family.valid_before), + GNUNET_PQ_result_spec_relative_time ("duration", + &details->token_family.duration), + GNUNET_PQ_result_spec_relative_time ("validity_granularity", + &details->token_family. + validity_granularity), + GNUNET_PQ_result_spec_relative_time ("start_offset", + &details->token_family.start_offset), + GNUNET_PQ_result_spec_string ("kind", + &kind), + GNUNET_PQ_result_spec_uint64 ("issued", + &details->token_family.issued), + GNUNET_PQ_result_spec_uint64 ("used", + &details->token_family.used), + 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" + " h_pub" + ",pub" + ",priv" + ",cipher_choice" + ",mtfk.signature_validity_start" + ",mtfk.signature_validity_end" + ",mtfk.private_key_deleted_at" + ",slug" + ",name" + ",description" + ",description_i18n::TEXT" + ",mtf.valid_after" + ",mtf.valid_before" + ",duration" + ",validity_granularity" + ",start_offset" + ",kind" + ",issued" + ",used" + " FROM merchant_token_families mtf" + " LEFT JOIN merchant_token_family_keys mtfk" + " ON ( (mtf.token_family_serial = mtfk.token_family_serial)" + " AND ($2 >= mtfk.signature_validity_start)" + " AND ($2 <= mtfk.signature_validity_end)" + " AND ($3 <= mtfk.private_key_deleted_at) )" + " WHERE slug=$1" + " ORDER BY mtfk.signature_validity_start ASC" + " LIMIT 1"); + memset (details, + 0, + sizeof (*details)); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + if (0 == strcmp (kind, + "discount")) + { + details->token_family.kind = TALER_MERCHANTDB_TFK_Discount; + } + else if (0 == strcmp (kind, + "subscription")) + { + details->token_family.kind = TALER_MERCHANTDB_TFK_Subscription; + } + else + { + GNUNET_free (kind); + GNUNET_free (details->token_family.slug); + GNUNET_free (details->token_family.name); + GNUNET_free (details->token_family.description); + json_decref (details->token_family.description_i18n); + GNUNET_CRYPTO_blind_sign_pub_decref (details->pub.public_key); + GNUNET_CRYPTO_blind_sign_priv_decref (details->priv.private_key); + GNUNET_free (details->token_family.cipher_spec); + GNUNET_break (0); + return GNUNET_DB_STATUS_HARD_ERROR; + } + GNUNET_free (kind); + } + return qs; +} diff --git a/src/backenddb/get_tos_accepted_early.c b/src/backenddb/get_tos_accepted_early.c @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/get_tos_accepted_early.c + * @brief Implementation of the get_tos_accepted_early function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_tos_accepted_early.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_tos_accepted_early ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *merchant_id, + const char *exchange_url, + char **tos_version) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("tos_version", + tos_version), + GNUNET_PQ_result_spec_end + }; + + *tos_version = NULL; + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (merchant_id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT tos_version" + " FROM merchant_tos_accepted" + " WHERE exchange_url=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_unit.c b/src/backenddb/get_unit.c @@ -0,0 +1,110 @@ +/* + 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_unit.c + * @brief Implementation of the get_unit function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_unit.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_unit ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *unit_id, + struct TALER_MERCHANTDB_UnitDetails *ud) +{ + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (unit_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("unit_serial", + &ud->unit_serial), + GNUNET_PQ_result_spec_string ("unit", + &ud->unit), + GNUNET_PQ_result_spec_string ("unit_name_long", + &ud->unit_name_long), + GNUNET_PQ_result_spec_string ("unit_name_short", + &ud->unit_name_short), + TALER_PQ_result_spec_json ("unit_name_long_i18n", + &ud->unit_name_long_i18n), + TALER_PQ_result_spec_json ("unit_name_short_i18n", + &ud->unit_name_short_i18n), + GNUNET_PQ_result_spec_bool ("unit_allow_fraction", + &ud->unit_allow_fraction), + GNUNET_PQ_result_spec_uint32 ("unit_precision_level", + &ud->unit_precision_level), + GNUNET_PQ_result_spec_bool ("unit_active", + &ud->unit_active), + GNUNET_PQ_result_spec_bool ("unit_builtin", + &ud->unit_builtin), + GNUNET_PQ_result_spec_end + }; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + // FIXME: combine both SELECT statements into a single statement! + TMH_PQ_prepare_anon (pg, + "SELECT" + " cu.unit_serial" + " ,cu.unit" + " ,cu.unit_name_long" + " ,cu.unit_name_short" + " ,cu.unit_name_long_i18n" + " ,cu.unit_name_short_i18n" + " ,cu.unit_allow_fraction" + " ,cu.unit_precision_level" + " ,cu.unit_active" + " ,FALSE AS unit_builtin" + " FROM merchant_custom_units cu" + " WHERE cu.unit=$1"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs) + return qs; + TMH_PQ_prepare_anon (pg, + "SELECT" + " bu.unit_serial" + " ,bu.unit" + " ,bu.unit_name_long" + " ,bu.unit_name_short" + " ,bu.unit_name_long_i18n" + " ,bu.unit_name_short_i18n" + " ,COALESCE(bo.override_allow_fraction, bu.unit_allow_fraction)" + " AS unit_allow_fraction" + " ,COALESCE(bo.override_precision_level, bu.unit_precision_level)" + " AS unit_precision_level" + " ,COALESCE(bo.override_active, bu.unit_active)" + " AS unit_active" + " ,TRUE AS unit_builtin" + " FROM merchant.merchant_builtin_units bu" + " LEFT JOIN merchant_builtin_unit_overrides bo" + " ON bo.builtin_unit_serial = bu.unit_serial" + " WHERE bu.unit=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs); +} diff --git a/src/backenddb/get_webhook.c b/src/backenddb/get_webhook.c @@ -0,0 +1,88 @@ +/* + 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_webhook.c + * @brief Implementation of the get_webhook function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/get_webhook.h" +#include "helper.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_webhook ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *webhook_id, + struct TALER_MERCHANTDB_WebhookDetails *wb) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (webhook_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, + "SELECT" + " event_type" + ",url" + ",http_method" + ",header_template" + ",body_template" + " FROM merchant_webhook" + " WHERE webhook_id=$1"); + + if (NULL == wb) // fIXME: is this case needed? + { + struct GNUNET_PQ_ResultSpec rs_null[] = { + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "", + params, + rs_null); + } + else + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("event_type", + &wb->event_type), + GNUNET_PQ_result_spec_string ("url", + &wb->url), + GNUNET_PQ_result_spec_string ("http_method", + &wb->http_method), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("header_template", + &wb->header_template), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("body_template", + &wb->body_template), + NULL), + GNUNET_PQ_result_spec_end + }; + + 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 @@ -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_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/iterate_accounts.c b/src/backenddb/iterate_accounts.c @@ -0,0 +1,170 @@ +/* + This file is part of TALER + Copyright (C) 2022, 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_accounts.c + * @brief Implementation of the iterate_accounts function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_accounts.h" +#include "helper.h" + + +/** + * Context for select_accounts(). + */ +struct SelectAccountsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AccountCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Database context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Set to the return value on errors. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * 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 SelectAccountsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_account_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectAccountsContext *lic = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_FullPayto payto; + char *instance_id; + char *facade_url = NULL; + char *extra_wire_subject_metadata = NULL; + json_t *credential = NULL; + struct TALER_MERCHANTDB_AccountDetails acc; + struct TALER_MerchantPrivateKeyP merchant_priv; + bool no_priv; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("out_h_wire", + &acc.h_wire), + GNUNET_PQ_result_spec_auto_from_type ("out_salt", + &acc.salt), + GNUNET_PQ_result_spec_string ("out_payto_uri", + &payto.full_payto), + GNUNET_PQ_result_spec_string ("out_merchant_id", + &instance_id), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("out_credit_facade_url", + &facade_url), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("out_extra_wire_subject_metadata", + &extra_wire_subject_metadata), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("out_credit_facade_credentials", + &credential), + NULL), + GNUNET_PQ_result_spec_bool ("out_active", + &acc.active), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("out_merchant_priv", + &merchant_priv), + &no_priv), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lic->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + acc.instance_id = instance_id; + acc.payto_uri = payto; + acc.credit_facade_url = facade_url; + acc.credit_facade_credentials = credential; + acc.extra_wire_subject_metadata = extra_wire_subject_metadata; + if (NULL != lic->cb) + lic->cb (lic->cb_cls, + no_priv ? NULL : &merchant_priv, + &acc); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_AccountCallback cb, + void *cb_cls) +{ + struct SelectAccountsContext lic = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_accounts", + "SELECT" + " out_merchant_id" + " ,out_merchant_priv" + " ,out_h_wire" + " ,out_salt" + " ,out_payto_uri" + " ,out_credit_facade_url" + " ,out_credit_facade_credentials::TEXT" + " ,out_extra_wire_subject_metadata" + " ,out_active" + " FROM merchant.select_accounts()"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "select_accounts", + params, + &select_account_cb, + &lic); + if (0 > lic.qs) + return lic.qs; + return qs; +} diff --git a/src/backenddb/iterate_accounts_by_exchange.c b/src/backenddb/iterate_accounts_by_exchange.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_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_accounts_by_instance.c b/src/backenddb/iterate_accounts_by_instance.c @@ -0,0 +1,175 @@ +/* + This file is part of TALER + Copyright (C) 2022, 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_accounts_by_instance.c + * @brief Implementation of the iterate_accounts_by_instance function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_accounts_by_instance.h" +#include "helper.h" + + +/** + * Context for select_accounts(). + */ +struct SelectAccountsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_AccountCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Database context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Merchant instance ID. + */ + const char *id; + + /** + * Set to the return value on errors. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * 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 SelectAccountsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_account_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectAccountsContext *lic = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_FullPayto payto; + char *facade_url = NULL; + char *extra_wire_subject_metadata = NULL; + json_t *credential = NULL; + struct TALER_MERCHANTDB_AccountDetails acc; + struct TALER_MerchantPrivateKeyP merchant_priv; + bool no_priv; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &acc.h_wire), + GNUNET_PQ_result_spec_auto_from_type ("salt", + &acc.salt), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto.full_payto), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("credit_facade_url", + &facade_url), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata", + &extra_wire_subject_metadata), + NULL), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("credit_facade_credentials", + &credential), + NULL), + GNUNET_PQ_result_spec_bool ("active", + &acc.active), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("merchant_priv", + &merchant_priv), + &no_priv), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lic->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + acc.instance_id = lic->id; + acc.payto_uri = payto; + acc.credit_facade_url = facade_url; + acc.credit_facade_credentials = credential; + acc.extra_wire_subject_metadata = extra_wire_subject_metadata; + if (NULL != lic->cb) + lic->cb (lic->cb_cls, + no_priv ? NULL : &merchant_priv, + &acc); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_accounts_by_instance ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + TALER_MERCHANTDB_AccountCallback cb, + void *cb_cls) +{ + struct SelectAccountsContext lic = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + .id = id + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (id), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + TMH_PQ_prepare_anon (pg, + "SELECT" + " ma.h_wire" + ",ma.salt" + ",ma.payto_uri" + ",ma.credit_facade_url" + ",ma.credit_facade_credentials::TEXT" + ",ma.extra_wire_subject_metadata" + ",ma.active" + ",mi.merchant_priv" + " FROM merchant_accounts ma" + " JOIN merchant.merchant_instances mi" + " ON (mi.merchant_id=$1)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &select_account_cb, + &lic); + if (0 > lic.qs) + return lic.qs; + return qs; +} diff --git a/src/backenddb/iterate_all_donau_instances.c b/src/backenddb/iterate_all_donau_instances.c @@ -0,0 +1,165 @@ +/* + This file is part of TALER + Copyright (C) 2024, 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_all_donau_instances.c + * @brief Implementation of the iterate_all_donau_instances function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_all_donau_instances.h" +#include "helper.h" + +/** + * Context for select_donau_instances(). + */ +struct SelectDonauInstanceContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_DonauInstanceCallback cb; + + /** + * Closure for @e 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 donau instances. + * + * @param[in, out] cls of type `struct SelectDonauInstanceContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_donau_instance_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectDonauInstanceContext *sdc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t donau_instance_serial; + char *donau_url; + char *charity_name; + struct DONAU_CharityPublicKeyP charity_pub_key; + uint64_t charity_id; + struct TALER_Amount charity_max_per_year; + struct TALER_Amount charity_receipts_to_date; + int64_t current_year; + json_t *donau_keys_json = NULL; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_donau_instances_serial", + &donau_instance_serial), + GNUNET_PQ_result_spec_string ("out_donau_url", + &donau_url), + GNUNET_PQ_result_spec_string ("out_charity_name", + &charity_name), + GNUNET_PQ_result_spec_auto_from_type ("out_charity_pub_key", + &charity_pub_key), + GNUNET_PQ_result_spec_uint64 ("out_charity_id", + &charity_id), + TALER_PQ_result_spec_amount_with_currency ("out_charity_max_per_year", + &charity_max_per_year), + TALER_PQ_result_spec_amount_with_currency ("out_charity_receipts_to_date", + &charity_receipts_to_date), + GNUNET_PQ_result_spec_int64 ("out_current_year", + &current_year), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("out_keys_json", + &donau_keys_json), + NULL), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + sdc->extract_failed = true; + return; + } + sdc->cb (sdc->cb_cls, + donau_instance_serial, + donau_url, + charity_name, + &charity_pub_key, + charity_id, + &charity_max_per_year, + &charity_receipts_to_date, + current_year, + donau_keys_json); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_all_donau_instances ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls) +{ + struct SelectDonauInstanceContext sdc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the select_donau_instance_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_all_donau_instances", + "SELECT" + " out_donau_instances_serial" + " ,out_donau_url" + " ,out_charity_name" + " ,out_charity_pub_key" + " ,out_charity_id" + " ,out_charity_max_per_year" + " ,out_charity_receipts_to_date" + " ,out_current_year" + " ,out_keys_json::TEXT" + " FROM merchant.select_all_donau_instances()"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "select_all_donau_instances", + params, + &select_donau_instance_cb, + &sdc); + + /* If there was an error inside select_donau_instance_cb, return a hard error. */ + if (sdc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + + return qs; +} diff --git a/src/backenddb/select_all_donau_instances.sql b/src/backenddb/iterate_all_donau_instances.sql diff --git a/src/backenddb/iterate_all_products.c b/src/backenddb/iterate_all_products.c @@ -0,0 +1,227 @@ +/* + This file is part of TALER + Copyright (C) 2024, 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_all_products.c + * @brief Implementation of the iterate_all_products function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_all_products.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_all_products(). + */ +struct LookupProductsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ProductCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Postgres context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * 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 products. + * + * @param[in,out] cls of type `struct LookupProductsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_products_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupProductsContext *plc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + char *product_id; + uint64_t product_serial; + struct TALER_MERCHANTDB_ProductDetails pd; + size_t num_categories; + uint64_t *categories; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("product_id", + &product_id), + GNUNET_PQ_result_spec_uint64 ("product_serial", + &product_serial), + GNUNET_PQ_result_spec_string ("product_name", + &pd.product_name), + GNUNET_PQ_result_spec_string ("description", + &pd.description), + TALER_PQ_result_spec_json ("description_i18n", + &pd.description_i18n), + GNUNET_PQ_result_spec_string ("unit", + &pd.unit), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "price_array", + &pd.price_array_length, + &pd.price_array), + TALER_PQ_result_spec_json ("taxes", + &pd.taxes), + GNUNET_PQ_result_spec_uint64 ("total_stock", + &pd.total_stock), + GNUNET_PQ_result_spec_uint32 ("total_stock_frac", + &pd.total_stock_frac), + GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", + &pd.allow_fractional_quantity), + GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", + &pd.fractional_precision_level), + GNUNET_PQ_result_spec_uint64 ("total_sold", + &pd.total_sold), + GNUNET_PQ_result_spec_uint32 ("total_sold_frac", + &pd.total_sold_frac), + GNUNET_PQ_result_spec_uint64 ("total_lost", + &pd.total_lost), + GNUNET_PQ_result_spec_uint32 ("total_lost_frac", + &pd.total_lost_frac), + GNUNET_PQ_result_spec_string ("image", + &pd.image), + TALER_PQ_result_spec_json ("address", + &pd.address), + GNUNET_PQ_result_spec_timestamp ("next_restock", + &pd.next_restock), + GNUNET_PQ_result_spec_uint32 ("minimum_age", + &pd.minimum_age), + GNUNET_PQ_result_spec_array_uint64 (pg->conn, + "categories", + &num_categories, + &categories), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint64 ("product_group_serial", + &pd.product_group_id), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint64 ("money_pot_serial", + &pd.money_pot_id), + NULL), + GNUNET_PQ_result_spec_bool ("price_is_net", + &pd.price_is_net), + GNUNET_PQ_result_spec_end + }; + + pd.product_group_id = 0; + pd.money_pot_id = 0; + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + plc->extract_failed = true; + return; + } + pd.image_hash = NULL; + plc->cb (plc->cb_cls, + product_serial, + product_id, + &pd, + num_categories, + categories); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_all_products ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_ProductCallback cb, + void *cb_cls) +{ + struct LookupProductsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + /* Can be overwritten by the lookup_products_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + ",description_i18n::TEXT" + ",product_name" + ",unit" + ",price_array" + ",taxes::TEXT" + ",total_stock" + ",total_stock_frac" + ",allow_fractional_quantity" + ",fractional_precision_level" + ",total_sold" + ",total_sold_frac" + ",total_lost" + ",total_lost_frac" + ",image" + ",minv.address::TEXT" + ",next_restock" + ",minimum_age" + ",product_id" + ",product_serial" + ",t.category_array AS categories" + ",product_group_serial" + ",money_pot_serial" + ",price_is_net" + " FROM merchant_inventory minv" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT mpc.category_serial" + " FROM merchant_product_categories mpc" + " WHERE mpc.product_serial = minv.product_serial" + " ) AS category_array" + " ) t"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_products_cb, + &plc); + /* If there was an error inside lookup_products_cb, return a hard error. */ + if (plc.extract_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 @@ -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_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_categories.c b/src/backenddb/iterate_categories.c @@ -0,0 +1,143 @@ +/* + 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_categories.c + * @brief Implementation of the iterate_categories function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_categories.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_categories(). + */ +struct LookupCategoryContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_CategoriesCallback 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 otp_device. + * + * @param[in,out] cls of type `struct LookupCategoryContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_categories_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCategoryContext *tlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t category_id; + char *category_name; + json_t *category_name_i18n; + uint64_t product_count; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("category_serial", + &category_id), + GNUNET_PQ_result_spec_string ("category_name", + &category_name), + TALER_PQ_result_spec_json ("category_name_i18n", + &category_name_i18n), + GNUNET_PQ_result_spec_uint64 ("product_count", + &product_count), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tlc->extract_failed = true; + return; + } + tlc->cb (tlc->cb_cls, + category_id, + category_name, + category_name_i18n, + product_count); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_categories ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_CategoriesCallback cb, + void *cb_cls) +{ + struct LookupCategoryContext tlc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_categories_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + " mc.category_serial" + ",mc.category_name" + ",mc.category_name_i18n::TEXT" + ",COALESCE(COUNT(mpc.product_serial),0)" + " AS product_count" + " FROM merchant_categories mc" + " LEFT JOIN merchant_product_categories mpc" + " USING (category_serial)" + " GROUP BY mc.category_serial" + " ORDER BY mc.category_serial;"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_categories_cb, + &tlc); + /* If there was an error inside lookup_categories_cb, return a hard error. */ + if (tlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_categories_by_ids.c b/src/backenddb/iterate_categories_by_ids.c @@ -0,0 +1,140 @@ +/* + 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_categories_by_ids.c + * @brief Lookup product categories by ID + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_categories_by_ids.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_categories_by_ids(). + */ +struct LookupCategoryContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_CategoriesCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +static void +lookup_categories_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupCategoryContext *tlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t category_id; + char *category_name; + json_t *category_name_i18n; + uint64_t product_count; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("category_serial", + &category_id), + GNUNET_PQ_result_spec_string ("category_name", + &category_name), + TALER_PQ_result_spec_json ("category_name_i18n", + &category_name_i18n), + GNUNET_PQ_result_spec_uint64 ("product_count", + &product_count), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tlc->extract_failed = true; + return; + } + tlc->cb (tlc->cb_cls, + category_id, + category_name, + category_name_i18n, + product_count); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_categories_by_ids (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const uint64_t *category_ids, + size_t num_category_ids, + TALER_MERCHANTDB_CategoriesCallback cb, + void *cb_cls) +{ + struct LookupCategoryContext tlc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_categories_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_array_uint64 (num_category_ids, + category_ids, + pg->conn), + 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" + " mc.category_serial" + ",mc.category_name" + ",mc.category_name_i18n::TEXT" + ",COALESCE(COUNT(mpc.product_serial),0)" + " AS product_count" + " FROM merchant_categories mc" + " LEFT JOIN merchant_product_categories mpc" + " USING (category_serial)" + " WHERE mc.category_serial = ANY ($1)" + " GROUP BY mc.category_serial" + " ORDER BY mc.category_serial;"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_categories_cb, + &tlc); + GNUNET_PQ_cleanup_query_params_closures (params); + if (tlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_custom_units_by_names.c b/src/backenddb/iterate_custom_units_by_names.c @@ -0,0 +1,139 @@ +/* + 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_custom_units_by_names.c + * @brief Lookup custom measurement units by name + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_custom_units_by_names.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_custom_units_by_names(). + */ +struct LookupUnitsContext +{ + TALER_MERCHANTDB_UnitsCallback cb; + void *cb_cls; + bool extract_failed; +}; + + +static void +lookup_units_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupUnitsContext *luc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_MERCHANTDB_UnitDetails ud = { 0 }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("unit_serial", + &ud.unit_serial), + GNUNET_PQ_result_spec_string ("unit", + &ud.unit), + GNUNET_PQ_result_spec_string ("unit_name_long", + &ud.unit_name_long), + GNUNET_PQ_result_spec_string ("unit_name_short", + &ud.unit_name_short), + TALER_PQ_result_spec_json ("unit_name_long_i18n", + &ud.unit_name_long_i18n), + TALER_PQ_result_spec_json ("unit_name_short_i18n", + &ud.unit_name_short_i18n), + GNUNET_PQ_result_spec_bool ("unit_allow_fraction", + &ud.unit_allow_fraction), + GNUNET_PQ_result_spec_uint32 ("unit_precision_level", + &ud.unit_precision_level), + GNUNET_PQ_result_spec_bool ("unit_active", + &ud.unit_active), + GNUNET_PQ_result_spec_bool ("unit_builtin", + &ud.unit_builtin), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + luc->extract_failed = true; + return; + } + luc->cb (luc->cb_cls, + ud.unit_serial, + &ud); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_custom_units_by_names ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *const *units, + size_t num_units, + TALER_MERCHANTDB_UnitsCallback cb, + void *cb_cls) +{ + struct LookupUnitsContext luc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_array_ptrs_string (num_units, + (const char **) units, + pg->conn), + 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 cu.unit_serial" + " ,cu.unit" + " ,cu.unit_name_long" + " ,cu.unit_name_short" + " ,cu.unit_name_long_i18n" + " ,cu.unit_name_short_i18n" + " ,cu.unit_allow_fraction" + " ,cu.unit_precision_level" + " ,cu.unit_active" + " ,FALSE AS unit_builtin" + " FROM merchant_custom_units cu" + " WHERE cu.unit = ANY ($1)" + " ORDER BY cu.unit"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_units_cb, + &luc); + GNUNET_PQ_cleanup_query_params_closures (params); + if (luc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_deposits.c b/src/backenddb/iterate_deposits.c @@ -0,0 +1,163 @@ +/* + 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_deposits.c + * @brief Implementation of the iterate_deposits function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_deposits.h" +#include "helper.h" + +/** + * Closure for #lookup_deposits_cb(). + */ +struct LookupDepositsContext +{ + /** + * Function to call with results. + */ + TALER_MERCHANTDB_DepositsCallback cb; + + /** + * Closure for @e cls. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Transaction status (set). + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param[in,out] cls of type `struct LookupDepositsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_deposits_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsContext *ldc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_Amount amount_with_fee; + struct TALER_Amount deposit_fee; + struct TALER_Amount refund_fee; + struct TALER_Amount wire_fee; + char *exchange_url; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", + &amount_with_fee), + TALER_PQ_result_spec_amount_with_currency ("deposit_fee", + &deposit_fee), + TALER_PQ_result_spec_amount_with_currency ("refund_fee", + &refund_fee), + TALER_PQ_result_spec_amount_with_currency ("wire_fee", + &wire_fee), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ldc->cb (ldc->cb_cls, + exchange_url, + &coin_pub, + &amount_with_fee, + &deposit_fee, + &refund_fee, + &wire_fee); + GNUNET_PQ_cleanup_result (rs); + } + ldc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms, + TALER_MERCHANTDB_DepositsCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + struct LookupDepositsContext ldc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (instance_id, + pg->current_merchant_id)); + /* no preflight check here, run in its own transaction by the caller! */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Finding deposits for h_contract_terms '%s'\n", + GNUNET_h2s (&h_contract_terms->hash)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " dcom.exchange_url" + ",dcom.wire_fee" + ",dep.coin_pub" + ",dep.amount_with_fee" + ",dep.deposit_fee" + ",dep.refund_fee" + " FROM merchant_deposits dep" + " JOIN merchant_deposit_confirmations dcom" + " USING (deposit_confirmation_serial)" + " WHERE dcom.order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$1)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_deposits_cb, + &ldc); + if (qs <= 0) + return qs; + return ldc.qs; +} diff --git a/src/backenddb/iterate_deposits_by_contract_and_coin.c b/src/backenddb/iterate_deposits_by_contract_and_coin.c @@ -0,0 +1,318 @@ +/* + 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_deposits_by_contract_and_coin.c + * @brief Implementation of the iterate_deposits_by_contract_and_coin function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_deposits_by_contract_and_coin.h" +#include "helper.h" + +/** + * Closure for #lookup_deposits_by_contract_and_coin_cb(). + */ +struct LookupDepositsByCnCContext +{ + /** + * Function to call for each deposit. + */ + TALER_MERCHANTDB_CoinDepositCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Total amount refunded on this coin and contract. + */ + struct TALER_Amount refund_total; + + /** + * 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 LookupDepositsByCnCContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_refunds_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsByCnCContext *ldcc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_Amount refund_amount; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_amount_with_currency ("refund_amount", + &refund_amount), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Coin had refund of %s\n", + TALER_amount2s (&refund_amount)); + if (0 == i) + ldcc->refund_total = refund_amount; + else + GNUNET_assert (0 <= + TALER_amount_add (&ldcc->refund_total, + &ldcc->refund_total, + &refund_amount)); + GNUNET_PQ_cleanup_result (rs); /* technically useless here */ + } +} + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls of type `struct LookupDepositsByCnCContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_deposits_by_contract_and_coin_cb ( + void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsByCnCContext *ldcc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + char *exchange_url; + struct TALER_Amount amount_with_fee; + struct TALER_Amount deposit_fee; + struct TALER_Amount refund_fee; + struct TALER_Amount wire_fee; + struct TALER_MerchantWireHashP h_wire; + struct GNUNET_TIME_Timestamp deposit_timestamp; + struct GNUNET_TIME_Timestamp refund_deadline; + struct TALER_ExchangeSignatureP exchange_sig; + struct TALER_ExchangePublicKeyP exchange_pub; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", + &amount_with_fee), + TALER_PQ_result_spec_amount_with_currency ("deposit_fee", + &deposit_fee), + TALER_PQ_result_spec_amount_with_currency ("refund_fee", + &refund_fee), + TALER_PQ_result_spec_amount_with_currency ("wire_fee", + &wire_fee), + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &h_wire), + GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", + &deposit_timestamp), + GNUNET_PQ_result_spec_timestamp ("refund_deadline", + &refund_deadline), + GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", + &exchange_sig), + GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", + &exchange_pub), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Coin original deposit value is %s\n", + TALER_amount2s (&amount_with_fee)); + if (TALER_amount_is_valid (&ldcc->refund_total)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Coin had total refunds of %s\n", + TALER_amount2s (&ldcc->refund_total)); + if (1 == + TALER_amount_cmp (&ldcc->refund_total, + &amount_with_fee)) + { + /* Refunds exceeded total deposit? not OK! */ + GNUNET_break (0); + ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + if (0 == + TALER_amount_cmp (&ldcc->refund_total, + &amount_with_fee)) + { + /* refund_total == amount_with_fee; + in this case, the total contributed to the + wire transfer is zero (as are fees) */ + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (ldcc->refund_total.currency, + &amount_with_fee)); + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (ldcc->refund_total.currency, + &deposit_fee)); + + } + else + { + /* Compute deposit value by subtracting refunds */ + GNUNET_assert (0 < + TALER_amount_subtract (&amount_with_fee, + &amount_with_fee, + &ldcc->refund_total)); + if (-1 == + TALER_amount_cmp (&amount_with_fee, + &deposit_fee)) + { + /* amount_with_fee < deposit_fee, so after refunds less than + the deposit fee remains; reduce deposit fee to + the remaining value of the coin */ + deposit_fee = amount_with_fee; + } + } + } + ldcc->cb (ldcc->cb_cls, + exchange_url, + &amount_with_fee, + &deposit_fee, + &refund_fee, + &wire_fee, + &h_wire, + deposit_timestamp, + refund_deadline, + &exchange_sig, + &exchange_pub); + GNUNET_PQ_cleanup_result (rs); + } + ldcc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits_by_contract_and_coin ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP * + h_contract_terms, + const struct TALER_CoinSpendPublicKeyP * + coin_pub, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_auto_from_type (coin_pub), + GNUNET_PQ_query_param_end + }; + struct LookupDepositsByCnCContext ldcc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + 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! */ + TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n", + GNUNET_h2s (&h_contract_terms->hash), + instance_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " refund_amount" + " FROM merchant_refunds" + /* Join to filter by refunds that actually + did work, not only those we approved */ + " JOIN merchant_refund_proofs" + " USING (refund_serial)" + " WHERE coin_pub=$2" + " AND order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$1)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_refunds_cb, + &ldcc); + if (0 > qs) + return qs; + + TMH_PQ_prepare_anon (pg, + "SELECT" + " mcon.exchange_url" + ",dep.amount_with_fee" + ",dep.deposit_fee" + ",dep.refund_fee" + ",mcon.wire_fee" + ",acc.h_wire" + ",mcon.deposit_timestamp" + ",mct.refund_deadline" + ",mcon.exchange_sig" + ",msig.exchange_pub" + " FROM merchant_contract_terms mct" + " JOIN merchant_deposit_confirmations mcon" + " USING (order_serial)" + " JOIN merchant_deposits dep" + " USING (deposit_confirmation_serial)" + " JOIN merchant.merchant_exchange_signing_keys msig" + " ON (mcon.signkey_serial=msig.signkey_serial)" + " JOIN merchant_accounts acc" + " USING (account_serial)" + " WHERE h_contract_terms=$1" + " AND dep.coin_pub=$2"); + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_deposits_by_contract_and_coin_cb, + &ldcc); + if (0 >= qs) + return qs; + return ldcc.qs; +} diff --git a/src/backenddb/iterate_deposits_by_order.c b/src/backenddb/iterate_deposits_by_order.c @@ -0,0 +1,161 @@ +/* + This file is part of TALER + Copyright (C) 2023, 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_deposits_by_order.c + * @brief Implementation of the iterate_deposits_by_order function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_deposits_by_order.h" +#include "helper.h" + +/** + * Closure for lookup_deposits_by_order_cb(). + */ +struct LookupDepositsByOrderContext +{ + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with all results. + */ + TALER_MERCHANTDB_DepositedCoinsCallback 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 closure of type `struct LookupDepositsByOrderContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_deposits_by_order_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsByOrderContext *ldoc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + uint64_t deposit_serial; + char *exchange_url; + struct TALER_MerchantWireHashP h_wire; + struct TALER_CoinSpendPublicKeyP coin_pub; + struct GNUNET_TIME_Timestamp deposit_timestamp; + struct TALER_Amount amount_with_fee; + struct TALER_Amount deposit_fee; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("deposit_serial", + &deposit_serial), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", + &deposit_timestamp), + GNUNET_PQ_result_spec_auto_from_type ("h_wire", + &h_wire), + TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", + &amount_with_fee), + TALER_PQ_result_spec_amount_with_currency ("deposit_fee", + &deposit_fee), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldoc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ldoc->cb (ldoc->cb_cls, + deposit_serial, + exchange_url, + &h_wire, + deposit_timestamp, + &amount_with_fee, + &deposit_fee, + &coin_pub); + GNUNET_PQ_cleanup_result (rs); /* technically useless here */ + } + ldoc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits_by_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_DepositedCoinsCallback cb, + void *cb_cls) +{ + struct LookupDepositsByOrderContext ldoc = { + .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" + " dep.deposit_serial" + ",mcon.exchange_url" + ",acc.h_wire" + ",mcon.deposit_timestamp" + ",dep.amount_with_fee" + ",dep.deposit_fee" + ",dep.coin_pub" + " FROM merchant_deposits dep" + " JOIN merchant_deposit_confirmations mcon" + " USING(deposit_confirmation_serial)" + " JOIN merchant_accounts acc" + " USING (account_serial)" + " WHERE mcon.order_serial=$1"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_deposits_by_order_cb, + &ldoc); + if (qs < 0) + return qs; + return ldoc.qs; +} diff --git a/src/backenddb/iterate_donau_instances.c b/src/backenddb/iterate_donau_instances.c @@ -0,0 +1,179 @@ +/* + 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_donau_instances.c + * @brief Implementation of the iterate_donau_instances function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include <donau/donau_util.h> +#include "merchant-database/iterate_donau_instances.h" +#include "helper.h" + +/** + * Context for select_donau_instances(). + */ +struct SelectDonauInstanceContext +{ + /** + * Database connection. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_DonauInstanceCallback cb; + + /** + * Closure for @e 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 donau instances. + * + * @param[in, out] cls of type `struct SelectDonauInstanceContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_donau_instance_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectDonauInstanceContext *sdc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = sdc->pg; + struct DONAU_CharityPublicKeyP charity_pub_key; + + GNUNET_static_assert (sizeof (charity_pub_key) == + sizeof (pg->current_merchant_pub)); + memcpy (&charity_pub_key, + &pg->current_merchant_pub, + sizeof (charity_pub_key)); + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t donau_instance_serial; + char *donau_url; + char *charity_name; + uint64_t charity_id; + struct TALER_Amount charity_max_per_year; + struct TALER_Amount charity_receipts_to_date; + int64_t current_year; + json_t *donau_keys_json = NULL; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("donau_instances_serial", + &donau_instance_serial), + GNUNET_PQ_result_spec_string ("donau_url", + &donau_url), + GNUNET_PQ_result_spec_string ("charity_name", + &charity_name), + GNUNET_PQ_result_spec_uint64 ("charity_id", + &charity_id), + 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_int64 ("current_year", + &current_year), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("keys_json", + &donau_keys_json), + NULL), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + sdc->extract_failed = true; + return; + } + sdc->cb (sdc->cb_cls, + donau_instance_serial, + donau_url, + charity_name, + &charity_pub_key, + charity_id, + &charity_max_per_year, + &charity_receipts_to_date, + current_year, + donau_keys_json); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_donau_instances ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls) +{ + struct SelectDonauInstanceContext sdc = { + .pg = pg, + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the select_donau_instance_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != pg->current_merchant_id); + GNUNET_assert (0 == strcmp (id, + pg->current_merchant_id)); + TMH_PQ_prepare_anon (pg, + "SELECT" + " di.donau_instances_serial" + ",di.donau_url" + ",di.charity_name" + ",di.charity_id" + ",di.charity_max_per_year" + ",di.charity_receipts_to_date" + ",di.current_year" + ",dk.keys_json::TEXT" + " FROM merchant_donau_instances di" + " LEFT JOIN merchant.merchant_donau_keys dk" + " ON di.donau_url = dk.donau_url"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &select_donau_instance_cb, + &sdc); + + /* If there was an error inside select_donau_instance_cb, return a hard error. */ + if (sdc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + + return qs; +} diff --git a/src/backenddb/iterate_donau_instances_filtered.c b/src/backenddb/iterate_donau_instances_filtered.c @@ -0,0 +1,123 @@ +/* + 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_donau_instances_filtered.c + * @brief Implementation of the iterate_donau_instances_filtered function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_donau_instances_filtered.h" +#include "helper.h" + + +/** + * Context for select_donau_instances_filtered(). + */ +struct SelectDonauInstanceContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_DonauInstanceFilteredCallback cb; + + /** + * Closure for @e 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 donau instances. + * + * @param[in, out] cls of type `struct SelectDonauInstanceContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +select_donau_instance_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectDonauInstanceContext *sdc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *donau_url; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("donau_url", + &donau_url), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + sdc->extract_failed = true; + return; + } + sdc->cb (sdc->cb_cls, + donau_url); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_donau_instances_filtered ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *currency, + TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, + void *cb_cls) +{ + struct SelectDonauInstanceContext sdc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the select_donau_instance_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (currency), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + TMH_PQ_prepare_anon (pg, + "SELECT donau_url" + " FROM merchant_donau_instances" + " WHERE (charity_max_per_year).curr = $1"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &select_donau_instance_cb, + &sdc); + + /* If there was an error inside select_donau_instance_cb, return a hard error. */ + if (sdc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_exchanges.c b/src/backenddb/iterate_exchanges.c @@ -0,0 +1,150 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_exchanges.c + * @brief Implementation of the iterate_exchanges function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_exchanges.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_exchanges(). + */ +struct LookupExchangesContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ExchangesCallback 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 product exchanges. + * + * @param[in,out] cls of type `struct LookupExchangesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_exchanges_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupExchangesContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *exchange_url; + json_t *keys = NULL; + struct GNUNET_TIME_Absolute next_download; + struct GNUNET_TIME_Absolute keys_expiration; + uint32_t hc; + uint32_t ec; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_absolute_time ("first_retry", + &next_download), + GNUNET_PQ_result_spec_absolute_time ("expiration_time", + &keys_expiration), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("keys_json", + &keys), + NULL), + GNUNET_PQ_result_spec_uint32 ("exchange_http_status", + &hc), + GNUNET_PQ_result_spec_uint32 ("exchange_ec_code", + &ec), + 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, + exchange_url, + keys, + next_download, + keys_expiration, + (unsigned int) hc, + (enum TALER_ErrorCode) ec); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_exchanges ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_ExchangesCallback cb, + void *cb_cls) +{ + struct LookupExchangesContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_exchanges_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_exchanges", + "SELECT" + " exchange_url" + " ,first_retry" + " ,expiration_time" + " ,keys_json::TEXT" + " ,exchange_http_status" + " ,exchange_ec_code" + " FROM merchant.merchant_exchange_keys"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "select_exchanges", + params, + &lookup_exchanges_cb, + &plc); + /* If there was an error inside lookup_exchanges_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_expected_transfers.c b/src/backenddb/iterate_expected_transfers.c @@ -0,0 +1,272 @@ +/* + 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_expected_transfers.c + * @brief Implementation of the iterate_expected_transfers function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_expected_transfers.h" +#include "helper.h" +#include <microhttpd.h> /* for HTTP status codes */ + +/** + * Closure for #lookup_expected_transfers_cb(). + */ +struct LookupExpectedTransfersContext +{ + /** + * Function to call on results. + */ + TALER_MERCHANTDB_IncomingCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Postgres context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Transaction status (set). + */ + 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 LookupExpectedTransfersContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_expected_transfers_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupExpectedTransfersContext *ltc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_Amount expected_credit_amount; + struct TALER_WireTransferIdentifierRawP wtid; + struct TALER_FullPayto payto_uri; + char *exchange_url; + uint64_t expected_transfer_serial_id; + struct GNUNET_TIME_Timestamp execution_time + = GNUNET_TIME_UNIT_ZERO_TS; + bool confirmed; + bool validated; + bool no_amount; + char *last_detail = NULL; + uint32_t last_http_status = 0; + uint32_t last_ec = TALER_EC_NONE; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", + &expected_credit_amount), + &no_amount), + GNUNET_PQ_result_spec_auto_from_type ("wtid", + &wtid), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto_uri.full_payto), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", + &expected_transfer_serial_id), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("execution_time", + &execution_time), + NULL), + GNUNET_PQ_result_spec_bool ("confirmed", + &confirmed), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("last_http_status", + &last_http_status), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("last_ec", + &last_ec), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("last_detail", + &last_detail), + NULL), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ltc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + validated = ( (MHD_HTTP_OK == last_http_status) && + (TALER_EC_NONE == last_ec) ); + ltc->cb (ltc->cb_cls, + no_amount + ? NULL + : &expected_credit_amount, + &wtid, + payto_uri, + exchange_url, + expected_transfer_serial_id, + execution_time, + confirmed, + validated, + last_http_status, + last_ec, + last_detail); + GNUNET_PQ_cleanup_result (rs); + } + ltc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_expected_transfers ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + struct GNUNET_TIME_Timestamp before, + struct GNUNET_TIME_Timestamp after, + int64_t limit, + uint64_t offset, + enum TALER_EXCHANGE_YesNoAll confirmed, + enum TALER_EXCHANGE_YesNoAll verified, + TALER_MERCHANTDB_IncomingCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + bool by_time = ( (! GNUNET_TIME_absolute_is_never (before.abs_time)) || + (! GNUNET_TIME_absolute_is_zero (after.abs_time)) ); + struct LookupExpectedTransfersContext ltc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_timestamp (&before), + GNUNET_PQ_query_param_timestamp (&after), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + NULL == payto_uri.full_payto + ? GNUNET_PQ_query_param_null () /* NULL: do not filter by payto URI */ + : GNUNET_PQ_query_param_string (payto_uri.full_payto), + GNUNET_PQ_query_param_bool (! by_time), /* $6: filter by time? */ + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == confirmed), /* filter by confirmed? */ + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == confirmed), + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == verified), /* filter by verified? */ + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == verified), + + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " met.expected_credit_amount" + ",met.wtid" + ",mac.payto_uri" + ",met.exchange_url" + ",met.expected_credit_serial" + ",mts.execution_time" + ",met.confirmed" + ",met.last_http_status" + ",met.last_ec" + ",met.last_detail" + " FROM merchant_expected_transfers met" + " JOIN merchant_accounts mac" + " USING (account_serial)" + " LEFT JOIN merchant_transfer_signatures mts" + " USING (expected_credit_serial)" + " WHERE ( $6 OR " + " (mts.execution_time IS NOT NULL AND" + " mts.execution_time < $1 AND" + " mts.execution_time >= $2) )" + " AND ( (CAST($5 AS TEXT) IS NULL) OR " + " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" + " =REGEXP_REPLACE($5,'\\?.*','')) )" + " AND ( $7 OR " + " (met.confirmed = $8) )" + " AND ( $9 OR " + " ($10 = (200=met.last_http_status) AND" + " (0=met.last_ec) ) )" + " AND (met.expected_credit_serial > $3)" + " ORDER BY met.expected_credit_serial ASC" + " LIMIT $4"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " met.expected_credit_amount" + ",met.wtid" + ",mac.payto_uri" + ",met.exchange_url" + ",met.expected_credit_serial" + ",mts.execution_time" + ",met.confirmed" + ",met.last_http_status" + ",met.last_ec" + ",met.last_detail" + " FROM merchant_expected_transfers met" + " JOIN merchant_accounts mac" + " USING (account_serial)" + " LEFT JOIN merchant_transfer_signatures mts" + " USING (expected_credit_serial)" + " WHERE ( $6 OR " + " (mts.execution_time IS NOT NULL AND" + " mts.execution_time < $1 AND" + " mts.execution_time >= $2) )" + " AND ( (CAST($5 AS TEXT) IS NULL) OR " + " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" + " =REGEXP_REPLACE($5,'\\?.*','')) )" + " AND ( $7 OR " + " (met.confirmed = $8) )" + " AND ( $9 OR " + " ($10 = (200=met.last_http_status) AND" + " (0=met.last_ec) ) )" + " AND (met.expected_credit_serial < $3)" + " ORDER BY met.expected_credit_serial DESC" + " LIMIT $4"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_expected_transfers_cb, + &ltc); + if (0 >= qs) + return qs; + return ltc.qs; +} diff --git a/src/backenddb/iterate_instances.c b/src/backenddb/iterate_instances.c @@ -0,0 +1,283 @@ +/* + This file is part of TALER + Copyright (C) 2022--2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_instances.c + * @brief Implementation of the iterate_instances function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_instances.h" +#include "helper.h" + + +/** + * Context for lookup_instances(). + */ +struct LookupInstancesContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_InstanceCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Database context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Set to the return value on errors. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about instances. + * + * @param cls of type `struct LookupInstancesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_instances_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupInstancesContext *lic = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_MERCHANTDB_InstanceSettings is; + struct TALER_MERCHANTDB_InstanceAuthSettings ias; + uint64_t instance_serial; + struct TALER_MerchantPublicKeyP merchant_pub; + struct TALER_MerchantPrivateKeyP merchant_priv; + bool no_auth; + bool no_salt; + bool no_priv; + char *dwtri; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("merchant_serial", + &instance_serial), + GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", + &merchant_pub), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("auth_hash", + &ias.auth_hash), + &no_auth), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("auth_salt", + &ias.auth_salt), + &no_salt), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_auto_from_type ("merchant_priv", + &merchant_priv), + &no_priv), + GNUNET_PQ_result_spec_string ("merchant_id", + &is.id), + GNUNET_PQ_result_spec_string ("merchant_name", + &is.name), + TALER_PQ_result_spec_json ("address", + &is.address), + TALER_PQ_result_spec_json ("jurisdiction", + &is.jurisdiction), + GNUNET_PQ_result_spec_bool ("use_stefan", + &is.use_stefan), + GNUNET_PQ_result_spec_bool ("phone_validated", + &is.phone_validated), + GNUNET_PQ_result_spec_bool ("email_validated", + &is.email_validated), + GNUNET_PQ_result_spec_relative_time ( + "default_wire_transfer_delay", + &is.default_wire_transfer_delay), + GNUNET_PQ_result_spec_relative_time ("default_pay_delay", + &is.default_pay_delay), + GNUNET_PQ_result_spec_relative_time ("default_refund_delay", + &is.default_refund_delay), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("website", + &is.website), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("email", + &is.email), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("phone_number", + &is.phone), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("logo", + &is.logo), + NULL), + GNUNET_PQ_result_spec_string ( + "default_wire_transfer_rounding_interval", + &dwtri), + GNUNET_PQ_result_spec_end + }; + + memset (&ias.auth_salt, + 0, + sizeof (ias.auth_salt)); + memset (&ias.auth_hash, + 0, + sizeof (ias.auth_hash)); + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lic->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + if (GNUNET_OK != + GNUNET_TIME_string_to_round_interval ( + dwtri, + &is.default_wire_transfer_rounding_interval)) + { + GNUNET_break (0); + lic->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + lic->cb (lic->cb_cls, + &merchant_pub, + (no_priv) ? NULL : &merchant_priv, + &is, + &ias); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_instances ( + struct TALER_MERCHANTDB_PostgresContext *pg, + bool active_only, + TALER_MERCHANTDB_InstanceCallback cb, + void *cb_cls) +{ + struct LookupInstancesContext lic = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_bool (active_only), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_instances", + "SELECT" + " merchant_serial" + " ,merchant_pub" + " ,auth_hash" + " ,auth_salt" + " ,merchant_priv" + " ,merchant_id" + " ,merchant_name" + " ,address::TEXT" + " ,jurisdiction::TEXT" + " ,use_stefan" + " ,phone_validated" + " ,email_validated" + " ,default_wire_transfer_delay" + " ,default_pay_delay" + " ,default_refund_delay" + " ,website" + " ,email" + " ,phone_number" + " ,logo" + " ,default_wire_transfer_rounding_interval::TEXT" + " FROM merchant.merchant_instances" + " WHERE (NOT $1 OR merchant_priv IS NOT NULL)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_instances", + params, + &lookup_instances_cb, + &lic); + if (0 > lic.qs) + return lic.qs; + return qs; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_instances_by_id ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + bool active_only, + TALER_MERCHANTDB_InstanceCallback cb, + void *cb_cls) +{ + struct LookupInstancesContext lic = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_bool (active_only), + GNUNET_PQ_query_param_string (id), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "iterate_instances_by_id", + "SELECT" + " merchant_serial" + " ,merchant_pub" + " ,auth_hash" + " ,auth_salt" + " ,merchant_priv" + " ,merchant_id" + " ,merchant_name" + " ,address::TEXT" + " ,jurisdiction::TEXT" + " ,use_stefan" + " ,phone_validated" + " ,email_validated" + " ,default_wire_transfer_delay" + " ,default_pay_delay" + " ,default_refund_delay" + " ,website" + " ,email" + " ,phone_number" + " ,logo" + " ,default_wire_transfer_rounding_interval::TEXT" + " FROM merchant.merchant_instances" + " WHERE (merchant_id = $2)" + " AND (NOT $1 OR merchant_priv IS NOT NULL)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "iterate_instances_by_id", + params, + &lookup_instances_cb, + &lic); + if (0 > lic.qs) + return lic.qs; + return qs; +} diff --git a/src/backenddb/iterate_inventory_products.c b/src/backenddb/iterate_inventory_products.c @@ -0,0 +1,219 @@ +/* + 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_inventory_products.c + * @brief Implementation of the iterate_inventory_products function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_inventory_products.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_inventory_products(). + */ +struct LookupInventoryProductsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_InventoryProductCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Postgres context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * 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 products. + * + * @param[in,out] cls of type `struct LookupInventoryProductsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_inventory_products_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupInventoryProductsContext *plc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + char *product_id; + struct TALER_MERCHANTDB_InventoryProductDetails pd; + size_t num_categories; + uint64_t *categories; + bool no_image_hash; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("product_id", + &product_id), + GNUNET_PQ_result_spec_string ("product_name", + &pd.product_name), + GNUNET_PQ_result_spec_string ("description", + &pd.description), + TALER_PQ_result_spec_json ("description_i18n", + &pd.description_i18n), + GNUNET_PQ_result_spec_string ("unit", + &pd.unit), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "price_array", + &pd.price_array_length, + &pd.price_array), + GNUNET_PQ_result_spec_uint64 ("remaining_stock", + &pd.remaining_stock), + GNUNET_PQ_result_spec_uint32 ("remaining_stock_frac", + &pd.remaining_stock_frac), + TALER_PQ_result_spec_json ("taxes", + &pd.taxes), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("image_hash", + &pd.image_hash), + &no_image_hash), + GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", + &pd.allow_fractional_quantity), + GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", + &pd.fractional_precision_level), + GNUNET_PQ_result_spec_array_uint64 (pg->conn, + "categories", + &num_categories, + &categories), + 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, + product_id, + &pd, + num_categories, + categories); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_inventory_products ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_InventoryProductCallback cb, + void *cb_cls) +{ + struct LookupInventoryProductsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + /* Can be overwritten by the lookup_inventory_products_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + ",description_i18n::TEXT" + ",product_name" + ",unit" + ",price_array" + ",CASE WHEN minv.total_stock = 9223372036854775807" + " THEN minv.total_stock" + " ELSE (GREATEST(0, rt.remaining_total) / 1000000)::INT8" + " END AS remaining_stock" + ",CASE WHEN minv.total_stock = 9223372036854775807" + " THEN 2147483647" + " ELSE mod(GREATEST(0, rt.remaining_total), 1000000)::INT4" + " END AS remaining_stock_frac" + ",taxes::TEXT" + ",image_hash" + ",allow_fractional_quantity" + ",fractional_precision_level" + ",product_id" + ",t.category_array AS categories" + " FROM merchant_inventory minv" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT mpc.category_serial" + " FROM merchant_product_categories mpc" + " WHERE mpc.product_serial = minv.product_serial" + " ) AS category_array" + " ) t" + ",LATERAL (" + " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" + " + total_locked_frac::NUMERIC), 0)" + " AS total_locked" + " FROM merchant_inventory_locks mil" + " WHERE mil.product_serial = minv.product_serial" + " ) il" + ",LATERAL (" + " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" + " + total_locked_frac::NUMERIC), 0)" + " AS total_locked" + " FROM merchant_order_locks mol" + " WHERE mol.product_serial = minv.product_serial" + " ) ol" + ",LATERAL (" + " SELECT" + " (minv.total_stock::NUMERIC * 1000000" + " + minv.total_stock_frac::NUMERIC)" + " - (minv.total_sold::NUMERIC * 1000000" + " + minv.total_sold_frac::NUMERIC)" + " - (minv.total_lost::NUMERIC * 1000000" + " + minv.total_lost_frac::NUMERIC)" + " - il.total_locked" + " - ol.total_locked" + " AS remaining_total" + " ) rt"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_inventory_products_cb, + &plc); + /* If there was an error inside lookup_inventory_products_cb, return a hard error. */ + if (plc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_inventory_products_filtered.c b/src/backenddb/iterate_inventory_products_filtered.c @@ -0,0 +1,240 @@ +/* + 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_inventory_products_filtered.c + * @brief Lookup inventory product details for templates (filtered) + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_inventory_products_filtered.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_inventory_products_filtered(). + */ +struct LookupInventoryProductsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_InventoryProductCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Postgres context for callbacks. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Did database result extraction fail? + */ + bool extract_failed; +}; + + +static void +lookup_inventory_products_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupInventoryProductsContext *plc = cls; + struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; + + for (unsigned int i = 0; i < num_results; i++) + { + char *product_id; + struct TALER_MERCHANTDB_InventoryProductDetails pd; + size_t num_categories; + uint64_t *categories; + bool no_image_hash; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("product_id", + &product_id), + GNUNET_PQ_result_spec_string ("product_name", + &pd.product_name), + GNUNET_PQ_result_spec_string ("description", + &pd.description), + TALER_PQ_result_spec_json ("description_i18n", + &pd.description_i18n), + GNUNET_PQ_result_spec_string ("unit", + &pd.unit), + TALER_PQ_result_spec_array_amount_with_currency (pg->conn, + "merchant", + "price_array", + &pd.price_array_length, + &pd.price_array), + GNUNET_PQ_result_spec_uint64 ("remaining_stock", + &pd.remaining_stock), + GNUNET_PQ_result_spec_uint32 ("remaining_stock_frac", + &pd.remaining_stock_frac), + TALER_PQ_result_spec_json ("taxes", + &pd.taxes), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("image_hash", + &pd.image_hash), + &no_image_hash), + GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", + &pd.allow_fractional_quantity), + GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", + &pd.fractional_precision_level), + GNUNET_PQ_result_spec_array_uint64 (pg->conn, + "categories", + &num_categories, + &categories), + 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, + product_id, + &pd, + num_categories, + categories); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_inventory_products_filtered ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *const *product_ids, + size_t num_product_ids, + const uint64_t *categories, + size_t num_categories, + TALER_MERCHANTDB_InventoryProductCallback cb, + void *cb_cls) +{ + struct LookupInventoryProductsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + /* Can be overwritten by the lookup_inventory_products_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + (0 == num_product_ids) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_array_ptrs_string ( + num_product_ids, + (const char **) product_ids, + pg->conn), + (0 == num_categories) + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_array_uint64 (num_categories, + categories, + pg->conn), + 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" + ",description_i18n::TEXT" + ",product_name" + ",unit" + ",price_array" + ",CASE WHEN minv.total_stock = 9223372036854775807" + " THEN minv.total_stock" + " ELSE (GREATEST(0, rt.remaining_total) / 1000000)::INT8" + " END AS remaining_stock" + ",CASE WHEN minv.total_stock = 9223372036854775807" + " THEN 2147483647" + " ELSE mod(GREATEST(0, rt.remaining_total), 1000000)::INT4" + " END AS remaining_stock_frac" + ",taxes::TEXT" + ",image_hash" + ",allow_fractional_quantity" + ",fractional_precision_level" + ",product_id" + ",t.category_array AS categories" + " FROM merchant_inventory minv" + ",LATERAL (" + " SELECT ARRAY (" + " SELECT mpc.category_serial" + " FROM merchant_product_categories mpc" + " WHERE mpc.product_serial = minv.product_serial" + " ) AS category_array" + " ) t" + ",LATERAL (" + " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" + " + total_locked_frac::NUMERIC), 0)" + " AS total_locked" + " FROM merchant_inventory_locks mil" + " WHERE mil.product_serial = minv.product_serial" + " ) il" + ",LATERAL (" + " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" + " + total_locked_frac::NUMERIC), 0)" + " AS total_locked" + " FROM merchant_order_locks mol" + " WHERE mol.product_serial = minv.product_serial" + " ) ol" + ",LATERAL (" + " SELECT" + " (minv.total_stock::NUMERIC * 1000000" + " + minv.total_stock_frac::NUMERIC)" + " - (minv.total_sold::NUMERIC * 1000000" + " + minv.total_sold_frac::NUMERIC)" + " - (minv.total_lost::NUMERIC * 1000000" + " + minv.total_lost_frac::NUMERIC)" + " - il.total_locked" + " - ol.total_locked" + " AS remaining_total" + " ) rt" + " WHERE (" + " (COALESCE (array_length ($1::TEXT[], 1), 0) > 0" + " AND minv.product_id = ANY ($1::TEXT[]))" + " OR" + " (COALESCE (array_length ($2::BIGINT[], 1), 0) > 0" + " AND EXISTS (" + " SELECT 1" + " FROM merchant_product_categories mpc" + " WHERE mpc.product_serial = minv.product_serial" + " AND mpc.category_serial = ANY ($2::BIGINT[])" + " ))" + " )"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_inventory_products_cb, + &plc); + GNUNET_PQ_cleanup_query_params_closures (params); + /* If there was an error inside lookup_inventory_products_cb, return a hard error. */ + if (plc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_login_tokens.c b/src/backenddb/iterate_login_tokens.c @@ -0,0 +1,177 @@ +/* + 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_login_tokens.c + * @brief Implementation of the iterate_login_tokens function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_login_tokens.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_products(). + */ +struct LookupLoginTokensContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_LoginTokensCallback 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 products. + * + * @param[in,out] cls of type `struct LookupProductsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_login_tokens_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupLoginTokensContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint32_t validity_scope; + uint64_t serial; + struct GNUNET_TIME_Timestamp expiration_time; + struct GNUNET_TIME_Timestamp creation_time; + char *description; + struct TALER_MERCHANTDB_LoginTokenP token; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("token", + &token), + GNUNET_PQ_result_spec_uint32 ("validity_scope", + &validity_scope), + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_timestamp ("creation_time", + &creation_time), + GNUNET_PQ_result_spec_timestamp ("expiration_time", + &expiration_time), + GNUNET_PQ_result_spec_uint64 ("serial", + &serial), + 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, + creation_time, + expiration_time, + validity_scope, + description, + serial); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_login_tokens ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t offset, + int64_t limit, + TALER_MERCHANTDB_LoginTokensCallback cb, + void *cb_cls) +{ + struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + struct LookupLoginTokensContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_products_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_timestamp (&now), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " token" + ",serial" + ",creation_time" + ",expiration_time" + ",validity_scope" + ",description" + " FROM merchant_login_tokens" + " WHERE expiration_time > $1" + " AND serial > $2" + " ORDER BY serial ASC" + " LIMIT $3"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " token" + ",serial" + ",creation_time" + ",expiration_time" + ",validity_scope" + ",description" + " FROM merchant_login_tokens" + " WHERE expiration_time > $1" + " AND serial < $2" + " ORDER BY serial DESC" + " LIMIT $3"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_login_tokens_cb, + &plc); + /* If there was an error inside lookup_products_cb, return a hard error. */ + if (plc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_money_pots.c b/src/backenddb/iterate_money_pots.c @@ -0,0 +1,171 @@ +/* + 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_money_pots.c + * @brief Implementation of the iterate_money_pots function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_money_pots.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_money_pots(). + */ +struct LookupMoneyPotsContext +{ + /** + * DB context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_MoneyPotsCallback 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 money pots. + * + * @param[in,out] cls of type `struct LookupMoneyPotsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_money_pots_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupMoneyPotsContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t money_pot_serial; + char *money_pot_name; + size_t pot_total_len; + struct TALER_Amount *pot_totals; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("money_pot_serial", + &money_pot_serial), + GNUNET_PQ_result_spec_string ("money_pot_name", + &money_pot_name), + TALER_PQ_result_spec_array_amount_with_currency (plc->pg->conn, + "merchant", + "pot_totals", + &pot_total_len, + &pot_totals), + 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, + money_pot_serial, + money_pot_name, + pot_total_len, + pot_totals); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_money_pots ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_MoneyPotsCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + struct LookupMoneyPotsContext plc = { + .pg = pg, + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_money_pots_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " money_pot_serial" + " ,money_pot_name" + " ,pot_totals" + " FROM merchant_money_pots" + " WHERE money_pot_serial > $1" + " ORDER BY money_pot_serial ASC" + " LIMIT $2"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " money_pot_serial" + " ,money_pot_name" + " ,pot_totals" + " FROM merchant_money_pots" + " WHERE money_pot_serial < $1" + " ORDER BY money_pot_serial DESC" + " LIMIT $2"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_money_pots_cb, + &plc); + /* If there was an error inside lookup_money_pots_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_open_transfers.c b/src/backenddb/iterate_open_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_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/select_open_transfers.sql b/src/backenddb/iterate_open_transfers.sql diff --git a/src/backenddb/iterate_order_blinded_sigs.c b/src/backenddb/iterate_order_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_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_orders.c b/src/backenddb/iterate_orders.c @@ -0,0 +1,269 @@ +/* + This file is part of TALER + Copyright (C) 2022, 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_orders.c + * @brief Implementation of the iterate_orders function for Postgres + * @author Iván Ávalos + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_orders.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_orders(). + */ +struct LookupOrdersContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_OrdersCallback 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 orders. + * + * @param[in,out] cls of type `struct LookupOrdersContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_orders_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupOrdersContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *order_id; + uint64_t order_serial; + struct GNUNET_TIME_Timestamp ts; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("order_id", + &order_id), + GNUNET_PQ_result_spec_uint64 ("order_serial", + &order_serial), + GNUNET_PQ_result_spec_timestamp ("creation_time", + &ts), + 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, + order_id, + order_serial, + ts); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_orders ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_MERCHANTDB_OrderFilter *of, + TALER_MERCHANTDB_OrdersCallback cb, + void *cb_cls) +{ + struct LookupOrdersContext plc = { + .cb = cb, + .cb_cls = cb_cls + }; + uint64_t limit = (of->delta > 0) ? of->delta : -of->delta; + struct GNUNET_PQ_QueryParam params[] = { + /* $1 */ + GNUNET_PQ_query_param_uint64 (&limit), + GNUNET_PQ_query_param_uint64 (&of->start_row), + GNUNET_PQ_query_param_timestamp (&of->date), + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->paid)), + /* $5 */ + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->paid)), + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->refunded)), + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->refunded)), + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->wired)), + GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->wired)), + /* $10 */ + GNUNET_PQ_query_param_bool (NULL == of->session_id), + NULL == of->session_id + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (of->session_id), + GNUNET_PQ_query_param_bool (NULL == of->fulfillment_url), + NULL == of->fulfillment_url + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (of->fulfillment_url), + NULL == of->summary_filter + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (of->summary_filter), + 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)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Looking up orders, using filter paid: %d, refunded: %d, wired: %d\n", + of->paid, + of->refunded, + of->wired); + + if (of->delta > 0) + { + TMH_PQ_prepare_anon (pg, + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_orders" + " WHERE order_serial > $2" + " AND" + " creation_time > $3" + " AND ($4 OR " + " NOT CAST($5 AS BOOL))" /* unclaimed orders are never paid */ + " AND ($6 OR " + " NOT CAST($7 AS BOOL))"/* unclaimed orders are never refunded */ + " AND ($8 OR " + " NOT CAST($9 AS BOOL))" /* unclaimed orders are never wired */ + " AND" + " (order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms))" /* only select unclaimed orders */ + " AND ($10 OR " + " ($11 = session_id))" + " AND ($12 OR " + " ($13 = fulfillment_url))" + " AND ( ($14::TEXT IS NULL) OR " + " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" + " ORDER BY order_serial ASC" + " LIMIT $1)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_contract_terms" + " WHERE order_serial > $2" + " AND" + " creation_time > $3" + " AND ($4 OR " + " (CAST($5 AS BOOL) = paid))" + " AND ($6 OR " + " (CAST($7 AS BOOL) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))))" + " AND ($8 OR" + " (CAST($9 AS BOOL) = wired))" + " AND ($10 OR " + " ($11 = session_id))" + " AND ($12 OR " + " ($13 = fulfillment_url))" + " AND ( ($14::TEXT IS NULL) OR " + " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" + " ORDER BY order_serial ASC" + " LIMIT $1)" + " ORDER BY order_serial ASC" + " LIMIT $1"); + } + else + { + TMH_PQ_prepare_anon (pg, + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_orders" + " WHERE order_serial < $2" + " AND" + " creation_time < $3" + " AND ($4 OR " + " NOT CAST($5 AS BOOL))" /* unclaimed orders are never paid */ + " AND ($6 OR " + " NOT CAST($7 AS BOOL))"/* unclaimed orders are never refunded */ + " AND ($8 OR " + " NOT CAST($9 AS BOOL))" /* unclaimed orders are never wired */ + " AND" + " order_serial NOT IN" + " (SELECT order_serial" + " FROM merchant_contract_terms)" /* only select unclaimed orders */ + " AND ($10 OR " + " ($11 = session_id))" + " AND ($12 OR " + " ($13 = fulfillment_url))" + " AND ( ($14::TEXT IS NULL) OR " + " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" + " ORDER BY order_serial DESC" + " LIMIT $1)" + "UNION " /* union ensures elements are distinct! */ + "(SELECT" + " order_id" + ",order_serial" + ",creation_time" + " FROM merchant_contract_terms" + " WHERE order_serial < $2" + " AND" + " creation_time < $3" + " AND ($4 OR " + " (CAST($5 AS BOOL) = paid))" + " AND ($6 OR " + " (CAST($7 AS BOOL) = (order_serial IN" + " (SELECT order_serial " + " FROM merchant_refunds))))" + " AND ($8 OR" + " (CAST($9 AS BOOL) = wired))" + " AND ($10 OR " + " ($11 = session_id))" + " AND ($12 OR " + " ($13 = fulfillment_url))" + " AND ( ($14::TEXT IS NULL) OR " + " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" + " ORDER BY order_serial DESC" + " LIMIT $1)" + " ORDER BY order_serial DESC" + " LIMIT $1"); + } + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_orders_cb, + &plc); + if (plc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_otp_devices.c b/src/backenddb/iterate_otp_devices.c @@ -0,0 +1,128 @@ +/* + 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_otp_devices.c + * @brief Implementation of the iterate_otp_devices function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_otp_devices.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_otp_devices(). + */ +struct LookupOtpDeviceContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_OtpDeviceCallback 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 otp_device. + * + * @param[in,out] cls of type `struct LookupOtpDeviceContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_otp_devices_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupOtpDeviceContext *tlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *otp_device_id; + char *otp_device_description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("otp_id", + &otp_device_id), + GNUNET_PQ_result_spec_string ("otp_description", + &otp_device_description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tlc->extract_failed = true; + return; + } + tlc->cb (tlc->cb_cls, + otp_device_id, + otp_device_description); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_otp_devices ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_OtpDeviceCallback cb, + void *cb_cls) +{ + struct LookupOtpDeviceContext tlc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_otp_device_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + " otp_id" + ",otp_description" + " FROM merchant_otp_devices"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_otp_devices_cb, + &tlc); + /* If there was an error inside lookup_otp_device_cb, return a hard error. */ + if (tlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_pending_deposits.c b/src/backenddb/iterate_pending_deposits.c @@ -0,0 +1,178 @@ +/* + 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_pending_deposits.c + * @brief Implementation of the iterate_pending_deposits function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_pending_deposits.h" +#include "helper.h" + + +/** + * Context for lookup_pending_deposits(). + */ +struct LookupDepositsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_PendingDepositsCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Database context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Set to the return value on errors. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about instances. + * + * @param cls of type `struct LookupDepositsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_deposits_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupDepositsContext *ldc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t deposit_serial; + struct GNUNET_TIME_Absolute wire_deadline; + struct GNUNET_TIME_Absolute retry_time; + struct TALER_PrivateContractHashP h_contract_terms; + struct TALER_MerchantPrivateKeyP merchant_priv; + char *instance_id; + struct TALER_MerchantWireHashP h_wire; + struct TALER_Amount amount_with_fee; + struct TALER_Amount deposit_fee; + struct TALER_CoinSpendPublicKeyP coin_pub; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("out_deposit_serial", + &deposit_serial), + GNUNET_PQ_result_spec_auto_from_type ("out_h_contract_terms", + &h_contract_terms), + GNUNET_PQ_result_spec_auto_from_type ("out_merchant_priv", + &merchant_priv), + GNUNET_PQ_result_spec_string ("out_merchant_id", + &instance_id), + GNUNET_PQ_result_spec_absolute_time ("out_wire_transfer_deadline", + &wire_deadline), + GNUNET_PQ_result_spec_absolute_time ("out_retry_time", + &retry_time), + GNUNET_PQ_result_spec_auto_from_type ("out_h_wire", + &h_wire), + TALER_PQ_result_spec_amount_with_currency ("out_amount_with_fee", + &amount_with_fee), + TALER_PQ_result_spec_amount_with_currency ("out_deposit_fee", + &deposit_fee), + GNUNET_PQ_result_spec_auto_from_type ("out_coin_pub", + &coin_pub), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ldc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ldc->cb (ldc->cb_cls, + deposit_serial, + wire_deadline, + retry_time, + &h_contract_terms, + &merchant_priv, + instance_id, + &h_wire, + &amount_with_fee, + &deposit_fee, + &coin_pub); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_deposits ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + uint64_t limit, + bool allow_future, + TALER_MERCHANTDB_PendingDepositsCallback cb, + void *cb_cls) +{ + struct LookupDepositsContext ldc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_TIME_Absolute now + = GNUNET_TIME_absolute_get (); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (exchange_url), + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_uint64 (&limit), + GNUNET_PQ_query_param_bool (allow_future), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_pending_deposits", + "SELECT" + " out_deposit_serial" + " ,out_h_contract_terms" + " ,out_merchant_priv" + " ,out_merchant_id" + " ,out_wire_transfer_deadline" + " ,out_retry_time" + " ,out_h_wire" + " ,out_amount_with_fee" + " ,out_deposit_fee" + " ,out_coin_pub" + " FROM merchant.lookup_pending_deposits($1, $2, $3, $4)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_pending_deposits", + params, + &lookup_deposits_cb, + &ldc); + if (0 > ldc.qs) + return ldc.qs; + return qs; +} diff --git a/src/backenddb/lookup_pending_deposits.sql b/src/backenddb/iterate_pending_deposits.sql diff --git a/src/backenddb/iterate_pending_webhooks.c b/src/backenddb/iterate_pending_webhooks.c @@ -0,0 +1,198 @@ +/* + 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.c + * @brief Implementation of the iterate_pending_webhooks function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_pending_webhooks.h" +#include "helper.h" + +/** + * Context used for lookup_pending_webhooks_cb(). + */ +struct LookupPendingWebhookContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_PendingWebhooksCallback 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 LookupPendingWebhookContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_pending_webhooks_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupPendingWebhookContext *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 ("webhook_pending_serial", + &webhook_pending_serial), + GNUNET_PQ_result_spec_absolute_time ("next_attempt", + &next_attempt), + GNUNET_PQ_result_spec_uint32 ("retries", + &retries), + GNUNET_PQ_result_spec_string ("url", + &url), + GNUNET_PQ_result_spec_string ("http_method", + &http_method), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("header", + &header), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("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 ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t limit, + TALER_MERCHANTDB_PendingWebhooksCallback cb, + void *cb_cls) +{ + struct LookupPendingWebhookContext pwlc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false, + }; + struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_uint64 (&limit), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "lookup_pending_webhooks", + "SELECT" + " webhook_pending_serial" + " ,next_attempt" + " ,retries" + " ,url" + " ,http_method" + " ,header" + " ,body" + " FROM merchant.merchant_pending_webhooks" + " WHERE next_attempt <= $1" + " ORDER BY next_attempt ASC" + " LIMIT $2"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "lookup_pending_webhooks", + params, + &lookup_pending_webhooks_cb, + &pwlc); + if (pwlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_webhooks_next ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_PendingWebhooksCallback cb, + void *cb_cls) +{ + struct LookupPendingWebhookContext pwlc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params_null[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "iterate_pending_webhooks_next", + "SELECT" + " webhook_pending_serial" + " ,next_attempt" + " ,retries" + " ,url" + " ,http_method" + " ,header" + " ,body" + " FROM merchant.merchant_pending_webhooks" + " ORDER BY next_attempt ASC" + " LIMIT 1"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "iterate_pending_webhooks_next", + params_null, + &lookup_pending_webhooks_cb, + &pwlc); + if (pwlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_product_groups.c b/src/backenddb/iterate_product_groups.c @@ -0,0 +1,160 @@ +/* + 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_product_groups.c + * @brief Implementation of the iterate_product_groups function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_product_groups.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_product_groups(). + */ +struct LookupProductGroupsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ProductGroupsCallback 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 product groups. + * + * @param[in,out] cls of type `struct LookupProductGroupsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_product_groups_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupProductGroupsContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t product_group_serial; + char *product_group_name; + char *product_group_description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("product_group_serial", + &product_group_serial), + GNUNET_PQ_result_spec_string ("product_group_name", + &product_group_name), + GNUNET_PQ_result_spec_string ("product_group_description", + &product_group_description), + 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, + product_group_serial, + product_group_name, + product_group_description); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_product_groups ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_ProductGroupsCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + struct LookupProductGroupsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_product_groups_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " product_group_serial" + " ,product_group_name" + " ,product_group_description" + " FROM merchant_product_groups" + " WHERE product_group_serial > $1" + " ORDER BY product_group_serial ASC" + " LIMIT $2"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " product_group_serial" + " ,product_group_name" + " ,product_group_description" + " FROM merchant_product_groups" + " WHERE product_group_serial < $1" + " ORDER BY product_group_serial DESC" + " LIMIT $2"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_product_groups_cb, + &plc); + /* If there was an error inside lookup_product_groups_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_products.c b/src/backenddb/iterate_products.c @@ -0,0 +1,195 @@ +/* + 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_products.c + * @brief Implementation of the iterate_products function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_products.h" +#include "helper.h" + +/** + * Context used for TALER_MERCHANTDB_iterate_products(). + */ +struct LookupProductsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ProductsCallback 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 products. + * + * @param[in,out] cls of type `struct LookupProductsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_products_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupProductsContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *product_id; + uint64_t product_serial; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("product_id", + &product_id), + GNUNET_PQ_result_spec_uint64 ("product_serial", + &product_serial), + 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, + product_serial, + product_id); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_products ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t offset, + int64_t limit, + const char *category_filter, + const char *name_filter, + const char *description_filter, + uint64_t product_group_id_filter, + TALER_MERCHANTDB_ProductsCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + struct LookupProductsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_products_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&offset), + NULL == category_filter + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (category_filter), + NULL == name_filter + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (name_filter), + NULL == description_filter + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (description_filter), + GNUNET_PQ_query_param_uint64 (&plimit), + GNUNET_PQ_query_param_uint64 (&product_group_id_filter), + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " product_id" + " ,product_serial" + " FROM merchant_inventory" + " WHERE product_serial > $1" + " AND ( ($2::TEXT IS NULL) OR" + " (product_serial IN" + " (SELECT product_serial" + " FROM merchant_product_categories" + " WHERE category_serial IN" + " (SELECT category_serial" + " FROM merchant_categories" + " WHERE LOWER(category_name) LIKE LOWER($2)))) )" + " AND ( (0 = $6::INT8) OR" + " (product_group_serial = $6) )" + " AND ( ($3::TEXT IS NULL) OR" + " (LOWER(product_name) LIKE LOWER($3)) )" + " AND ( ($4::TEXT IS NULL) OR" + " (description LIKE LOWER($4)) )" + " ORDER BY product_serial ASC" + " LIMIT $5"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " product_id" + " ,product_serial" + " FROM merchant_inventory" + " WHERE product_serial < $1" + " AND ( ($2::TEXT IS NULL) OR" + " (product_serial IN" + " (SELECT product_serial" + " FROM merchant_product_categories" + " WHERE category_serial IN" + " (SELECT category_serial" + " FROM merchant_categories" + " WHERE LOWER(category_name) LIKE LOWER($2)))) )" + " AND ( (0 = $6::INT8) OR" + " (product_group_serial = $6) )" + " AND ( ($3::TEXT IS NULL) OR" + " (LOWER(product_name) LIKE LOWER($3)) )" + " AND ( ($4::TEXT IS NULL) OR" + " (description LIKE LOWER($4)) )" + " ORDER BY product_serial DESC" + " LIMIT $5"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_products_cb, + &plc); + /* If there was an error inside lookup_products_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_reconciliation_details.c b/src/backenddb/iterate_reconciliation_details.c @@ -0,0 +1,173 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_reconciliation_details.c + * @brief Implementation of the iterate_reconciliation_details function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_reconciliation_details.h" +#include "helper.h" + + +/** + * Context for TALER_MERCHANTDB_iterate_reconciliation_details(). + */ +struct ReconciliationContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ReconciliationDetailsCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Database context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Set to the return value on errors. + */ + enum GNUNET_DB_QueryStatus qs; + +}; + + +/** + * Function to be called with the results of a SELECT statement + * that has returned @a num_results results about reconciliation + * details. + * + * @param cls of type `struct ReconciliationContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +reconciliation_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct ReconciliationContext *lic = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *order_id; + uint64_t dvs; + uint64_t dfs; + uint64_t fvs; + uint64_t ffs; + char *currency; + struct TALER_Amount remaining_deposit; + struct TALER_Amount deposit_fee; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("order_id", + &order_id), + GNUNET_PQ_result_spec_string ("currency", + &currency), + GNUNET_PQ_result_spec_uint64 ("deposit_value_sum", + &dvs), + GNUNET_PQ_result_spec_uint64 ("deposit_frac_sum", + &dfs), + GNUNET_PQ_result_spec_uint64 ("fee_value_sum", + &fvs), + GNUNET_PQ_result_spec_uint64 ("fee_frac_sum", + &ffs), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lic->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &remaining_deposit)); + GNUNET_assert (GNUNET_OK == + TALER_amount_set_zero (currency, + &deposit_fee)); + remaining_deposit.value = dvs + dfs / TALER_AMOUNT_FRAC_BASE; + remaining_deposit.fraction = dfs % TALER_AMOUNT_FRAC_BASE; + deposit_fee.value = fvs + ffs / TALER_AMOUNT_FRAC_BASE; + deposit_fee.fraction = ffs % TALER_AMOUNT_FRAC_BASE; + + lic->cb (lic->cb_cls, + order_id, + &remaining_deposit, + &deposit_fee); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_reconciliation_details ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t expected_incoming_serial, + TALER_MERCHANTDB_ReconciliationDetailsCallback cb, + void *cb_cls) +{ + struct ReconciliationContext lic = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), + 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" + " mct.order_id" + ",SUM((etc.exchange_deposit_value).val)::INT8 AS deposit_value_sum" + ",SUM((etc.exchange_deposit_value).frac)::INT8 AS deposit_frac_sum" + ",SUM((etc.exchange_deposit_fee).val)::INT8 AS fee_value_sum" + ",SUM((etc.exchange_deposit_fee).frac)::INT8 AS fee_frac_sum" + ",(etc.exchange_deposit_value).curr AS currency" + " FROM merchant_expected_transfer_to_coin etc" + " JOIN merchant_deposits md" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mdc" + " USING (deposit_confirmation_serial)" + " JOIN merchant_contract_terms mct" + " USING (order_serial)" + " WHERE expected_credit_serial=$1" + " GROUP BY mct.order_id, (etc.exchange_deposit_value).curr;"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &reconciliation_cb, + &lic); + if (0 > lic.qs) + return lic.qs; + return qs; +} diff --git a/src/backenddb/iterate_refunds.c b/src/backenddb/iterate_refunds.c @@ -0,0 +1,141 @@ +/* + 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_refunds.c + * @brief Implementation of the iterate_refunds function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_refunds.h" +#include "helper.h" + +/** + * Closure for #lookup_refunds_cb(). + */ +struct LookupRefundsContext +{ + /** + * Function to call for each refund. + */ + TALER_MERCHANTDB_RefundCallback rc; + + /** + * Closure for @e rc. + */ + void *rc_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 closure of type `struct LookupRefundsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_refunds_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRefundsContext *lrc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_CoinSpendPublicKeyP coin_pub; + struct TALER_Amount refund_amount; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + TALER_PQ_result_spec_amount_with_currency ("refund_amount", + &refund_amount), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lrc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + lrc->rc (lrc->rc_cls, + &coin_pub, + &refund_amount); + GNUNET_PQ_cleanup_result (rs); /* technically useless here */ + } + lrc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_refunds ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms, + TALER_MERCHANTDB_RefundCallback rc, + void *rc_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + struct LookupRefundsContext lrc = { + .rc = rc, + .rc_cls = rc_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + 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! */ + TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n", + GNUNET_h2s (&h_contract_terms->hash), + instance_id); + TMH_PQ_prepare_anon (pg, + "SELECT" + " coin_pub" + ",refund_amount" + " FROM merchant_refunds" + " WHERE order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$1)"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_refunds_cb, + &lrc); + if (0 >= qs) + return qs; + return lrc.qs; +} diff --git a/src/backenddb/iterate_refunds_detailed.c b/src/backenddb/iterate_refunds_detailed.c @@ -0,0 +1,180 @@ +/* + 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_refunds_detailed.c + * @brief Implementation of the iterate_refunds_detailed function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_refunds_detailed.h" +#include "helper.h" + +/** + * Closure for #lookup_refunds_detailed_cb(). + */ +struct LookupRefundsDetailedContext +{ + /** + * Function to call for each refund. + */ + TALER_MERCHANTDB_RefundDetailCallback rc; + + /** + * Closure for @e rc. + */ + void *rc_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 GetRefundsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_refunds_detailed_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRefundsDetailedContext *lrdc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + uint64_t refund_serial; + struct GNUNET_TIME_Timestamp timestamp; + struct TALER_CoinSpendPublicKeyP coin_pub; + uint64_t rtransaction_id; + struct TALER_Amount refund_amount; + char *reason; + char *exchange_url; + uint8_t pending8; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("refund_serial", + &refund_serial), + GNUNET_PQ_result_spec_timestamp ("refund_timestamp", + &timestamp), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &coin_pub), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_uint64 ("rtransaction_id", + &rtransaction_id), + GNUNET_PQ_result_spec_string ("reason", + &reason), + TALER_PQ_result_spec_amount_with_currency ("refund_amount", + &refund_amount), + GNUNET_PQ_result_spec_auto_from_type ("pending", + &pending8), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + lrdc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + lrdc->rc (lrdc->rc_cls, + refund_serial, + timestamp, + &coin_pub, + exchange_url, + rtransaction_id, + reason, + &refund_amount, + 0 != pending8); + GNUNET_PQ_cleanup_result (rs); + } + lrdc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_refunds_detailed ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP * + h_contract_terms, + TALER_MERCHANTDB_RefundDetailCallback rc, + void *rc_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + struct LookupRefundsDetailedContext lrdc = { + .rc = rc, + .rc_cls = rc_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + 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! */ + TALER_LOG_DEBUG ("Looking for refund %s + %s\n", + GNUNET_h2s (&h_contract_terms->hash), + instance_id); + + TMH_PQ_prepare_anon (pg, + "SELECT" + " ref.refund_serial" + ",ref.refund_timestamp" + ",dep.coin_pub" + ",mcon.exchange_url" + ",ref.rtransaction_id" + ",ref.reason" + ",ref.refund_amount" + ",merchant_refund_proofs.exchange_sig IS NULL AS pending" + " FROM merchant_deposit_confirmations mcon" + " JOIN merchant_deposits dep" + " USING (deposit_confirmation_serial)" + " JOIN merchant_refunds ref" + " USING (order_serial, coin_pub)" + " LEFT JOIN merchant_refund_proofs" + " USING (refund_serial)" + " WHERE mcon.order_serial=" + " (SELECT order_serial" + " FROM merchant_contract_terms" + " WHERE h_contract_terms=$1)"); + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_refunds_detailed_cb, + &lrdc); + if (0 >= qs) + return qs; + return lrdc.qs; +} diff --git a/src/backenddb/iterate_reports.c b/src/backenddb/iterate_reports.c @@ -0,0 +1,162 @@ +/* + 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.c + * @brief Implementation of the iterate_reports function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_reports.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_reports(). + */ +struct SelectReportsContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_ReportsCallback 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_reports_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct SelectReportsContext *plc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t report_serial; + char *report_description; + struct GNUNET_TIME_Relative frequency; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("report_serial", + &report_serial), + GNUNET_PQ_result_spec_string ("report_description", + &report_description), + GNUNET_PQ_result_spec_relative_time ("frequency", + &frequency), + 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, + report_serial, + report_description, + frequency); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_reports ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_ReportsCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + struct SelectReportsContext plc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the select_reports_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " report_serial" + " ,report_description" + " ,frequency" + " FROM merchant_reports" + " WHERE report_serial > $1" + " AND NOT one_shot_hidden" + " ORDER BY report_serial ASC" + " LIMIT $2"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " report_serial" + " ,report_description" + " ,frequency" + " FROM merchant_reports" + " WHERE report_serial < $1" + " AND NOT one_shot_hidden" + " ORDER BY report_serial DESC" + " LIMIT $2"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &select_reports_cb, + &plc); + /* If there was an error inside select_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.c b/src/backenddb/iterate_reports_pending.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_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/lookup_reports_pending.sql b/src/backenddb/iterate_reports_pending.sql diff --git a/src/backenddb/iterate_spent_tokens_by_order.c b/src/backenddb/iterate_spent_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_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_statistics_amount_by_bucket.c b/src/backenddb/iterate_statistics_amount_by_bucket.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_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 @@ -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_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 @@ -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_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/lookup_statistics_amount_by_interval.sql b/src/backenddb/iterate_statistics_amount_by_interval.sql diff --git a/src/backenddb/iterate_statistics_counter_by_bucket.c b/src/backenddb/iterate_statistics_counter_by_bucket.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_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 @@ -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_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 @@ -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_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/lookup_statistics_counter_by_interval.sql b/src/backenddb/iterate_statistics_counter_by_interval.sql diff --git a/src/backenddb/iterate_templates.c b/src/backenddb/iterate_templates.c @@ -0,0 +1,128 @@ +/* + 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_templates.c + * @brief Implementation of the iterate_templates function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_templates.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_templates(). + */ +struct LookupTemplateContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_TemplatesCallback 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 template. + * + * @param[in,out] cls of type `struct LookupTemplateContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_templates_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTemplateContext *tlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *template_id; + char *template_description; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("template_id", + &template_id), + GNUNET_PQ_result_spec_string ("template_description", + &template_description), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tlc->extract_failed = true; + return; + } + tlc->cb (tlc->cb_cls, + template_id, + template_description); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_templates ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_TemplatesCallback cb, + void *cb_cls) +{ + struct LookupTemplateContext tlc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_template_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + " template_id" + ",template_description" + " FROM merchant_template"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_templates_cb, + &tlc); + /* If there was an error inside lookup_templates_cb, return a hard error. */ + if (tlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_token_families.c b/src/backenddb/iterate_token_families.c @@ -0,0 +1,157 @@ +/* + 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_token_families.c + * @brief Implementation of the iterate_token_families function for Postgres + * @author Christian Blättler + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_token_families.h" +#include "helper.h" +#include "merchantdb_lib.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_token_families(). + */ +struct LookupTokenFamiliesContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_TokenFamiliesCallback 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 LookupTokenFamiliesContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_token_families_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTokenFamiliesContext *tflc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *slug; + char *name; + char *description; + json_t *description_i18n = NULL; + char *kind; + struct GNUNET_TIME_Timestamp valid_after; + struct GNUNET_TIME_Timestamp valid_before; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("slug", + &slug), + GNUNET_PQ_result_spec_string ("name", + &name), + GNUNET_PQ_result_spec_string ("description", + &description), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("description_i18n", + &description_i18n), + NULL), + GNUNET_PQ_result_spec_timestamp ("valid_after", + &valid_after), + GNUNET_PQ_result_spec_timestamp ("valid_before", + &valid_before), + GNUNET_PQ_result_spec_string ("kind", + &kind), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + tflc->extract_failed = true; + return; + } + + tflc->cb (tflc->cb_cls, + slug, + name, + description, + description_i18n, + valid_after, + valid_before, + kind); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_token_families ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_TokenFamiliesCallback cb, + void *cb_cls) +{ + struct LookupTokenFamiliesContext context = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_token_families_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + " slug" + ",name" + ",description" + ",description_i18n::TEXT" + ",valid_after" + ",valid_before" + ",kind" + " FROM merchant_token_families"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_token_families_cb, + &context); + /* If there was an error inside lookup_token_families_cb, return a hard error. */ + if (context.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_token_family_keys.c b/src/backenddb/iterate_token_family_keys.c @@ -0,0 +1,224 @@ +/* + 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_token_family_keys.c + * @brief Implementation of the iterate_token_family_keys function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_token_family_keys.h" +#include "helper.h" + + +/** + * Closure for lookup_token_keys_cb(). + */ +struct Context +{ + /** + * Postgres handle. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call on each result. + */ + TALER_MERCHANTDB_TokenKeyCallback cb; + + /** + * Closure for @e 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 products. + * + * @param[in,out] cls of type `struct LookupProductsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_token_keys_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct Context *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_MERCHANTDB_TokenFamilyKeyDetails details; + char *kind; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_blind_sign_pub ("pub", + &details.pub.public_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_blind_sign_priv ("priv", + &details.priv.private_key), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("signature_validity_start", + &details.signature_validity_start), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("signature_validity_end", + &details.signature_validity_end), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_timestamp ("private_key_deleted_at", + &details.private_key_deleted_at), + NULL), + GNUNET_PQ_result_spec_string ("slug", + &details.token_family.slug), + GNUNET_PQ_result_spec_string ("name", + &details.token_family.name), + GNUNET_PQ_result_spec_string ("description", + &details.token_family.description), + GNUNET_PQ_result_spec_string ("cipher_choice", + &details.token_family.cipher_spec), + TALER_PQ_result_spec_json ("description_i18n", + &details.token_family.description_i18n), + GNUNET_PQ_result_spec_timestamp ("valid_after", + &details.token_family.valid_after), + GNUNET_PQ_result_spec_timestamp ("valid_before", + &details.token_family.valid_before), + GNUNET_PQ_result_spec_relative_time ("duration", + &details.token_family.duration), + GNUNET_PQ_result_spec_relative_time ("validity_granularity", + &details.token_family. + validity_granularity), + GNUNET_PQ_result_spec_relative_time ("start_offset", + &details.token_family.start_offset), + GNUNET_PQ_result_spec_string ("kind", + &kind), + GNUNET_PQ_result_spec_uint64 ("issued", + &details.token_family.issued), + GNUNET_PQ_result_spec_uint64 ("used", + &details.token_family.used), + GNUNET_PQ_result_spec_end + }; + + memset (&details, + 0, + sizeof (details)); + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->extract_failed = true; + return; + } + if (0 == strcmp (kind, + "discount")) + details.token_family.kind = TALER_MERCHANTDB_TFK_Discount; + else if (0 == strcmp (kind, + "subscription")) + details.token_family.kind = TALER_MERCHANTDB_TFK_Subscription; + else + { + GNUNET_break (0); + GNUNET_free (kind); + GNUNET_PQ_cleanup_result (rs); + return; + } + ctx->cb (ctx->cb_cls, + &details); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_token_family_keys ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct GNUNET_TIME_Timestamp start_time, + struct GNUNET_TIME_Timestamp end_time, + TALER_MERCHANTDB_TokenKeyCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (token_family_slug), + GNUNET_PQ_query_param_timestamp (&start_time), + GNUNET_PQ_query_param_timestamp (&end_time), + GNUNET_PQ_query_param_end + }; + struct Context ctx = { + .pg = pg, + .cb = cb, + .cb_cls = cb_cls + }; + 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" + " h_pub" + ",mtfk.pub" + ",mtfk.priv" + ",cipher_choice" + ",mtfk.signature_validity_start" + ",mtfk.signature_validity_end" + ",mtfk.private_key_deleted_at" + ",slug" + ",name" + ",description" + ",description_i18n::TEXT" + ",mtf.valid_after" + ",mtf.valid_before" + ",duration" + ",validity_granularity" + ",start_offset" + ",kind" + ",issued" + ",used" + " FROM merchant_token_families mtf" + " LEFT JOIN merchant_token_family_keys mtfk" + " USING (token_family_serial)" + " WHERE slug=$1" + " AND COALESCE ($2 <= mtfk.signature_validity_end, TRUE)" + " AND COALESCE ($3 >= mtfk.signature_validity_start, TRUE);"); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_token_keys_cb, + &ctx); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Lookup of MTFK %s with valid [%llu,%llu] got %d\n", + token_family_slug, + (unsigned long long) start_time.abs_time.abs_value_us, + (unsigned long long) end_time.abs_time.abs_value_us, + (int) qs); + if (ctx.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_transfer_details.c b/src/backenddb/iterate_transfer_details.c @@ -0,0 +1,153 @@ +/* + 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_transfer_details.c + * @brief Implementation of the iterate_transfer_details function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_transfer_details.h" +#include "helper.h" + +/** + * Closure for #lookup_transfer_details_cb(). + */ +struct LookupTransferDetailsContext +{ + /** + * Function to call for each order that was aggregated. + */ + TALER_MERCHANTDB_TransferDetailsCallback 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 LookupTransferDetailsContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_transfer_details_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTransferDetailsContext *ltdc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + uint64_t current_offset; + struct TALER_TrackTransferDetails ttd; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("offset_in_exchange_list", + &current_offset), + GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", + &ttd.h_contract_terms), + GNUNET_PQ_result_spec_auto_from_type ("coin_pub", + &ttd.coin_pub), + TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_value", + &ttd.coin_value), + TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_fee", + &ttd.coin_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, + (unsigned int) current_offset, + &ttd); + GNUNET_PQ_cleanup_result (rs); + } + ltdc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfer_details ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP *wtid, + TALER_MERCHANTDB_TransferDetailsCallback 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 LookupTransferDetailsContext 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" + " mterm.h_contract_terms" + ",mtcoin.offset_in_exchange_list" + ",dep.coin_pub" + ",mtcoin.exchange_deposit_value" + ",mtcoin.exchange_deposit_fee" + " FROM merchant_expected_transfer_to_coin mtcoin" + " JOIN merchant_deposits dep" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_contract_terms mterm" + " USING (order_serial)" + " JOIN merchant_expected_transfers met" + " USING (expected_credit_serial)" + " WHERE met.wtid=$2" + " AND met.exchange_url=$1"); + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_transfer_details_cb, + &ltdc); + if (0 >= qs) + return qs; + return ltdc.qs; +} diff --git a/src/backenddb/iterate_transfer_details_by_order.c b/src/backenddb/iterate_transfer_details_by_order.c @@ -0,0 +1,237 @@ +/* + This file is part of TALER + Copyright (C) 2023, 2025, 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/backenddb/iterate_transfer_details_by_order.c + * @brief Implementation of the iterate_transfer_details_by_order function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_transfer_details_by_order.h" +#include "helper.h" + +/** + * Closure for lookup_transfer_details_by_order_cb(). + */ +struct LookupTransferDetailsByOrderContext +{ + + /** + * Plugin context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Function to call with all results. + */ + TALER_MERCHANTDB_OrderTransferDetailsCallback 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. We SELECT by coin, + * but because that's not useful for the UI, we combine all coins + * that were deposited in the same wire transfer into a single + * record before calling the callback. + * + * @param cls of type `struct LookupTransferDetailsByOrderContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_transfer_details_by_order_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTransferDetailsByOrderContext *ltdo = cls; + struct TALER_WireTransferIdentifierRawP last_wtid; + char *last_exchange_url = NULL; + struct GNUNET_TIME_Timestamp last_execution_time; + struct TALER_Amount last_deposit_value; + struct TALER_Amount last_deposit_fee; + bool last_confirmed; + uint64_t last_expected_credit_serial; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_WireTransferIdentifierRawP wtid; + char *exchange_url; + struct GNUNET_TIME_Timestamp execution_time; + struct TALER_Amount deposit_value; + struct TALER_Amount deposit_fee; + bool confirmed; + uint64_t expected_credit_serial; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", + &execution_time), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_bool ("confirmed", + &confirmed), + GNUNET_PQ_result_spec_auto_from_type ("wtid", + &wtid), + GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", + &expected_credit_serial), + 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); + ltdo->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + if (0 == i) + { + last_wtid = wtid; + last_exchange_url = exchange_url; + last_execution_time = execution_time; + last_deposit_value = deposit_value; + last_deposit_fee = deposit_fee; + last_confirmed = confirmed; + last_expected_credit_serial = expected_credit_serial; + continue; + } + if ( (0 == + GNUNET_memcmp (&wtid, + &last_wtid)) && + (0 == strcmp (exchange_url, + last_exchange_url)) && + (expected_credit_serial == + last_expected_credit_serial) && + (GNUNET_TIME_timestamp_cmp (execution_time, + ==, + last_execution_time)) && + (last_confirmed == confirmed) && + (GNUNET_OK == + TALER_amount_cmp_currency (&deposit_value, + &last_deposit_value)) ) + { + GNUNET_assert (0 <= + TALER_amount_add (&last_deposit_value, + &last_deposit_value, + &deposit_value)); + GNUNET_assert (0 <= + TALER_amount_add (&last_deposit_fee, + &last_deposit_fee, + &deposit_fee)); + GNUNET_free (exchange_url); + continue; + } + ltdo->cb (ltdo->cb_cls, + &last_wtid, + last_exchange_url, + last_execution_time, + &last_deposit_value, + &last_deposit_fee, + last_confirmed, + last_expected_credit_serial); + GNUNET_free (last_exchange_url); + last_wtid = wtid; + last_exchange_url = exchange_url; + last_execution_time = execution_time; + last_deposit_value = deposit_value; + last_deposit_fee = deposit_fee; + last_confirmed = confirmed; + last_expected_credit_serial = expected_credit_serial; + } + if (num_results > 0) + { + ltdo->cb (ltdo->cb_cls, + &last_wtid, + last_exchange_url, + last_execution_time, + &last_deposit_value, + &last_deposit_fee, + last_confirmed, + last_expected_credit_serial); + } + GNUNET_free (last_exchange_url); + ltdo->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfer_details_by_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_OrderTransferDetailsCallback cb, + void *cb_cls) +{ + struct LookupTransferDetailsByOrderContext ltdo = { + .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" + " md.deposit_serial" + ",mcon.exchange_url" + ",met.wtid" + ",mtc.exchange_deposit_value" + ",mtc.exchange_deposit_fee" + ",mcon.deposit_timestamp" + ",met.confirmed" + ",met.expected_credit_serial" + " FROM merchant_expected_transfer_to_coin mtc" + " JOIN merchant_deposits md" + " USING (deposit_serial)" + " JOIN merchant_deposit_confirmations mcon" + " USING (deposit_confirmation_serial)" + " JOIN merchant_expected_transfers met" + " USING (expected_credit_serial)" + " JOIN merchant_accounts acc" + " ON (acc.account_serial = met.account_serial)" + " JOIN merchant_contract_terms contracts" + " USING (order_serial)" + " WHERE mcon.order_serial=$1" + " ORDER BY met.wtid"); + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_transfer_details_by_order_cb, + &ltdo); + if (qs < 0) + return qs; + return ltdo.qs; +} diff --git a/src/backenddb/iterate_transfer_summary.c b/src/backenddb/iterate_transfer_summary.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_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_transfers.c b/src/backenddb/iterate_transfers.c @@ -0,0 +1,239 @@ +/* + This file is part of TALER + Copyright (C) 2022-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_transfers.c + * @brief Implementation of the iterate_transfers function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_transfers.h" +#include "helper.h" + + +/** + * Closure for #lookup_transfers_cb(). + */ +struct LookupTransfersContext +{ + /** + * Function to call on results. + */ + TALER_MERCHANTDB_TransferCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Postgres context. + */ + struct TALER_MERCHANTDB_PostgresContext *pg; + + /** + * Transaction status (set). + */ + 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 LookupTransfersContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_transfers_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupTransfersContext *ltc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_Amount credit_amount; + struct TALER_WireTransferIdentifierRawP wtid; + struct TALER_FullPayto payto_uri; + char *exchange_url; + uint64_t transfer_serial_id; + uint64_t expected_transfer_serial_id = 0; + struct GNUNET_TIME_Absolute execution_time; + bool expected; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_result_spec_amount_with_currency ("credit_amount", + &credit_amount), + GNUNET_PQ_result_spec_auto_from_type ("wtid", + &wtid), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto_uri.full_payto), + GNUNET_PQ_result_spec_string ("exchange_url", + &exchange_url), + GNUNET_PQ_result_spec_uint64 ("credit_serial", + &transfer_serial_id), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", + &expected_transfer_serial_id), + NULL), + GNUNET_PQ_result_spec_absolute_time ("execution_time", + &execution_time), + GNUNET_PQ_result_spec_bool ("expected", + &expected), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ltc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + ltc->cb (ltc->cb_cls, + &credit_amount, + &wtid, + payto_uri, + exchange_url, + transfer_serial_id, + expected_transfer_serial_id, + execution_time, + expected); + GNUNET_PQ_cleanup_result (rs); + } + ltc->qs = num_results; +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfers ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + struct GNUNET_TIME_Timestamp before, + struct GNUNET_TIME_Timestamp after, + int64_t limit, + uint64_t offset, + enum TALER_EXCHANGE_YesNoAll expected, + TALER_MERCHANTDB_TransferCallback cb, + void *cb_cls) +{ + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); + bool by_time = ( (! GNUNET_TIME_absolute_is_never (before.abs_time)) || + (! GNUNET_TIME_absolute_is_zero (after.abs_time)) ); + struct LookupTransfersContext ltc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_timestamp (&before), + GNUNET_PQ_query_param_timestamp (&after), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + NULL == payto_uri.full_payto + ? GNUNET_PQ_query_param_null () /* NULL: do not filter by payto URI */ + : GNUNET_PQ_query_param_string (payto_uri.full_payto), + GNUNET_PQ_query_param_bool (! by_time), /* $6: filter by time? */ + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == expected), /* filter by expected? */ + GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == expected), + + 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)); + if (limit > 0) + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " mt.credit_amount" + ",mt.wtid" + ",mac.payto_uri" + ",mt.exchange_url" + ",mt.credit_serial" + ",mt.execution_time" + ",mt.expected" + ",met.expected_credit_serial" + " FROM merchant_transfers mt" + " JOIN merchant_accounts mac" + " USING (account_serial)" + " LEFT JOIN merchant_expected_transfers met" + " ON mt.wtid = met.wtid" + " AND mt.account_serial = met.account_serial" + " AND mt.exchange_url = met.exchange_url" + " AND mt.expected" + " WHERE ( $6 OR " + " (mt.execution_time < $1 AND" + " mt.execution_time >= $2) )" + " AND ( (CAST($5 AS TEXT) IS NULL) OR " + " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" + " =REGEXP_REPLACE($5,'\\?.*','')) )" + " AND ( $7 OR " + " (mt.expected = $8) )" + " AND (mt.credit_serial > $3)" + " ORDER BY mt.credit_serial ASC" + " LIMIT $4"); + } + else + { + TMH_PQ_prepare_anon (pg, + "SELECT" + " mt.credit_amount" + ",mt.wtid" + ",mac.payto_uri" + ",mt.exchange_url" + ",mt.credit_serial" + ",mt.execution_time" + ",mt.expected" + ",met.expected_credit_serial" + " FROM merchant_transfers mt" + " JOIN merchant_accounts mac" + " USING (account_serial)" + " LEFT JOIN merchant_expected_transfers met" + " ON mt.wtid = met.wtid" + " AND mt.account_serial = met.account_serial" + " AND mt.exchange_url = met.exchange_url" + " AND mt.expected" + " WHERE ( $6 OR " + " (mt.execution_time < $1 AND" + " mt.execution_time >= $2) )" + " AND ( (CAST($5 AS TEXT) IS NULL) OR " + " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" + " =REGEXP_REPLACE($5,'\\?.*','')) )" + " AND ( $7 OR " + " (mt.expected = $8) )" + " AND (mt.credit_serial < $3)" + " ORDER BY mt.credit_serial DESC" + " LIMIT $4"); + } + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "", + params, + &lookup_transfers_cb, + &ltc); + if (0 >= qs) + return qs; + return ltc.qs; +} diff --git a/src/backenddb/iterate_units.c b/src/backenddb/iterate_units.c @@ -0,0 +1,144 @@ +/* + 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_units.c + * @brief Implementation of the iterate_units function for Postgres + * @author Bohdan Potuzhnyi + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_units.h" +#include "helper.h" + + +/** + * Context used for TALER_MERCHANTDB_iterate_units(). + */ +struct LookupUnitsContext +{ + TALER_MERCHANTDB_UnitsCallback cb; + void *cb_cls; + bool extract_failed; +}; + + +static void +lookup_units_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupUnitsContext *luc = cls; + + for (unsigned int i = 0; i<num_results; i++) + { + struct TALER_MERCHANTDB_UnitDetails ud = { 0 }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("unit_serial", + &ud.unit_serial), + GNUNET_PQ_result_spec_string ("unit", + &ud.unit), + GNUNET_PQ_result_spec_string ("unit_name_long", + &ud.unit_name_long), + GNUNET_PQ_result_spec_string ("unit_name_short", + &ud.unit_name_short), + TALER_PQ_result_spec_json ("unit_name_long_i18n", + &ud.unit_name_long_i18n), + TALER_PQ_result_spec_json ("unit_name_short_i18n", + &ud.unit_name_short_i18n), + GNUNET_PQ_result_spec_bool ("unit_allow_fraction", + &ud.unit_allow_fraction), + GNUNET_PQ_result_spec_uint32 ("unit_precision_level", + &ud.unit_precision_level), + GNUNET_PQ_result_spec_bool ("unit_active", + &ud.unit_active), + GNUNET_PQ_result_spec_bool ("unit_builtin", + &ud.unit_builtin), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + luc->extract_failed = true; + return; + } + luc->cb (luc->cb_cls, + ud.unit_serial, + &ud); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_units ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_UnitsCallback cb, + void *cb_cls) +{ + struct LookupUnitsContext luc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false + }; + struct GNUNET_PQ_QueryParam params[] = { + 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 cu.unit_serial" + " ,cu.unit" + " ,cu.unit_name_long" + " ,cu.unit_name_short" + " ,cu.unit_name_long_i18n" + " ,cu.unit_name_short_i18n" + " ,cu.unit_allow_fraction" + " ,cu.unit_precision_level" + " ,cu.unit_active" + " ,FALSE AS unit_builtin" + " FROM merchant_custom_units cu" + " UNION ALL " + "SELECT bu.unit_serial" + " ,bu.unit" + " ,bu.unit_name_long" + " ,bu.unit_name_short" + " ,bu.unit_name_long_i18n" + " ,bu.unit_name_short_i18n" + " ,COALESCE(bo.override_allow_fraction, bu.unit_allow_fraction)" + " ,COALESCE(bo.override_precision_level, bu.unit_precision_level)" + " ,COALESCE(bo.override_active, bu.unit_active)" + " ,TRUE AS unit_builtin" + " FROM merchant.merchant_builtin_units bu" + " LEFT JOIN merchant_builtin_unit_overrides bo" + " ON bo.builtin_unit_serial = bu.unit_serial" + " ORDER BY unit"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_units_cb, + &luc); + if (luc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_webhooks.c b/src/backenddb/iterate_webhooks.c @@ -0,0 +1,128 @@ +/* + 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_webhooks.c + * @brief Implementation of the iterate_webhooks function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_webhooks.h" +#include "helper.h" + +/** + * Context used for postgres_lookup_webhooks(). + */ +struct LookupWebhookContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_WebhooksCallback 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 LookupWebhookContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_webhooks_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupWebhookContext *wlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *webhook_id; + char *event_type; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("webhook_id", + &webhook_id), + GNUNET_PQ_result_spec_string ("event_type", + &event_type), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + wlc->extract_failed = true; + return; + } + wlc->cb (wlc->cb_cls, + webhook_id, + event_type); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_webhooks ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_WebhooksCallback cb, + void *cb_cls) +{ + struct LookupWebhookContext wlc = { + .cb = cb, + .cb_cls = cb_cls, + /* Can be overwritten by the lookup_webhook_cb */ + .extract_failed = false, + }; + struct GNUNET_PQ_QueryParam params[] = { + 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" + " webhook_id" + ",event_type" + " FROM merchant_webhook"); + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_webhooks_cb, + &wlc); + /* If there was an error inside lookup_webhook_cb, return a hard error. */ + if (wlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_webhooks_by_event.c b/src/backenddb/iterate_webhooks_by_event.c @@ -0,0 +1,154 @@ +/* + 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_webhooks_by_event.c + * @brief Implementation of the iterate_webhooks_by_event function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_webhooks_by_event.h" +#include "helper.h" + +/** + * Context used for lookup_webhook_by_event_cb(). + */ +struct LookupWebhookDetailContext +{ + /** + * Function to call with the results. + */ + TALER_MERCHANTDB_WebhookDetailCallback 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 LookupPendingWebhookContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lookup_webhook_by_event_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupWebhookDetailContext *wlc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + uint64_t webhook_serial; + char *event_type; + char *url; + char *http_method; + char *header_template; + char *body_template; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("webhook_serial", + &webhook_serial), + GNUNET_PQ_result_spec_string ("event_type", + &event_type), + GNUNET_PQ_result_spec_string ("url", + &url), + GNUNET_PQ_result_spec_string ("http_method", + &http_method), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("header_template", + &header_template), + NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_string ("body_template", + &body_template), + NULL), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + wlc->extract_failed = true; + return; + } + wlc->cb (wlc->cb_cls, + webhook_serial, + event_type, + url, + http_method, + header_template, + body_template); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_webhooks_by_event ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *event_type, + TALER_MERCHANTDB_WebhookDetailCallback cb, + void *cb_cls) +{ + struct LookupWebhookDetailContext wlc = { + .cb = cb, + .cb_cls = cb_cls, + .extract_failed = false, + }; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (event_type), + 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" + " webhook_serial" + ",event_type" + ",url" + ",http_method" + ",header_template" + ",body_template" + " FROM merchant_webhook" + " WHERE event_type=$1"); + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "", + params, + &lookup_webhook_by_event_cb, + &wlc); + + if (wlc.extract_failed) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/iterate_wirewatch_accounts.c b/src/backenddb/iterate_wirewatch_accounts.c @@ -0,0 +1,139 @@ +/* + This file is part of TALER + Copyright (C) 2022, 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_wirewatch_accounts.c + * @brief Implementation of the iterate_wirewatch_accounts function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_pq_lib.h> +#include "merchant-database/iterate_wirewatch_accounts.h" +#include "helper.h" + + +/** + * Closure for #handle_results(). + */ +struct Context +{ + /** + * Function to call with results. + */ + TALER_MERCHANTDB_WirewatchWorkCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Set to true if the parsing failed. + */ + bool failure; +}; + + +/** + * 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 Context *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +handle_results (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct Context *ctx = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + char *instance; + struct TALER_FullPayto payto_uri; + char *facade_url; + json_t *credential = NULL; + uint64_t last_serial; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("out_merchant_id", + &instance), + GNUNET_PQ_result_spec_string ("out_payto_uri", + &payto_uri.full_payto), + GNUNET_PQ_result_spec_string ("out_credit_facade_url", + &facade_url), + GNUNET_PQ_result_spec_allow_null ( + TALER_PQ_result_spec_json ("out_credit_facade_credentials", + &credential), + NULL), + GNUNET_PQ_result_spec_uint64 ("out_last_bank_serial", + &last_serial), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->failure = true; + return; + } + ctx->cb (ctx->cb_cls, + instance, + payto_uri, + facade_url, + credential, + last_serial); + GNUNET_PQ_cleanup_result (rs); + } +} + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_wirewatch_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_WirewatchWorkCallback cb, + void *cb_cls) +{ + struct Context ctx = { + .cb = cb, + .cb_cls = cb_cls + }; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "select_wirewatch_accounts", + "SELECT" + " out_last_bank_serial" + " ,out_merchant_id" + " ,out_payto_uri" + " ,out_credit_facade_url" + " ,out_credit_facade_credentials::TEXT" + " FROM merchant.select_wirewatch_accounts()"); + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "select_wirewatch_accounts", + params, + &handle_results, + &ctx); + if (ctx.failure) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} diff --git a/src/backenddb/select_wirewatch_accounts.sql b/src/backenddb/iterate_wirewatch_accounts.sql diff --git a/src/backenddb/lookup_account.c b/src/backenddb/lookup_account.c @@ -1,57 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_account.c - * @brief Implementation of the lookup_account function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_account.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_account ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - uint64_t *account_serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_uri.full_payto), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("account_serial", - account_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" - " account_serial" - " FROM merchant_accounts" - " WHERE REGEXP_REPLACE(payto_uri,'\\?.*','')" - " =REGEXP_REPLACE($1,'\\?.*','')"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_all_products.c b/src/backenddb/lookup_all_products.c @@ -1,227 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024, 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_all_products.c - * @brief Implementation of the lookup_all_products function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_all_products.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_all_products(). - */ -struct LookupProductsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ProductCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Postgres context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * 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 products. - * - * @param[in,out] cls of type `struct LookupProductsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_products_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupProductsContext *plc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - char *product_id; - uint64_t product_serial; - struct TALER_MERCHANTDB_ProductDetails pd; - size_t num_categories; - uint64_t *categories; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("product_id", - &product_id), - GNUNET_PQ_result_spec_uint64 ("product_serial", - &product_serial), - GNUNET_PQ_result_spec_string ("product_name", - &pd.product_name), - GNUNET_PQ_result_spec_string ("description", - &pd.description), - TALER_PQ_result_spec_json ("description_i18n", - &pd.description_i18n), - GNUNET_PQ_result_spec_string ("unit", - &pd.unit), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "price_array", - &pd.price_array_length, - &pd.price_array), - TALER_PQ_result_spec_json ("taxes", - &pd.taxes), - GNUNET_PQ_result_spec_uint64 ("total_stock", - &pd.total_stock), - GNUNET_PQ_result_spec_uint32 ("total_stock_frac", - &pd.total_stock_frac), - GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", - &pd.allow_fractional_quantity), - GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", - &pd.fractional_precision_level), - GNUNET_PQ_result_spec_uint64 ("total_sold", - &pd.total_sold), - GNUNET_PQ_result_spec_uint32 ("total_sold_frac", - &pd.total_sold_frac), - GNUNET_PQ_result_spec_uint64 ("total_lost", - &pd.total_lost), - GNUNET_PQ_result_spec_uint32 ("total_lost_frac", - &pd.total_lost_frac), - GNUNET_PQ_result_spec_string ("image", - &pd.image), - TALER_PQ_result_spec_json ("address", - &pd.address), - GNUNET_PQ_result_spec_timestamp ("next_restock", - &pd.next_restock), - GNUNET_PQ_result_spec_uint32 ("minimum_age", - &pd.minimum_age), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "categories", - &num_categories, - &categories), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("product_group_serial", - &pd.product_group_id), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("money_pot_serial", - &pd.money_pot_id), - NULL), - GNUNET_PQ_result_spec_bool ("price_is_net", - &pd.price_is_net), - GNUNET_PQ_result_spec_end - }; - - pd.product_group_id = 0; - pd.money_pot_id = 0; - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - plc->extract_failed = true; - return; - } - pd.image_hash = NULL; - plc->cb (plc->cb_cls, - product_serial, - product_id, - &pd, - num_categories, - categories); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_all_products ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_ProductCallback cb, - void *cb_cls) -{ - struct LookupProductsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - /* Can be overwritten by the lookup_products_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - ",description_i18n::TEXT" - ",product_name" - ",unit" - ",price_array" - ",taxes::TEXT" - ",total_stock" - ",total_stock_frac" - ",allow_fractional_quantity" - ",fractional_precision_level" - ",total_sold" - ",total_sold_frac" - ",total_lost" - ",total_lost_frac" - ",image" - ",minv.address::TEXT" - ",next_restock" - ",minimum_age" - ",product_id" - ",product_serial" - ",t.category_array AS categories" - ",product_group_serial" - ",money_pot_serial" - ",price_is_net" - " FROM merchant_inventory minv" - ",LATERAL (" - " SELECT ARRAY (" - " SELECT mpc.category_serial" - " FROM merchant_product_categories mpc" - " WHERE mpc.product_serial = minv.product_serial" - " ) AS category_array" - " ) t"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_products_cb, - &plc); - /* If there was an error inside lookup_products_cb, return a hard error. */ - if (plc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_all_webhooks.c b/src/backenddb/lookup_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/lookup_all_webhooks.c - * @brief Implementation of the lookup_all_webhooks function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_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_lookup_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/lookup_categories.c b/src/backenddb/lookup_categories.c @@ -1,143 +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/lookup_categories.c - * @brief Implementation of the lookup_categories function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_categories.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_categories(). - */ -struct LookupCategoryContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CategoriesCallback 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 otp_device. - * - * @param[in,out] cls of type `struct LookupCategoryContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_categories_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCategoryContext *tlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t category_id; - char *category_name; - json_t *category_name_i18n; - uint64_t product_count; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("category_serial", - &category_id), - GNUNET_PQ_result_spec_string ("category_name", - &category_name), - TALER_PQ_result_spec_json ("category_name_i18n", - &category_name_i18n), - GNUNET_PQ_result_spec_uint64 ("product_count", - &product_count), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tlc->extract_failed = true; - return; - } - tlc->cb (tlc->cb_cls, - category_id, - category_name, - category_name_i18n, - product_count); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_categories ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_CategoriesCallback cb, - void *cb_cls) -{ - struct LookupCategoryContext tlc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_categories_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - " mc.category_serial" - ",mc.category_name" - ",mc.category_name_i18n::TEXT" - ",COALESCE(COUNT(mpc.product_serial),0)" - " AS product_count" - " FROM merchant_categories mc" - " LEFT JOIN merchant_product_categories mpc" - " USING (category_serial)" - " GROUP BY mc.category_serial" - " ORDER BY mc.category_serial;"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_categories_cb, - &tlc); - /* If there was an error inside lookup_categories_cb, return a hard error. */ - if (tlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_categories_by_ids.c b/src/backenddb/lookup_categories_by_ids.c @@ -1,140 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_categories_by_ids.c - * @brief Lookup product categories by ID - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_categories_by_ids.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_categories_by_ids(). - */ -struct LookupCategoryContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CategoriesCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; -}; - - -static void -lookup_categories_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCategoryContext *tlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t category_id; - char *category_name; - json_t *category_name_i18n; - uint64_t product_count; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("category_serial", - &category_id), - GNUNET_PQ_result_spec_string ("category_name", - &category_name), - TALER_PQ_result_spec_json ("category_name_i18n", - &category_name_i18n), - GNUNET_PQ_result_spec_uint64 ("product_count", - &product_count), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tlc->extract_failed = true; - return; - } - tlc->cb (tlc->cb_cls, - category_id, - category_name, - category_name_i18n, - product_count); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_categories_by_ids (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const uint64_t *category_ids, - size_t num_category_ids, - TALER_MERCHANTDB_CategoriesCallback cb, - void *cb_cls) -{ - struct LookupCategoryContext tlc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_categories_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_array_uint64 (num_category_ids, - category_ids, - pg->conn), - 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" - " mc.category_serial" - ",mc.category_name" - ",mc.category_name_i18n::TEXT" - ",COALESCE(COUNT(mpc.product_serial),0)" - " AS product_count" - " FROM merchant_categories mc" - " LEFT JOIN merchant_product_categories mpc" - " USING (category_serial)" - " WHERE mc.category_serial = ANY ($1)" - " GROUP BY mc.category_serial" - " ORDER BY mc.category_serial;"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_categories_cb, - &tlc); - GNUNET_PQ_cleanup_query_params_closures (params); - if (tlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_contract_terms.c b/src/backenddb/lookup_contract_terms.c @@ -1,73 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-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/lookup_contract_terms.c - * @brief Implementation of the lookup_contract_terms function for Postgres - * @author Iván Ávalos - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_contract_terms.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - struct TALER_ClaimTokenP *claim_token) -{ - enum GNUNET_DB_QueryStatus qs; - struct TALER_ClaimTokenP ct; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - /* contract_terms must be first! */ - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",order_serial" - ",claim_token" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - (NULL != contract_terms) - ? rs - : &rs[1]); - if (NULL != claim_token) - *claim_token = ct; - return qs; -} diff --git a/src/backenddb/lookup_contract_terms_pos.c b/src/backenddb/lookup_contract_terms_pos.c @@ -1,90 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_contract_terms_pos.c - * @brief Implementation of the lookup_contract_terms_pos function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_contract_terms_pos.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms_pos ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - struct TALER_ClaimTokenP *claim_token, - char **pos_key, - enum TALER_MerchantConfirmationAlgorithm *pos_algorithm) -{ - enum GNUNET_DB_QueryStatus qs; - struct TALER_ClaimTokenP ct; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - uint32_t pos32 = TALER_MCA_NONE; - struct GNUNET_PQ_ResultSpec rs[] = { - /* contract_terms must be first! */ - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_bool ("paid", - paid), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("pos_key", - pos_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("pos_algorithm", - &pos32), - NULL), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",order_serial" - ",claim_token" - ",paid" - ",pos_key" - ",pos_algorithm" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - (NULL != contract_terms) - ? rs - : &rs[1]); - *pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos32; - if (NULL != claim_token) - *claim_token = ct; - return qs; -} diff --git a/src/backenddb/lookup_contract_terms_status.c b/src/backenddb/lookup_contract_terms_status.c @@ -1,102 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_contract_terms_status.c - * @brief Implementation of the lookup_contract_terms_status function for Postgres - * @author Iván Ávalos - * @author Christian Grothoff - */ -#include "platform.h" -#include <sys/types.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_contract_terms_status.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms_status ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - const char *session_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - bool *wired, - bool *session_matches, - struct TALER_ClaimTokenP *claim_token, - int16_t *choice_index) -{ - enum GNUNET_DB_QueryStatus qs; - struct TALER_ClaimTokenP ct; - uint16_t ci = 0; - bool choice_index_null = false; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - NULL == session_id - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (session_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - /* contract_terms must be first! */ - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_bool ("paid", - paid), - GNUNET_PQ_result_spec_bool ("wired", - wired), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_bool ("session_matches", - session_matches), - NULL), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint16 ("choice_index", - &ci), - &choice_index_null), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - *session_matches = false; - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",order_serial" - ",claim_token" - ",paid" - ",wired" - ",(session_id=$2) AS session_matches" - ",choice_index" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - (NULL != contract_terms) - ? rs - : &rs[1]); - if (NULL != claim_token) - *claim_token = ct; - *choice_index = (choice_index_null) ? -1 : (int16_t) ci; - return qs; -} diff --git a/src/backenddb/lookup_custom_units_by_names.c b/src/backenddb/lookup_custom_units_by_names.c @@ -1,139 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_custom_units_by_names.c - * @brief Lookup custom measurement units by name - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_custom_units_by_names.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_custom_units_by_names(). - */ -struct LookupUnitsContext -{ - TALER_MERCHANTDB_UnitsCallback cb; - void *cb_cls; - bool extract_failed; -}; - - -static void -lookup_units_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupUnitsContext *luc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_MERCHANTDB_UnitDetails ud = { 0 }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("unit_serial", - &ud.unit_serial), - GNUNET_PQ_result_spec_string ("unit", - &ud.unit), - GNUNET_PQ_result_spec_string ("unit_name_long", - &ud.unit_name_long), - GNUNET_PQ_result_spec_string ("unit_name_short", - &ud.unit_name_short), - TALER_PQ_result_spec_json ("unit_name_long_i18n", - &ud.unit_name_long_i18n), - TALER_PQ_result_spec_json ("unit_name_short_i18n", - &ud.unit_name_short_i18n), - GNUNET_PQ_result_spec_bool ("unit_allow_fraction", - &ud.unit_allow_fraction), - GNUNET_PQ_result_spec_uint32 ("unit_precision_level", - &ud.unit_precision_level), - GNUNET_PQ_result_spec_bool ("unit_active", - &ud.unit_active), - GNUNET_PQ_result_spec_bool ("unit_builtin", - &ud.unit_builtin), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - luc->extract_failed = true; - return; - } - luc->cb (luc->cb_cls, - ud.unit_serial, - &ud); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_custom_units_by_names ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *const *units, - size_t num_units, - TALER_MERCHANTDB_UnitsCallback cb, - void *cb_cls) -{ - struct LookupUnitsContext luc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_array_ptrs_string (num_units, - (const char **) units, - pg->conn), - 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 cu.unit_serial" - " ,cu.unit" - " ,cu.unit_name_long" - " ,cu.unit_name_short" - " ,cu.unit_name_long_i18n" - " ,cu.unit_name_short_i18n" - " ,cu.unit_allow_fraction" - " ,cu.unit_precision_level" - " ,cu.unit_active" - " ,FALSE AS unit_builtin" - " FROM merchant_custom_units cu" - " WHERE cu.unit = ANY ($1)" - " ORDER BY cu.unit"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_units_cb, - &luc); - GNUNET_PQ_cleanup_query_params_closures (params); - if (luc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_deposits.c b/src/backenddb/lookup_deposits.c @@ -1,163 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_deposits.c - * @brief Implementation of the lookup_deposits function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_deposits.h" -#include "helper.h" - -/** - * Closure for #lookup_deposits_cb(). - */ -struct LookupDepositsContext -{ - /** - * Function to call with results. - */ - TALER_MERCHANTDB_DepositsCallback cb; - - /** - * Closure for @e cls. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Transaction status (set). - */ - enum GNUNET_DB_QueryStatus qs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param[in,out] cls of type `struct LookupDepositsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_deposits_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupDepositsContext *ldc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_CoinSpendPublicKeyP coin_pub; - struct TALER_Amount amount_with_fee; - struct TALER_Amount deposit_fee; - struct TALER_Amount refund_fee; - struct TALER_Amount wire_fee; - char *exchange_url; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), - TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", - &amount_with_fee), - TALER_PQ_result_spec_amount_with_currency ("deposit_fee", - &deposit_fee), - TALER_PQ_result_spec_amount_with_currency ("refund_fee", - &refund_fee), - TALER_PQ_result_spec_amount_with_currency ("wire_fee", - &wire_fee), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ldc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ldc->cb (ldc->cb_cls, - exchange_url, - &coin_pub, - &amount_with_fee, - &deposit_fee, - &refund_fee, - &wire_fee); - GNUNET_PQ_cleanup_result (rs); - } - ldc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - TALER_MERCHANTDB_DepositsCallback cb, - void *cb_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_end - }; - struct LookupDepositsContext ldc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - /* no preflight check here, run in its own transaction by the caller! */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finding deposits for h_contract_terms '%s'\n", - GNUNET_h2s (&h_contract_terms->hash)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " dcom.exchange_url" - ",dcom.wire_fee" - ",dep.coin_pub" - ",dep.amount_with_fee" - ",dep.deposit_fee" - ",dep.refund_fee" - " FROM merchant_deposits dep" - " JOIN merchant_deposit_confirmations dcom" - " USING (deposit_confirmation_serial)" - " WHERE dcom.order_serial=" - " (SELECT order_serial" - " FROM merchant_contract_terms" - " WHERE h_contract_terms=$1)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_deposits_cb, - &ldc); - if (qs <= 0) - return qs; - return ldc.qs; -} diff --git a/src/backenddb/lookup_deposits_by_contract_and_coin.c b/src/backenddb/lookup_deposits_by_contract_and_coin.c @@ -1,318 +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/lookup_deposits_by_contract_and_coin.c - * @brief Implementation of the lookup_deposits_by_contract_and_coin function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_deposits_by_contract_and_coin.h" -#include "helper.h" - -/** - * Closure for #lookup_deposits_by_contract_and_coin_cb(). - */ -struct LookupDepositsByCnCContext -{ - /** - * Function to call for each deposit. - */ - TALER_MERCHANTDB_CoinDepositCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Total amount refunded on this coin and contract. - */ - struct TALER_Amount refund_total; - - /** - * 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 LookupDepositsByCnCContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_refunds_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupDepositsByCnCContext *ldcc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_Amount refund_amount; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount_with_currency ("refund_amount", - &refund_amount), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Coin had refund of %s\n", - TALER_amount2s (&refund_amount)); - if (0 == i) - ldcc->refund_total = refund_amount; - else - GNUNET_assert (0 <= - TALER_amount_add (&ldcc->refund_total, - &ldcc->refund_total, - &refund_amount)); - GNUNET_PQ_cleanup_result (rs); /* technically useless here */ - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls of type `struct LookupDepositsByCnCContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_deposits_by_contract_and_coin_cb ( - void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupDepositsByCnCContext *ldcc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - char *exchange_url; - struct TALER_Amount amount_with_fee; - struct TALER_Amount deposit_fee; - struct TALER_Amount refund_fee; - struct TALER_Amount wire_fee; - struct TALER_MerchantWireHashP h_wire; - struct GNUNET_TIME_Timestamp deposit_timestamp; - struct GNUNET_TIME_Timestamp refund_deadline; - struct TALER_ExchangeSignatureP exchange_sig; - struct TALER_ExchangePublicKeyP exchange_pub; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", - &amount_with_fee), - TALER_PQ_result_spec_amount_with_currency ("deposit_fee", - &deposit_fee), - TALER_PQ_result_spec_amount_with_currency ("refund_fee", - &refund_fee), - TALER_PQ_result_spec_amount_with_currency ("wire_fee", - &wire_fee), - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &h_wire), - GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", - &deposit_timestamp), - GNUNET_PQ_result_spec_timestamp ("refund_deadline", - &refund_deadline), - GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", - &exchange_sig), - GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", - &exchange_pub), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Coin original deposit value is %s\n", - TALER_amount2s (&amount_with_fee)); - if (TALER_amount_is_valid (&ldcc->refund_total)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Coin had total refunds of %s\n", - TALER_amount2s (&ldcc->refund_total)); - if (1 == - TALER_amount_cmp (&ldcc->refund_total, - &amount_with_fee)) - { - /* Refunds exceeded total deposit? not OK! */ - GNUNET_break (0); - ldcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - if (0 == - TALER_amount_cmp (&ldcc->refund_total, - &amount_with_fee)) - { - /* refund_total == amount_with_fee; - in this case, the total contributed to the - wire transfer is zero (as are fees) */ - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (ldcc->refund_total.currency, - &amount_with_fee)); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (ldcc->refund_total.currency, - &deposit_fee)); - - } - else - { - /* Compute deposit value by subtracting refunds */ - GNUNET_assert (0 < - TALER_amount_subtract (&amount_with_fee, - &amount_with_fee, - &ldcc->refund_total)); - if (-1 == - TALER_amount_cmp (&amount_with_fee, - &deposit_fee)) - { - /* amount_with_fee < deposit_fee, so after refunds less than - the deposit fee remains; reduce deposit fee to - the remaining value of the coin */ - deposit_fee = amount_with_fee; - } - } - } - ldcc->cb (ldcc->cb_cls, - exchange_url, - &amount_with_fee, - &deposit_fee, - &refund_fee, - &wire_fee, - &h_wire, - deposit_timestamp, - refund_deadline, - &exchange_sig, - &exchange_pub); - GNUNET_PQ_cleanup_result (rs); - } - ldcc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits_by_contract_and_coin ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP * - h_contract_terms, - const struct TALER_CoinSpendPublicKeyP * - coin_pub, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (coin_pub), - GNUNET_PQ_query_param_end - }; - struct LookupDepositsByCnCContext ldcc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - 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! */ - TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n", - GNUNET_h2s (&h_contract_terms->hash), - instance_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " refund_amount" - " FROM merchant_refunds" - /* Join to filter by refunds that actually - did work, not only those we approved */ - " JOIN merchant_refund_proofs" - " USING (refund_serial)" - " WHERE coin_pub=$2" - " AND order_serial=" - " (SELECT order_serial" - " FROM merchant_contract_terms" - " WHERE h_contract_terms=$1)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_refunds_cb, - &ldcc); - if (0 > qs) - return qs; - - TMH_PQ_prepare_anon (pg, - "SELECT" - " mcon.exchange_url" - ",dep.amount_with_fee" - ",dep.deposit_fee" - ",dep.refund_fee" - ",mcon.wire_fee" - ",acc.h_wire" - ",mcon.deposit_timestamp" - ",mct.refund_deadline" - ",mcon.exchange_sig" - ",msig.exchange_pub" - " FROM merchant_contract_terms mct" - " JOIN merchant_deposit_confirmations mcon" - " USING (order_serial)" - " JOIN merchant_deposits dep" - " USING (deposit_confirmation_serial)" - " JOIN merchant.merchant_exchange_signing_keys msig" - " ON (mcon.signkey_serial=msig.signkey_serial)" - " JOIN merchant_accounts acc" - " USING (account_serial)" - " WHERE h_contract_terms=$1" - " AND dep.coin_pub=$2"); - - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_deposits_by_contract_and_coin_cb, - &ldcc); - if (0 >= qs) - return qs; - return ldcc.qs; -} diff --git a/src/backenddb/lookup_deposits_by_order.c b/src/backenddb/lookup_deposits_by_order.c @@ -1,161 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 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/lookup_deposits_by_order.c - * @brief Implementation of the lookup_deposits_by_order function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_deposits_by_order.h" -#include "helper.h" - -/** - * Closure for lookup_deposits_by_order_cb(). - */ -struct LookupDepositsByOrderContext -{ - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with all results. - */ - TALER_MERCHANTDB_DepositedCoinsCallback 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 closure of type `struct LookupDepositsByOrderContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_deposits_by_order_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupDepositsByOrderContext *ldoc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - uint64_t deposit_serial; - char *exchange_url; - struct TALER_MerchantWireHashP h_wire; - struct TALER_CoinSpendPublicKeyP coin_pub; - struct GNUNET_TIME_Timestamp deposit_timestamp; - struct TALER_Amount amount_with_fee; - struct TALER_Amount deposit_fee; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("deposit_serial", - &deposit_serial), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", - &deposit_timestamp), - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &h_wire), - TALER_PQ_result_spec_amount_with_currency ("amount_with_fee", - &amount_with_fee), - TALER_PQ_result_spec_amount_with_currency ("deposit_fee", - &deposit_fee), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ldoc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ldoc->cb (ldoc->cb_cls, - deposit_serial, - exchange_url, - &h_wire, - deposit_timestamp, - &amount_with_fee, - &deposit_fee, - &coin_pub); - GNUNET_PQ_cleanup_result (rs); /* technically useless here */ - } - ldoc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits_by_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_DepositedCoinsCallback cb, - void *cb_cls) -{ - struct LookupDepositsByOrderContext ldoc = { - .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" - " dep.deposit_serial" - ",mcon.exchange_url" - ",acc.h_wire" - ",mcon.deposit_timestamp" - ",dep.amount_with_fee" - ",dep.deposit_fee" - ",dep.coin_pub" - " FROM merchant_deposits dep" - " JOIN merchant_deposit_confirmations mcon" - " USING(deposit_confirmation_serial)" - " JOIN merchant_accounts acc" - " USING (account_serial)" - " WHERE mcon.order_serial=$1"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_deposits_by_order_cb, - &ldoc); - if (qs < 0) - return qs; - return ldoc.qs; -} diff --git a/src/backenddb/lookup_donau_keys.c b/src/backenddb/lookup_donau_keys.c @@ -1,71 +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/lookup_donau_keys.c - * @brief Implementation of the lookup_donau_keys function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "donau/donau_service.h" -#include "merchant-database/lookup_donau_keys.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_donau_keys ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *donau_url, - struct GNUNET_TIME_Absolute *first_retry, - struct DONAU_Keys **keys) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (donau_url), - GNUNET_PQ_query_param_end - }; - json_t *jkeys; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_absolute_time ("first_retry", - first_retry), - TALER_PQ_result_spec_json ("keys_json", - &jkeys), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_donau_keys", - "SELECT" - " first_retry" - ",keys_json::TEXT" - " FROM merchant_donau_keys" - " WHERE donau_url=$1;"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_donau_keys", - params, - rs); - if (qs <= 0) - return qs; - *keys = DONAU_keys_from_json (jkeys); - json_decref (jkeys); - if (NULL == *keys) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/lookup_expected_transfer.c b/src/backenddb/lookup_expected_transfer.c @@ -1,98 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_expected_transfer.c - * @brief Implementation of the lookup_expected_transfer function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_expected_transfer.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_expected_transfer ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t expected_incoming_serial, - struct GNUNET_TIME_Timestamp *expected_time, - struct TALER_Amount *expected_credit_amount, - struct TALER_WireTransferIdentifierRawP *wtid, - struct TALER_FullPayto *payto_uri, - char **exchange_url, - struct GNUNET_TIME_Timestamp *execution_time, - bool *confirmed, - struct TALER_MasterPublicKeyP *master_pub) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("expected_time", - expected_time), - GNUNET_PQ_result_spec_bool ("confirmed", - confirmed), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", - expected_credit_amount), - NULL), - GNUNET_PQ_result_spec_string ("exchange_url", - exchange_url), - GNUNET_PQ_result_spec_auto_from_type ("wtid", - wtid), - GNUNET_PQ_result_spec_string ("payto_uri", - &payto_uri->full_payto), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("execution_time", - execution_time), - NULL), - GNUNET_PQ_result_spec_auto_from_type ("master_pub", - master_pub), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - *execution_time = GNUNET_TIME_UNIT_ZERO_TS; - memset (expected_credit_amount, - 0, - sizeof (*expected_credit_amount)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " met.expected_time" - " ,met.confirmed" - " ,met.expected_credit_amount" - " ,met.exchange_url" - " ,met.wtid" - " ,ma.payto_uri" - " ,mts.execution_time" - " ,esk.master_pub" - " FROM merchant_expected_transfers met" - " JOIN merchant.merchant_exchange_signing_keys esk" - " USING (signkey_serial)" - " JOIN merchant_accounts ma" - " USING (account_serial)" - " LEFT JOIN merchant_transfer_signatures mts" - " USING (expected_credit_serial)" - " WHERE met.expected_credit_serial=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_expected_transfers.c b/src/backenddb/lookup_expected_transfers.c @@ -1,272 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_expected_transfers.c - * @brief Implementation of the lookup_expected_transfers function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_expected_transfers.h" -#include "helper.h" -#include <microhttpd.h> /* for HTTP status codes */ - -/** - * Closure for #lookup_expected_transfers_cb(). - */ -struct LookupExpectedTransfersContext -{ - /** - * Function to call on results. - */ - TALER_MERCHANTDB_IncomingCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Postgres context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Transaction status (set). - */ - 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 LookupExpectedTransfersContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_expected_transfers_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupExpectedTransfersContext *ltc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_Amount expected_credit_amount; - struct TALER_WireTransferIdentifierRawP wtid; - struct TALER_FullPayto payto_uri; - char *exchange_url; - uint64_t expected_transfer_serial_id; - struct GNUNET_TIME_Timestamp execution_time - = GNUNET_TIME_UNIT_ZERO_TS; - bool confirmed; - bool validated; - bool no_amount; - char *last_detail = NULL; - uint32_t last_http_status = 0; - uint32_t last_ec = TALER_EC_NONE; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_amount_with_currency ("expected_credit_amount", - &expected_credit_amount), - &no_amount), - GNUNET_PQ_result_spec_auto_from_type ("wtid", - &wtid), - GNUNET_PQ_result_spec_string ("payto_uri", - &payto_uri.full_payto), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", - &expected_transfer_serial_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("execution_time", - &execution_time), - NULL), - GNUNET_PQ_result_spec_bool ("confirmed", - &confirmed), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("last_http_status", - &last_http_status), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("last_ec", - &last_ec), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("last_detail", - &last_detail), - NULL), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ltc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - validated = ( (MHD_HTTP_OK == last_http_status) && - (TALER_EC_NONE == last_ec) ); - ltc->cb (ltc->cb_cls, - no_amount - ? NULL - : &expected_credit_amount, - &wtid, - payto_uri, - exchange_url, - expected_transfer_serial_id, - execution_time, - confirmed, - validated, - last_http_status, - last_ec, - last_detail); - GNUNET_PQ_cleanup_result (rs); - } - ltc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_expected_transfers ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - struct GNUNET_TIME_Timestamp before, - struct GNUNET_TIME_Timestamp after, - int64_t limit, - uint64_t offset, - enum TALER_EXCHANGE_YesNoAll confirmed, - enum TALER_EXCHANGE_YesNoAll verified, - TALER_MERCHANTDB_IncomingCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - bool by_time = ( (! GNUNET_TIME_absolute_is_never (before.abs_time)) || - (! GNUNET_TIME_absolute_is_zero (after.abs_time)) ); - struct LookupExpectedTransfersContext ltc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&before), - GNUNET_PQ_query_param_timestamp (&after), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - NULL == payto_uri.full_payto - ? GNUNET_PQ_query_param_null () /* NULL: do not filter by payto URI */ - : GNUNET_PQ_query_param_string (payto_uri.full_payto), - GNUNET_PQ_query_param_bool (! by_time), /* $6: filter by time? */ - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == confirmed), /* filter by confirmed? */ - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == confirmed), - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == verified), /* filter by verified? */ - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == verified), - - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " met.expected_credit_amount" - ",met.wtid" - ",mac.payto_uri" - ",met.exchange_url" - ",met.expected_credit_serial" - ",mts.execution_time" - ",met.confirmed" - ",met.last_http_status" - ",met.last_ec" - ",met.last_detail" - " FROM merchant_expected_transfers met" - " JOIN merchant_accounts mac" - " USING (account_serial)" - " LEFT JOIN merchant_transfer_signatures mts" - " USING (expected_credit_serial)" - " WHERE ( $6 OR " - " (mts.execution_time IS NOT NULL AND" - " mts.execution_time < $1 AND" - " mts.execution_time >= $2) )" - " AND ( (CAST($5 AS TEXT) IS NULL) OR " - " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" - " =REGEXP_REPLACE($5,'\\?.*','')) )" - " AND ( $7 OR " - " (met.confirmed = $8) )" - " AND ( $9 OR " - " ($10 = (200=met.last_http_status) AND" - " (0=met.last_ec) ) )" - " AND (met.expected_credit_serial > $3)" - " ORDER BY met.expected_credit_serial ASC" - " LIMIT $4"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " met.expected_credit_amount" - ",met.wtid" - ",mac.payto_uri" - ",met.exchange_url" - ",met.expected_credit_serial" - ",mts.execution_time" - ",met.confirmed" - ",met.last_http_status" - ",met.last_ec" - ",met.last_detail" - " FROM merchant_expected_transfers met" - " JOIN merchant_accounts mac" - " USING (account_serial)" - " LEFT JOIN merchant_transfer_signatures mts" - " USING (expected_credit_serial)" - " WHERE ( $6 OR " - " (mts.execution_time IS NOT NULL AND" - " mts.execution_time < $1 AND" - " mts.execution_time >= $2) )" - " AND ( (CAST($5 AS TEXT) IS NULL) OR " - " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" - " =REGEXP_REPLACE($5,'\\?.*','')) )" - " AND ( $7 OR " - " (met.confirmed = $8) )" - " AND ( $9 OR " - " ($10 = (200=met.last_http_status) AND" - " (0=met.last_ec) ) )" - " AND (met.expected_credit_serial < $3)" - " ORDER BY met.expected_credit_serial DESC" - " LIMIT $4"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_expected_transfers_cb, - &ltc); - if (0 >= qs) - return qs; - return ltc.qs; -} diff --git a/src/backenddb/lookup_instance_auth.c b/src/backenddb/lookup_instance_auth.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/lookup_instance_auth.c - * @brief Implementation of the lookup_instance_auth function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_instance_auth.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instance_auth ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_MERCHANTDB_InstanceAuthSettings *ias) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("auth_hash", - &ias->auth_hash), - GNUNET_PQ_result_spec_auto_from_type ("auth_salt", - &ias->auth_salt), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "lookup_instance_auth", - "SELECT" - " auth_hash" - ",auth_salt" - " FROM merchant.merchant_instances" - " WHERE merchant_id=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_instance_auth", - params, - rs); -} diff --git a/src/backenddb/lookup_instances.c b/src/backenddb/lookup_instances.c @@ -1,283 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022--2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_instances.c - * @brief Implementation of the lookup_instances function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_instances.h" -#include "helper.h" - - -/** - * Context for lookup_instances(). - */ -struct LookupInstancesContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_InstanceCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Database context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Set to the return value on errors. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about instances. - * - * @param cls of type `struct LookupInstancesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_instances_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupInstancesContext *lic = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_MERCHANTDB_InstanceSettings is; - struct TALER_MERCHANTDB_InstanceAuthSettings ias; - uint64_t instance_serial; - struct TALER_MerchantPublicKeyP merchant_pub; - struct TALER_MerchantPrivateKeyP merchant_priv; - bool no_auth; - bool no_salt; - bool no_priv; - char *dwtri; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("merchant_serial", - &instance_serial), - GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", - &merchant_pub), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("auth_hash", - &ias.auth_hash), - &no_auth), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("auth_salt", - &ias.auth_salt), - &no_salt), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("merchant_priv", - &merchant_priv), - &no_priv), - GNUNET_PQ_result_spec_string ("merchant_id", - &is.id), - GNUNET_PQ_result_spec_string ("merchant_name", - &is.name), - TALER_PQ_result_spec_json ("address", - &is.address), - TALER_PQ_result_spec_json ("jurisdiction", - &is.jurisdiction), - GNUNET_PQ_result_spec_bool ("use_stefan", - &is.use_stefan), - GNUNET_PQ_result_spec_bool ("phone_validated", - &is.phone_validated), - GNUNET_PQ_result_spec_bool ("email_validated", - &is.email_validated), - GNUNET_PQ_result_spec_relative_time ( - "default_wire_transfer_delay", - &is.default_wire_transfer_delay), - GNUNET_PQ_result_spec_relative_time ("default_pay_delay", - &is.default_pay_delay), - GNUNET_PQ_result_spec_relative_time ("default_refund_delay", - &is.default_refund_delay), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("website", - &is.website), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("email", - &is.email), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("phone_number", - &is.phone), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("logo", - &is.logo), - NULL), - GNUNET_PQ_result_spec_string ( - "default_wire_transfer_rounding_interval", - &dwtri), - GNUNET_PQ_result_spec_end - }; - - memset (&ias.auth_salt, - 0, - sizeof (ias.auth_salt)); - memset (&ias.auth_hash, - 0, - sizeof (ias.auth_hash)); - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - if (GNUNET_OK != - GNUNET_TIME_string_to_round_interval ( - dwtri, - &is.default_wire_transfer_rounding_interval)) - { - GNUNET_break (0); - lic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - lic->cb (lic->cb_cls, - &merchant_pub, - (no_priv) ? NULL : &merchant_priv, - &is, - &ias); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instances ( - struct TALER_MERCHANTDB_PostgresContext *pg, - bool active_only, - TALER_MERCHANTDB_InstanceCallback cb, - void *cb_cls) -{ - struct LookupInstancesContext lic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_bool (active_only), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_instances", - "SELECT" - " merchant_serial" - " ,merchant_pub" - " ,auth_hash" - " ,auth_salt" - " ,merchant_priv" - " ,merchant_id" - " ,merchant_name" - " ,address::TEXT" - " ,jurisdiction::TEXT" - " ,use_stefan" - " ,phone_validated" - " ,email_validated" - " ,default_wire_transfer_delay" - " ,default_pay_delay" - " ,default_refund_delay" - " ,website" - " ,email" - " ,phone_number" - " ,logo" - " ,default_wire_transfer_rounding_interval::TEXT" - " FROM merchant.merchant_instances" - " WHERE (NOT $1 OR merchant_priv IS NOT NULL)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_instances", - params, - &lookup_instances_cb, - &lic); - if (0 > lic.qs) - return lic.qs; - return qs; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instances_by_id ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - bool active_only, - TALER_MERCHANTDB_InstanceCallback cb, - void *cb_cls) -{ - struct LookupInstancesContext lic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_bool (active_only), - GNUNET_PQ_query_param_string (id), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_instances_by_id", - "SELECT" - " merchant_serial" - " ,merchant_pub" - " ,auth_hash" - " ,auth_salt" - " ,merchant_priv" - " ,merchant_id" - " ,merchant_name" - " ,address::TEXT" - " ,jurisdiction::TEXT" - " ,use_stefan" - " ,phone_validated" - " ,email_validated" - " ,default_wire_transfer_delay" - " ,default_pay_delay" - " ,default_refund_delay" - " ,website" - " ,email" - " ,phone_number" - " ,logo" - " ,default_wire_transfer_rounding_interval::TEXT" - " FROM merchant.merchant_instances" - " WHERE (merchant_id = $2)" - " AND (NOT $1 OR merchant_priv IS NOT NULL)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_instances_by_id", - params, - &lookup_instances_cb, - &lic); - if (0 > lic.qs) - return lic.qs; - return qs; -} diff --git a/src/backenddb/lookup_inventory_products.c b/src/backenddb/lookup_inventory_products.c @@ -1,219 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_inventory_products.c - * @brief Implementation of the lookup_inventory_products function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_inventory_products.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_inventory_products(). - */ -struct LookupInventoryProductsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_InventoryProductCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Postgres context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * 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 products. - * - * @param[in,out] cls of type `struct LookupInventoryProductsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_inventory_products_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupInventoryProductsContext *plc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - char *product_id; - struct TALER_MERCHANTDB_InventoryProductDetails pd; - size_t num_categories; - uint64_t *categories; - bool no_image_hash; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("product_id", - &product_id), - GNUNET_PQ_result_spec_string ("product_name", - &pd.product_name), - GNUNET_PQ_result_spec_string ("description", - &pd.description), - TALER_PQ_result_spec_json ("description_i18n", - &pd.description_i18n), - GNUNET_PQ_result_spec_string ("unit", - &pd.unit), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "price_array", - &pd.price_array_length, - &pd.price_array), - GNUNET_PQ_result_spec_uint64 ("remaining_stock", - &pd.remaining_stock), - GNUNET_PQ_result_spec_uint32 ("remaining_stock_frac", - &pd.remaining_stock_frac), - TALER_PQ_result_spec_json ("taxes", - &pd.taxes), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("image_hash", - &pd.image_hash), - &no_image_hash), - GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", - &pd.allow_fractional_quantity), - GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", - &pd.fractional_precision_level), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "categories", - &num_categories, - &categories), - 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, - product_id, - &pd, - num_categories, - categories); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_inventory_products ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_InventoryProductCallback cb, - void *cb_cls) -{ - struct LookupInventoryProductsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - /* Can be overwritten by the lookup_inventory_products_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - ",description_i18n::TEXT" - ",product_name" - ",unit" - ",price_array" - ",CASE WHEN minv.total_stock = 9223372036854775807" - " THEN minv.total_stock" - " ELSE (GREATEST(0, rt.remaining_total) / 1000000)::INT8" - " END AS remaining_stock" - ",CASE WHEN minv.total_stock = 9223372036854775807" - " THEN 2147483647" - " ELSE mod(GREATEST(0, rt.remaining_total), 1000000)::INT4" - " END AS remaining_stock_frac" - ",taxes::TEXT" - ",image_hash" - ",allow_fractional_quantity" - ",fractional_precision_level" - ",product_id" - ",t.category_array AS categories" - " FROM merchant_inventory minv" - ",LATERAL (" - " SELECT ARRAY (" - " SELECT mpc.category_serial" - " FROM merchant_product_categories mpc" - " WHERE mpc.product_serial = minv.product_serial" - " ) AS category_array" - " ) t" - ",LATERAL (" - " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" - " + total_locked_frac::NUMERIC), 0)" - " AS total_locked" - " FROM merchant_inventory_locks mil" - " WHERE mil.product_serial = minv.product_serial" - " ) il" - ",LATERAL (" - " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" - " + total_locked_frac::NUMERIC), 0)" - " AS total_locked" - " FROM merchant_order_locks mol" - " WHERE mol.product_serial = minv.product_serial" - " ) ol" - ",LATERAL (" - " SELECT" - " (minv.total_stock::NUMERIC * 1000000" - " + minv.total_stock_frac::NUMERIC)" - " - (minv.total_sold::NUMERIC * 1000000" - " + minv.total_sold_frac::NUMERIC)" - " - (minv.total_lost::NUMERIC * 1000000" - " + minv.total_lost_frac::NUMERIC)" - " - il.total_locked" - " - ol.total_locked" - " AS remaining_total" - " ) rt"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_inventory_products_cb, - &plc); - /* If there was an error inside lookup_inventory_products_cb, return a hard error. */ - if (plc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_inventory_products_filtered.c b/src/backenddb/lookup_inventory_products_filtered.c @@ -1,240 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_inventory_products_filtered.c - * @brief Lookup inventory product details for templates (filtered) - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_inventory_products_filtered.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_inventory_products_filtered(). - */ -struct LookupInventoryProductsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_InventoryProductCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Postgres context for callbacks. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Did database result extraction fail? - */ - bool extract_failed; -}; - - -static void -lookup_inventory_products_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupInventoryProductsContext *plc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = plc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - char *product_id; - struct TALER_MERCHANTDB_InventoryProductDetails pd; - size_t num_categories; - uint64_t *categories; - bool no_image_hash; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("product_id", - &product_id), - GNUNET_PQ_result_spec_string ("product_name", - &pd.product_name), - GNUNET_PQ_result_spec_string ("description", - &pd.description), - TALER_PQ_result_spec_json ("description_i18n", - &pd.description_i18n), - GNUNET_PQ_result_spec_string ("unit", - &pd.unit), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "price_array", - &pd.price_array_length, - &pd.price_array), - GNUNET_PQ_result_spec_uint64 ("remaining_stock", - &pd.remaining_stock), - GNUNET_PQ_result_spec_uint32 ("remaining_stock_frac", - &pd.remaining_stock_frac), - TALER_PQ_result_spec_json ("taxes", - &pd.taxes), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("image_hash", - &pd.image_hash), - &no_image_hash), - GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", - &pd.allow_fractional_quantity), - GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", - &pd.fractional_precision_level), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "categories", - &num_categories, - &categories), - 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, - product_id, - &pd, - num_categories, - categories); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_inventory_products_filtered ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *const *product_ids, - size_t num_product_ids, - const uint64_t *categories, - size_t num_categories, - TALER_MERCHANTDB_InventoryProductCallback cb, - void *cb_cls) -{ - struct LookupInventoryProductsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - /* Can be overwritten by the lookup_inventory_products_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - (0 == num_product_ids) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_array_ptrs_string ( - num_product_ids, - (const char **) product_ids, - pg->conn), - (0 == num_categories) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_array_uint64 (num_categories, - categories, - pg->conn), - 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" - ",description_i18n::TEXT" - ",product_name" - ",unit" - ",price_array" - ",CASE WHEN minv.total_stock = 9223372036854775807" - " THEN minv.total_stock" - " ELSE (GREATEST(0, rt.remaining_total) / 1000000)::INT8" - " END AS remaining_stock" - ",CASE WHEN minv.total_stock = 9223372036854775807" - " THEN 2147483647" - " ELSE mod(GREATEST(0, rt.remaining_total), 1000000)::INT4" - " END AS remaining_stock_frac" - ",taxes::TEXT" - ",image_hash" - ",allow_fractional_quantity" - ",fractional_precision_level" - ",product_id" - ",t.category_array AS categories" - " FROM merchant_inventory minv" - ",LATERAL (" - " SELECT ARRAY (" - " SELECT mpc.category_serial" - " FROM merchant_product_categories mpc" - " WHERE mpc.product_serial = minv.product_serial" - " ) AS category_array" - " ) t" - ",LATERAL (" - " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" - " + total_locked_frac::NUMERIC), 0)" - " AS total_locked" - " FROM merchant_inventory_locks mil" - " WHERE mil.product_serial = minv.product_serial" - " ) il" - ",LATERAL (" - " SELECT COALESCE(SUM(total_locked::NUMERIC * 1000000" - " + total_locked_frac::NUMERIC), 0)" - " AS total_locked" - " FROM merchant_order_locks mol" - " WHERE mol.product_serial = minv.product_serial" - " ) ol" - ",LATERAL (" - " SELECT" - " (minv.total_stock::NUMERIC * 1000000" - " + minv.total_stock_frac::NUMERIC)" - " - (minv.total_sold::NUMERIC * 1000000" - " + minv.total_sold_frac::NUMERIC)" - " - (minv.total_lost::NUMERIC * 1000000" - " + minv.total_lost_frac::NUMERIC)" - " - il.total_locked" - " - ol.total_locked" - " AS remaining_total" - " ) rt" - " WHERE (" - " (COALESCE (array_length ($1::TEXT[], 1), 0) > 0" - " AND minv.product_id = ANY ($1::TEXT[]))" - " OR" - " (COALESCE (array_length ($2::BIGINT[], 1), 0) > 0" - " AND EXISTS (" - " SELECT 1" - " FROM merchant_product_categories mpc" - " WHERE mpc.product_serial = minv.product_serial" - " AND mpc.category_serial = ANY ($2::BIGINT[])" - " ))" - " )"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_inventory_products_cb, - &plc); - GNUNET_PQ_cleanup_query_params_closures (params); - /* If there was an error inside lookup_inventory_products_cb, return a hard error. */ - if (plc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_login_tokens.c b/src/backenddb/lookup_login_tokens.c @@ -1,177 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_login_tokens.c - * @brief Implementation of the lookup_login_tokens function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_login_tokens.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_products(). - */ -struct LookupLoginTokensContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_LoginTokensCallback 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 products. - * - * @param[in,out] cls of type `struct LookupProductsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_login_tokens_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupLoginTokensContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint32_t validity_scope; - uint64_t serial; - struct GNUNET_TIME_Timestamp expiration_time; - struct GNUNET_TIME_Timestamp creation_time; - char *description; - struct TALER_MERCHANTDB_LoginTokenP token; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("token", - &token), - GNUNET_PQ_result_spec_uint32 ("validity_scope", - &validity_scope), - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_timestamp ("creation_time", - &creation_time), - GNUNET_PQ_result_spec_timestamp ("expiration_time", - &expiration_time), - GNUNET_PQ_result_spec_uint64 ("serial", - &serial), - 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, - creation_time, - expiration_time, - validity_scope, - description, - serial); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_login_tokens ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t offset, - int64_t limit, - TALER_MERCHANTDB_LoginTokensCallback cb, - void *cb_cls) -{ - struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct LookupLoginTokensContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_products_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " token" - ",serial" - ",creation_time" - ",expiration_time" - ",validity_scope" - ",description" - " FROM merchant_login_tokens" - " WHERE expiration_time > $1" - " AND serial > $2" - " ORDER BY serial ASC" - " LIMIT $3"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " token" - ",serial" - ",creation_time" - ",expiration_time" - ",validity_scope" - ",description" - " FROM merchant_login_tokens" - " WHERE expiration_time > $1" - " AND serial < $2" - " ORDER BY serial DESC" - " LIMIT $3"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_login_tokens_cb, - &plc); - /* If there was an error inside lookup_products_cb, return a hard error. */ - if (plc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_mfa_challenge.c b/src/backenddb/lookup_mfa_challenge.c @@ -1,110 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_mfa_challenge.c - * @brief Implementation of the lookup_mfa_challenge function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "taler/taler_merchant_util.h" -#include "merchantdb_lib.h" -#include "merchant-database/lookup_mfa_challenge.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_mfa_challenge ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t challenge_id, - const struct TALER_MERCHANT_MFA_BodyHash *h_body, - struct TALER_MERCHANT_MFA_BodySalt *salt, - char **required_address, - enum TALER_MERCHANT_MFA_CriticalOperation *op, - struct GNUNET_TIME_Absolute *confirmation_date, - struct GNUNET_TIME_Absolute *retransmission_date, - uint32_t *retry_counter, - enum TALER_MERCHANT_MFA_Channel *tan_channel, - char **instance_name) -{ - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&challenge_id), - GNUNET_PQ_query_param_auto_from_type (h_body), - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_end - }; - char *op_str; - char *chan_str; - bool no_conf; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("op", - &op_str), - GNUNET_PQ_result_spec_auto_from_type ("salt", - salt), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_absolute_time ("confirmation_date", - confirmation_date), - &no_conf), - GNUNET_PQ_result_spec_absolute_time ("retransmission_date", - retransmission_date), - GNUNET_PQ_result_spec_uint32 ("retry_counter", - retry_counter), - GNUNET_PQ_result_spec_string ("tan_channel", - &chan_str), - GNUNET_PQ_result_spec_string ("required_address", - required_address), - GNUNET_PQ_result_spec_string ("instance_name", - instance_name), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_mfa_challenge", - "SELECT " - " op::TEXT" - " ,salt" - " ,confirmation_date" - " ,retransmission_date" - " ,retry_counter" - " ,required_address" - " ,tan_channel::TEXT" - " ,instance_name" - " FROM merchant.tan_challenges" - " WHERE (challenge_id = $1)" - " AND (h_body = $2)" - " AND (expiration_date > $3)"); - /* Initialize to conservative values in case qs ends up <= 0 */ - *tan_channel = TALER_MERCHANT_MFA_CHANNEL_NONE; - *op = TALER_MERCHANT_MFA_CO_NONE; - *instance_name = NULL; - *required_address = NULL; - *retry_counter = 0; - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_mfa_challenge", - params, - rs); - if (qs <= 0) - return qs; - if (no_conf) - *confirmation_date = GNUNET_TIME_UNIT_FOREVER_ABS; - *tan_channel = TALER_MERCHANT_MFA_channel_from_string (chan_str); - *op = TALER_MERCHANT_MFA_co_from_string (op_str); - GNUNET_free (chan_str); - GNUNET_free (op_str); - return qs; -} diff --git a/src/backenddb/lookup_order.c b/src/backenddb/lookup_order.c @@ -1,91 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_order.c - * @brief Implementation of the lookup_order function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_order.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct TALER_ClaimTokenP *claim_token, - struct TALER_MerchantPostDataHashP *h_post_data, - json_t **contract_terms) -{ - json_t *j; - struct TALER_ClaimTokenP ct; - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_json ("contract_terms", - &j), - GNUNET_PQ_result_spec_auto_from_type ("claim_token", - &ct), - GNUNET_PQ_result_spec_auto_from_type ("h_post_data", - h_post_data), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Finding contract term, order_id: '%s', instance_id: '%s'.\n", - order_id, - instance_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " contract_terms::TEXT" - ",claim_token" - ",h_post_data" - " FROM merchant_orders" - " WHERE order_id=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - { - if (NULL != contract_terms) - *contract_terms = j; - else - json_decref (j); - if (NULL != claim_token) - *claim_token = ct; - } - else - { - /* just to be safe: NULL it */ - if (NULL != contract_terms) - *contract_terms = NULL; - if (NULL != claim_token) - memset (claim_token, - 0, - sizeof (struct TALER_ClaimTokenP)); - } - return qs; -} diff --git a/src/backenddb/lookup_order_by_fulfillment.c b/src/backenddb/lookup_order_by_fulfillment.c @@ -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/backenddb/lookup_order_by_fulfillment.c - * @brief Implementation of the lookup_order_by_fulfillment function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_by_fulfillment ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *fulfillment_url, - const char *session_id, - bool allow_refunded_for_repurchase, - char **order_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (fulfillment_url), - GNUNET_PQ_query_param_string (session_id), - GNUNET_PQ_query_param_bool (allow_refunded_for_repurchase), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("order_id", - order_id), - 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" - " mct.order_id" - " FROM merchant_contract_terms mct" - " LEFT JOIN merchant_refunds mref" - " USING (order_serial)" - " WHERE fulfillment_url=$1" - " AND session_id=$2" - " AND ((CAST($3 AS BOOL)) OR" - " mref.refund_serial IS NULL)" - /* Theoretically, multiple paid orders - for the same fulfillment URL could - exist for this session_id -- if a - wallet was broken and did multiple - payments without repurchase detection. - So we need to limit to 1 when returning! */ - " ORDER BY order_id DESC" - " LIMIT 1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_order_charity.c b/src/backenddb/lookup_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/lookup_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/lookup_order_charity.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_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/lookup_order_status.c b/src/backenddb/lookup_order_status.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/lookup_order_status.c - * @brief Implementation of the lookup_order_status function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_order_status.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_status ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct TALER_PrivateContractHashP *h_contract_terms, - bool *paid) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - h_contract_terms), - GNUNET_PQ_result_spec_bool ("paid", - paid), - 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" - " h_contract_terms" - ",paid" - " FROM merchant_contract_terms" - " WHERE order_id=$1"); - *paid = false; - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_order_status_by_serial.c b/src/backenddb/lookup_order_status_by_serial.c @@ -1,65 +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/lookup_order_status_by_serial.c - * @brief Implementation of the lookup_order_status_by_serial function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_order_status_by_serial.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_status_by_serial ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t order_serial, - char **order_id, - struct TALER_PrivateContractHashP *h_contract_terms, - bool *paid) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&order_serial), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - h_contract_terms), - GNUNET_PQ_result_spec_string ("order_id", - order_id), - GNUNET_PQ_result_spec_bool ("paid", - paid), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - *paid = false; /* just to be safe(r) */ - TMH_PQ_prepare_anon (pg, - "SELECT" - " h_contract_terms" - ",order_id" - ",paid" - " FROM merchant_contract_terms" - " WHERE order_serial=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_order_summary.c b/src/backenddb/lookup_order_summary.c @@ -1,66 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_order_summary.c - * @brief Implementation of the lookup_order_summary function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_order_summary.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_summary ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct GNUNET_TIME_Timestamp *timestamp, - uint64_t *order_serial) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (order_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_timestamp ("creation_time", - timestamp), - 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" - " creation_time" - ",order_serial" - " FROM merchant_contract_terms" - " WHERE order_id=$1)" - "UNION" - "(SELECT" - " creation_time" - ",order_serial" - " FROM merchant_orders" - " WHERE order_id=$1)"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_orders.c b/src/backenddb/lookup_orders.c @@ -1,269 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 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/lookup_orders.c - * @brief Implementation of the lookup_orders function for Postgres - * @author Iván Ávalos - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_orders.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_orders(). - */ -struct LookupOrdersContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_OrdersCallback 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 orders. - * - * @param[in,out] cls of type `struct LookupOrdersContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_orders_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupOrdersContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *order_id; - uint64_t order_serial; - struct GNUNET_TIME_Timestamp ts; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("order_id", - &order_id), - GNUNET_PQ_result_spec_uint64 ("order_serial", - &order_serial), - GNUNET_PQ_result_spec_timestamp ("creation_time", - &ts), - 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, - order_id, - order_serial, - ts); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_orders ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_MERCHANTDB_OrderFilter *of, - TALER_MERCHANTDB_OrdersCallback cb, - void *cb_cls) -{ - struct LookupOrdersContext plc = { - .cb = cb, - .cb_cls = cb_cls - }; - uint64_t limit = (of->delta > 0) ? of->delta : -of->delta; - struct GNUNET_PQ_QueryParam params[] = { - /* $1 */ - GNUNET_PQ_query_param_uint64 (&limit), - GNUNET_PQ_query_param_uint64 (&of->start_row), - GNUNET_PQ_query_param_timestamp (&of->date), - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->paid)), - /* $5 */ - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->paid)), - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->refunded)), - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->refunded)), - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_ALL == of->wired)), - GNUNET_PQ_query_param_bool ((TALER_EXCHANGE_YNA_YES == of->wired)), - /* $10 */ - GNUNET_PQ_query_param_bool (NULL == of->session_id), - NULL == of->session_id - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (of->session_id), - GNUNET_PQ_query_param_bool (NULL == of->fulfillment_url), - NULL == of->fulfillment_url - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (of->fulfillment_url), - NULL == of->summary_filter - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (of->summary_filter), - 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)); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Looking up orders, using filter paid: %d, refunded: %d, wired: %d\n", - of->paid, - of->refunded, - of->wired); - - if (of->delta > 0) - { - TMH_PQ_prepare_anon (pg, - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_orders" - " WHERE order_serial > $2" - " AND" - " creation_time > $3" - " AND ($4 OR " - " NOT CAST($5 AS BOOL))" /* unclaimed orders are never paid */ - " AND ($6 OR " - " NOT CAST($7 AS BOOL))"/* unclaimed orders are never refunded */ - " AND ($8 OR " - " NOT CAST($9 AS BOOL))" /* unclaimed orders are never wired */ - " AND" - " (order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms))" /* only select unclaimed orders */ - " AND ($10 OR " - " ($11 = session_id))" - " AND ($12 OR " - " ($13 = fulfillment_url))" - " AND ( ($14::TEXT IS NULL) OR " - " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" - " ORDER BY order_serial ASC" - " LIMIT $1)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_contract_terms" - " WHERE order_serial > $2" - " AND" - " creation_time > $3" - " AND ($4 OR " - " (CAST($5 AS BOOL) = paid))" - " AND ($6 OR " - " (CAST($7 AS BOOL) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))))" - " AND ($8 OR" - " (CAST($9 AS BOOL) = wired))" - " AND ($10 OR " - " ($11 = session_id))" - " AND ($12 OR " - " ($13 = fulfillment_url))" - " AND ( ($14::TEXT IS NULL) OR " - " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" - " ORDER BY order_serial ASC" - " LIMIT $1)" - " ORDER BY order_serial ASC" - " LIMIT $1"); - } - else - { - TMH_PQ_prepare_anon (pg, - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_orders" - " WHERE order_serial < $2" - " AND" - " creation_time < $3" - " AND ($4 OR " - " NOT CAST($5 AS BOOL))" /* unclaimed orders are never paid */ - " AND ($6 OR " - " NOT CAST($7 AS BOOL))"/* unclaimed orders are never refunded */ - " AND ($8 OR " - " NOT CAST($9 AS BOOL))" /* unclaimed orders are never wired */ - " AND" - " order_serial NOT IN" - " (SELECT order_serial" - " FROM merchant_contract_terms)" /* only select unclaimed orders */ - " AND ($10 OR " - " ($11 = session_id))" - " AND ($12 OR " - " ($13 = fulfillment_url))" - " AND ( ($14::TEXT IS NULL) OR " - " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" - " ORDER BY order_serial DESC" - " LIMIT $1)" - "UNION " /* union ensures elements are distinct! */ - "(SELECT" - " order_id" - ",order_serial" - ",creation_time" - " FROM merchant_contract_terms" - " WHERE order_serial < $2" - " AND" - " creation_time < $3" - " AND ($4 OR " - " (CAST($5 AS BOOL) = paid))" - " AND ($6 OR " - " (CAST($7 AS BOOL) = (order_serial IN" - " (SELECT order_serial " - " FROM merchant_refunds))))" - " AND ($8 OR" - " (CAST($9 AS BOOL) = wired))" - " AND ($10 OR " - " ($11 = session_id))" - " AND ($12 OR " - " ($13 = fulfillment_url))" - " AND ( ($14::TEXT IS NULL) OR " - " (LOWER(contract_terms ->> 'summary') LIKE LOWER($14)) )" - " ORDER BY order_serial DESC" - " LIMIT $1)" - " ORDER BY order_serial DESC" - " LIMIT $1"); - } - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_orders_cb, - &plc); - if (plc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_otp_devices.c b/src/backenddb/lookup_otp_devices.c @@ -1,128 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_otp_devices.c - * @brief Implementation of the lookup_otp_devices function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_otp_devices.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_otp_devices(). - */ -struct LookupOtpDeviceContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_OtpDeviceCallback 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 otp_device. - * - * @param[in,out] cls of type `struct LookupOtpDeviceContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_otp_devices_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupOtpDeviceContext *tlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *otp_device_id; - char *otp_device_description; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("otp_id", - &otp_device_id), - GNUNET_PQ_result_spec_string ("otp_description", - &otp_device_description), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tlc->extract_failed = true; - return; - } - tlc->cb (tlc->cb_cls, - otp_device_id, - otp_device_description); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_otp_devices ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_OtpDeviceCallback cb, - void *cb_cls) -{ - struct LookupOtpDeviceContext tlc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_otp_device_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - " otp_id" - ",otp_description" - " FROM merchant_otp_devices"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_otp_devices_cb, - &tlc); - /* If there was an error inside lookup_otp_device_cb, return a hard error. */ - if (tlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_pending_deposits.c b/src/backenddb/lookup_pending_deposits.c @@ -1,178 +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/lookup_pending_deposits.c - * @brief Implementation of the lookup_pending_deposits function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_pending_deposits.h" -#include "helper.h" - - -/** - * Context for lookup_pending_deposits(). - */ -struct LookupDepositsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_PendingDepositsCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Database context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Set to the return value on errors. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about instances. - * - * @param cls of type `struct LookupDepositsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_deposits_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupDepositsContext *ldc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t deposit_serial; - struct GNUNET_TIME_Absolute wire_deadline; - struct GNUNET_TIME_Absolute retry_time; - struct TALER_PrivateContractHashP h_contract_terms; - struct TALER_MerchantPrivateKeyP merchant_priv; - char *instance_id; - struct TALER_MerchantWireHashP h_wire; - struct TALER_Amount amount_with_fee; - struct TALER_Amount deposit_fee; - struct TALER_CoinSpendPublicKeyP coin_pub; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("out_deposit_serial", - &deposit_serial), - GNUNET_PQ_result_spec_auto_from_type ("out_h_contract_terms", - &h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("out_merchant_priv", - &merchant_priv), - GNUNET_PQ_result_spec_string ("out_merchant_id", - &instance_id), - GNUNET_PQ_result_spec_absolute_time ("out_wire_transfer_deadline", - &wire_deadline), - GNUNET_PQ_result_spec_absolute_time ("out_retry_time", - &retry_time), - GNUNET_PQ_result_spec_auto_from_type ("out_h_wire", - &h_wire), - TALER_PQ_result_spec_amount_with_currency ("out_amount_with_fee", - &amount_with_fee), - TALER_PQ_result_spec_amount_with_currency ("out_deposit_fee", - &deposit_fee), - GNUNET_PQ_result_spec_auto_from_type ("out_coin_pub", - &coin_pub), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ldc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ldc->cb (ldc->cb_cls, - deposit_serial, - wire_deadline, - retry_time, - &h_contract_terms, - &merchant_priv, - instance_id, - &h_wire, - &amount_with_fee, - &deposit_fee, - &coin_pub); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_pending_deposits ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - uint64_t limit, - bool allow_future, - TALER_MERCHANTDB_PendingDepositsCallback cb, - void *cb_cls) -{ - struct LookupDepositsContext ldc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_TIME_Absolute now - = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_uint64 (&limit), - GNUNET_PQ_query_param_bool (allow_future), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_pending_deposits", - "SELECT" - " out_deposit_serial" - " ,out_h_contract_terms" - " ,out_merchant_priv" - " ,out_merchant_id" - " ,out_wire_transfer_deadline" - " ,out_retry_time" - " ,out_h_wire" - " ,out_amount_with_fee" - " ,out_deposit_fee" - " ,out_coin_pub" - " FROM merchant.lookup_pending_deposits($1, $2, $3, $4)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pending_deposits", - params, - &lookup_deposits_cb, - &ldc); - if (0 > ldc.qs) - return ldc.qs; - return qs; -} diff --git a/src/backenddb/lookup_pending_webhooks.c b/src/backenddb/lookup_pending_webhooks.c @@ -1,198 +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/lookup_pending_webhooks.c - * @brief Implementation of the lookup_pending_webhooks function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_pending_webhooks.h" -#include "helper.h" - -/** - * Context used for lookup_pending_webhooks_cb(). - */ -struct LookupPendingWebhookContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_PendingWebhooksCallback 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 LookupPendingWebhookContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_pending_webhooks_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupPendingWebhookContext *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 ("webhook_pending_serial", - &webhook_pending_serial), - GNUNET_PQ_result_spec_absolute_time ("next_attempt", - &next_attempt), - GNUNET_PQ_result_spec_uint32 ("retries", - &retries), - GNUNET_PQ_result_spec_string ("url", - &url), - GNUNET_PQ_result_spec_string ("http_method", - &http_method), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("header", - &header), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("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_lookup_pending_webhooks ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t limit, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls) -{ - struct LookupPendingWebhookContext pwlc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false, - }; - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_uint64 (&limit), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_pending_webhooks", - "SELECT" - " webhook_pending_serial" - " ,next_attempt" - " ,retries" - " ,url" - " ,http_method" - " ,header" - " ,body" - " FROM merchant.merchant_pending_webhooks" - " WHERE next_attempt <= $1" - " ORDER BY next_attempt ASC" - " LIMIT $2"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pending_webhooks", - params, - &lookup_pending_webhooks_cb, - &pwlc); - if (pwlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_pending_webhooks_next ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls) -{ - struct LookupPendingWebhookContext pwlc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params_null[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "lookup_pending_webhooks_next", - "SELECT" - " webhook_pending_serial" - " ,next_attempt" - " ,retries" - " ,url" - " ,http_method" - " ,header" - " ,body" - " FROM merchant.merchant_pending_webhooks" - " ORDER BY next_attempt ASC" - " LIMIT 1"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pending_webhooks_next", - params_null, - &lookup_pending_webhooks_cb, - &pwlc); - if (pwlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_product.c b/src/backenddb/lookup_product.c @@ -1,196 +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/lookup_product.c - * @brief Implementation of the lookup_product function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_product.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *product_id, - struct TALER_MERCHANTDB_ProductDetails *pd, - size_t *num_categories, - uint64_t **categories) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (product_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, - "SELECT" - " mi.description" - ",mi.description_i18n::TEXT" - ",mi.product_name" - ",mi.unit" - ",mi.price_array" - ",mi.taxes::TEXT" - ",mi.total_stock" - ",mi.total_stock_frac" - ",mi.allow_fractional_quantity" - ",mi.fractional_precision_level" - ",mi.total_sold" - ",mi.total_sold_frac" - ",mi.total_lost" - ",mi.total_lost_frac" - ",mi.total_locked" - ",mi.total_locked_frac" - ",mi.image" - ",mi.address::TEXT" - ",mi.next_restock" - ",mi.minimum_age" - ",mi.product_group_serial" - ",mi.money_pot_serial" - ",mi.price_is_net" - ",t.category_array AS categories" - " FROM merchant_inventory mi" - ",LATERAL (" - " SELECT ARRAY (" - " SELECT mpc.category_serial" - " FROM merchant_product_categories mpc" - " WHERE mpc.product_serial = mi.product_serial" - " ) AS category_array" - " ) t" - " WHERE mi.product_id=$1" - ); - if (NULL == pd) // FIXME: is this case needed? For now yes: delete-private-products-PRODUCT_ID uses it! - { - struct GNUNET_PQ_ResultSpec rs_null[] = { - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs_null); - } - else - { - char *my_name = NULL; - char *my_description = NULL; - json_t *my_description_i18n = NULL; - char *my_unit = NULL; - char *my_image = NULL; - json_t *my_address = NULL; - json_t *my_taxes = NULL; - uint64_t *my_categories = NULL; - struct TALER_Amount *my_price_array = NULL; - size_t my_price_array_length = 0; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("description", - &my_description), - TALER_PQ_result_spec_json ("description_i18n", - &my_description_i18n), - GNUNET_PQ_result_spec_string ("product_name", - &my_name), - GNUNET_PQ_result_spec_string ("unit", - &my_unit), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "price_array", - &my_price_array_length, - &my_price_array), - TALER_PQ_result_spec_json ("taxes", - &my_taxes), - GNUNET_PQ_result_spec_uint64 ("total_stock", - &pd->total_stock), - GNUNET_PQ_result_spec_uint32 ("total_stock_frac", - &pd->total_stock_frac), - GNUNET_PQ_result_spec_bool ("allow_fractional_quantity", - &pd->allow_fractional_quantity), - GNUNET_PQ_result_spec_uint32 ("fractional_precision_level", - &pd->fractional_precision_level), - GNUNET_PQ_result_spec_uint64 ("total_sold", - &pd->total_sold), - GNUNET_PQ_result_spec_uint32 ("total_sold_frac", - &pd->total_sold_frac), - GNUNET_PQ_result_spec_uint64 ("total_lost", - &pd->total_lost), - GNUNET_PQ_result_spec_uint32 ("total_lost_frac", - &pd->total_lost_frac), - GNUNET_PQ_result_spec_uint64 ("total_locked", - &pd->total_locked), - GNUNET_PQ_result_spec_uint32 ("total_locked_frac", - &pd->total_locked_frac), - GNUNET_PQ_result_spec_string ("image", - &my_image), - TALER_PQ_result_spec_json ("address", - &my_address), - GNUNET_PQ_result_spec_timestamp ("next_restock", - &pd->next_restock), - GNUNET_PQ_result_spec_uint32 ("minimum_age", - &pd->minimum_age), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "categories", - num_categories, - &my_categories), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("product_group_serial", - &pd->product_group_id), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("money_pot_serial", - &pd->money_pot_id), - NULL), - GNUNET_PQ_result_spec_bool ("price_is_net", - &pd->price_is_net), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - pd->product_group_id = 0; - pd->money_pot_id = 0; - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - pd->product_name = my_name; - pd->description = my_description; - pd->description_i18n = my_description_i18n; - pd->unit = my_unit; - pd->taxes = my_taxes; - pd->image = my_image; - pd->image_hash = NULL; - pd->address = my_address; - pd->price_array = my_price_array; - pd->price_array_length = my_price_array_length; - *categories = my_categories; - /* Clear original pointers to that cleanup_result doesn't squash them */ - my_name = NULL; - my_description = NULL; - my_description_i18n = NULL; - my_unit = NULL; - my_taxes = NULL; - my_image = NULL; - my_address = NULL; - my_price_array = NULL; - my_price_array_length = 0; - my_categories = NULL; - GNUNET_PQ_cleanup_result (rs); - return qs; - } -} diff --git a/src/backenddb/lookup_product_image_by_hash.c b/src/backenddb/lookup_product_image_by_hash.c @@ -1,58 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_product_image_by_hash.c - * @brief Implementation of the lookup_product_image_by_hash function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "merchantdb_lib.h" -#include "merchant-database/lookup_product_image_by_hash.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product_image_by_hash ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *image_hash, - char **image) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (image_hash), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("image", - image), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon ( - pg, - "SELECT" - " mi.image" - " FROM merchant_inventory mi" - " WHERE mi.image_hash=$1"); - *image = NULL; - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_products.c b/src/backenddb/lookup_products.c @@ -1,195 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_products.c - * @brief Implementation of the lookup_products function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_products.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_products(). - */ -struct LookupProductsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ProductsCallback 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 products. - * - * @param[in,out] cls of type `struct LookupProductsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_products_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupProductsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *product_id; - uint64_t product_serial; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("product_id", - &product_id), - GNUNET_PQ_result_spec_uint64 ("product_serial", - &product_serial), - 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, - product_serial, - product_id); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_products ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t offset, - int64_t limit, - const char *category_filter, - const char *name_filter, - const char *description_filter, - uint64_t product_group_id_filter, - TALER_MERCHANTDB_ProductsCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct LookupProductsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_products_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - NULL == category_filter - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (category_filter), - NULL == name_filter - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (name_filter), - NULL == description_filter - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string (description_filter), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_uint64 (&product_group_id_filter), - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " product_id" - " ,product_serial" - " FROM merchant_inventory" - " WHERE product_serial > $1" - " AND ( ($2::TEXT IS NULL) OR" - " (product_serial IN" - " (SELECT product_serial" - " FROM merchant_product_categories" - " WHERE category_serial IN" - " (SELECT category_serial" - " FROM merchant_categories" - " WHERE LOWER(category_name) LIKE LOWER($2)))) )" - " AND ( (0 = $6::INT8) OR" - " (product_group_serial = $6) )" - " AND ( ($3::TEXT IS NULL) OR" - " (LOWER(product_name) LIKE LOWER($3)) )" - " AND ( ($4::TEXT IS NULL) OR" - " (description LIKE LOWER($4)) )" - " ORDER BY product_serial ASC" - " LIMIT $5"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " product_id" - " ,product_serial" - " FROM merchant_inventory" - " WHERE product_serial < $1" - " AND ( ($2::TEXT IS NULL) OR" - " (product_serial IN" - " (SELECT product_serial" - " FROM merchant_product_categories" - " WHERE category_serial IN" - " (SELECT category_serial" - " FROM merchant_categories" - " WHERE LOWER(category_name) LIKE LOWER($2)))) )" - " AND ( (0 = $6::INT8) OR" - " (product_group_serial = $6) )" - " AND ( ($3::TEXT IS NULL) OR" - " (LOWER(product_name) LIKE LOWER($3)) )" - " AND ( ($4::TEXT IS NULL) OR" - " (description LIKE LOWER($4)) )" - " ORDER BY product_serial DESC" - " LIMIT $5"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_products_cb, - &plc); - /* If there was an error inside lookup_products_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/lookup_reconciliation_details.c b/src/backenddb/lookup_reconciliation_details.c @@ -1,173 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_reconciliation_details.c - * @brief Implementation of the lookup_reconciliation_details function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_reconciliation_details.h" -#include "helper.h" - - -/** - * Context for TALER_MERCHANTDB_lookup_reconciliation_details(). - */ -struct ReconciliationContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ReconciliationDetailsCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Database context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Set to the return value on errors. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about reconciliation - * details. - * - * @param cls of type `struct ReconciliationContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -reconciliation_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct ReconciliationContext *lic = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *order_id; - uint64_t dvs; - uint64_t dfs; - uint64_t fvs; - uint64_t ffs; - char *currency; - struct TALER_Amount remaining_deposit; - struct TALER_Amount deposit_fee; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("order_id", - &order_id), - GNUNET_PQ_result_spec_string ("currency", - &currency), - GNUNET_PQ_result_spec_uint64 ("deposit_value_sum", - &dvs), - GNUNET_PQ_result_spec_uint64 ("deposit_frac_sum", - &dfs), - GNUNET_PQ_result_spec_uint64 ("fee_value_sum", - &fvs), - GNUNET_PQ_result_spec_uint64 ("fee_frac_sum", - &ffs), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (currency, - &remaining_deposit)); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (currency, - &deposit_fee)); - remaining_deposit.value = dvs + dfs / TALER_AMOUNT_FRAC_BASE; - remaining_deposit.fraction = dfs % TALER_AMOUNT_FRAC_BASE; - deposit_fee.value = fvs + ffs / TALER_AMOUNT_FRAC_BASE; - deposit_fee.fraction = ffs % TALER_AMOUNT_FRAC_BASE; - - lic->cb (lic->cb_cls, - order_id, - &remaining_deposit, - &deposit_fee); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_reconciliation_details ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t expected_incoming_serial, - TALER_MERCHANTDB_ReconciliationDetailsCallback cb, - void *cb_cls) -{ - struct ReconciliationContext lic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&expected_incoming_serial), - 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" - " mct.order_id" - ",SUM((etc.exchange_deposit_value).val)::INT8 AS deposit_value_sum" - ",SUM((etc.exchange_deposit_value).frac)::INT8 AS deposit_frac_sum" - ",SUM((etc.exchange_deposit_fee).val)::INT8 AS fee_value_sum" - ",SUM((etc.exchange_deposit_fee).frac)::INT8 AS fee_frac_sum" - ",(etc.exchange_deposit_value).curr AS currency" - " FROM merchant_expected_transfer_to_coin etc" - " JOIN merchant_deposits md" - " USING (deposit_serial)" - " JOIN merchant_deposit_confirmations mdc" - " USING (deposit_confirmation_serial)" - " JOIN merchant_contract_terms mct" - " USING (order_serial)" - " WHERE expected_credit_serial=$1" - " GROUP BY mct.order_id, (etc.exchange_deposit_value).curr;"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &reconciliation_cb, - &lic); - if (0 > lic.qs) - return lic.qs; - return qs; -} diff --git a/src/backenddb/lookup_refund_proof.c b/src/backenddb/lookup_refund_proof.c @@ -1,60 +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/lookup_refund_proof.c - * @brief Implementation of the lookup_refund_proof function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_refund_proof.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refund_proof ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t refund_serial, - struct TALER_ExchangeSignatureP *exchange_sig, - struct TALER_ExchangePublicKeyP *exchange_pub) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&refund_serial), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("exchange_sig", - exchange_sig), - GNUNET_PQ_result_spec_auto_from_type ("exchange_pub", - exchange_pub), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " merchant.merchant_exchange_signing_keys.exchange_pub" - ",exchange_sig" - " FROM merchant_refund_proofs" - " JOIN merchant.merchant_exchange_signing_keys" - " USING (signkey_serial)" - " WHERE" - " refund_serial=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_refunds.c b/src/backenddb/lookup_refunds.c @@ -1,141 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_refunds.c - * @brief Implementation of the lookup_refunds function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_refunds.h" -#include "helper.h" - -/** - * Closure for #lookup_refunds_cb(). - */ -struct LookupRefundsContext -{ - /** - * Function to call for each refund. - */ - TALER_MERCHANTDB_RefundCallback rc; - - /** - * Closure for @e rc. - */ - void *rc_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 closure of type `struct LookupRefundsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_refunds_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRefundsContext *lrc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_CoinSpendPublicKeyP coin_pub; - struct TALER_Amount refund_amount; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), - TALER_PQ_result_spec_amount_with_currency ("refund_amount", - &refund_amount), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lrc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - lrc->rc (lrc->rc_cls, - &coin_pub, - &refund_amount); - GNUNET_PQ_cleanup_result (rs); /* technically useless here */ - } - lrc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refunds ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - TALER_MERCHANTDB_RefundCallback rc, - void *rc_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_end - }; - struct LookupRefundsContext lrc = { - .rc = rc, - .rc_cls = rc_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - 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! */ - TALER_LOG_DEBUG ("Looking for refund of h_contract_terms %s at `%s'\n", - GNUNET_h2s (&h_contract_terms->hash), - instance_id); - TMH_PQ_prepare_anon (pg, - "SELECT" - " coin_pub" - ",refund_amount" - " FROM merchant_refunds" - " WHERE order_serial=" - " (SELECT order_serial" - " FROM merchant_contract_terms" - " WHERE h_contract_terms=$1)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_refunds_cb, - &lrc); - if (0 >= qs) - return qs; - return lrc.qs; -} diff --git a/src/backenddb/lookup_refunds_detailed.c b/src/backenddb/lookup_refunds_detailed.c @@ -1,180 +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/lookup_refunds_detailed.c - * @brief Implementation of the lookup_refunds_detailed function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_refunds_detailed.h" -#include "helper.h" - -/** - * Closure for #lookup_refunds_detailed_cb(). - */ -struct LookupRefundsDetailedContext -{ - /** - * Function to call for each refund. - */ - TALER_MERCHANTDB_RefundDetailCallback rc; - - /** - * Closure for @e rc. - */ - void *rc_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 GetRefundsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_refunds_detailed_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRefundsDetailedContext *lrdc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - uint64_t refund_serial; - struct GNUNET_TIME_Timestamp timestamp; - struct TALER_CoinSpendPublicKeyP coin_pub; - uint64_t rtransaction_id; - struct TALER_Amount refund_amount; - char *reason; - char *exchange_url; - uint8_t pending8; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("refund_serial", - &refund_serial), - GNUNET_PQ_result_spec_timestamp ("refund_timestamp", - &timestamp), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &coin_pub), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_uint64 ("rtransaction_id", - &rtransaction_id), - GNUNET_PQ_result_spec_string ("reason", - &reason), - TALER_PQ_result_spec_amount_with_currency ("refund_amount", - &refund_amount), - GNUNET_PQ_result_spec_auto_from_type ("pending", - &pending8), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lrdc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - lrdc->rc (lrdc->rc_cls, - refund_serial, - timestamp, - &coin_pub, - exchange_url, - rtransaction_id, - reason, - &refund_amount, - 0 != pending8); - GNUNET_PQ_cleanup_result (rs); - } - lrdc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refunds_detailed ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP * - h_contract_terms, - TALER_MERCHANTDB_RefundDetailCallback rc, - void *rc_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_end - }; - struct LookupRefundsDetailedContext lrdc = { - .rc = rc, - .rc_cls = rc_cls, - .pg = pg - }; - enum GNUNET_DB_QueryStatus qs; - - 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! */ - TALER_LOG_DEBUG ("Looking for refund %s + %s\n", - GNUNET_h2s (&h_contract_terms->hash), - instance_id); - - TMH_PQ_prepare_anon (pg, - "SELECT" - " ref.refund_serial" - ",ref.refund_timestamp" - ",dep.coin_pub" - ",mcon.exchange_url" - ",ref.rtransaction_id" - ",ref.reason" - ",ref.refund_amount" - ",merchant_refund_proofs.exchange_sig IS NULL AS pending" - " FROM merchant_deposit_confirmations mcon" - " JOIN merchant_deposits dep" - " USING (deposit_confirmation_serial)" - " JOIN merchant_refunds ref" - " USING (order_serial, coin_pub)" - " LEFT JOIN merchant_refund_proofs" - " USING (refund_serial)" - " WHERE mcon.order_serial=" - " (SELECT order_serial" - " FROM merchant_contract_terms" - " WHERE h_contract_terms=$1)"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_refunds_detailed_cb, - &lrdc); - if (0 >= qs) - return qs; - return lrdc.qs; -} diff --git a/src/backenddb/lookup_reports_pending.c b/src/backenddb/lookup_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/lookup_reports_pending.c - * @brief Implementation of the lookup_reports_pending function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_reports_pending.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_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_lookup_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/lookup_spent_tokens_by_order.c b/src/backenddb/lookup_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/lookup_spent_tokens_by_order.c - * @brief Implementation of the lookup_spent_tokens_by_order function for Postgres - * @author Christian Blättler - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_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_lookup_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/lookup_statistics_amount_by_bucket.c b/src/backenddb/lookup_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/lookup_statistics_amount_by_bucket.c - * @brief Implementation of the lookup_statistics_amount_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_amount_by_bucket.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_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_lookup_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/lookup_statistics_amount_by_bucket_range.c b/src/backenddb/lookup_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/lookup_statistics_amount_by_bucket_range.c - * @brief Implementation of the lookup_statistics_amount_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_amount_by_bucket_range.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range(). - */ -struct LookupAmountStatisticsContext2 -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Postgres context for array lookups - */ - struct TALER_MERCHANTDB_PostgresContext *pg; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. - * - * @param[in,out] cls of type `struct LookupAmountStatisticsContext2 *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_amount_by_bucket_cb2 (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupAmountStatisticsContext2 *tflc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_Amount *amounts; - size_t num_amounts; - uint64_t bucket_start_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "cumulative_amounts", - &num_amounts, - &amounts), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp bucket_start; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); - tflc->cb (tflc->cb_cls, - bucket_start, - num_amounts, - amounts); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *slug, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback cb, - void *cb_cls) -{ - struct LookupAmountStatisticsContext2 context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_amount_by_bucket_cb2 */ - .extract_failed = false, - .pg = pg, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (slug), - GNUNET_PQ_query_param_string (granularity), - GNUNET_PQ_query_param_uint64 (&counter), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " msba.bucket_start" - ",ARRAY_AGG (" - " ROW(msba.cumulative_value::INT8, msba.cumulative_frac::INT4, msba.curr)::merchant.taler_amount_currency" - " ) AS cumulative_amounts" - " FROM merchant_statistic_bucket_meta msbm" - " JOIN merchant_statistic_bucket_amount msba" - " USING (bmeta_serial_id)" - " WHERE msbm.slug=$1" - " AND msba.bucket_range=$2::TEXT::merchant.statistic_range" - " AND msbm.stype='amount'" - " GROUP BY msba.bucket_start" - " ORDER BY msba.bucket_start DESC" - " LIMIT $3;"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_amount_by_bucket_cb2, - &context); - /* If there was an error inside the cb, return a hard error. */ - if (context.extract_failed) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/lookup_statistics_amount_by_interval.c b/src/backenddb/lookup_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/lookup_statistics_amount_by_interval.c - * @brief Implementation of the lookup_statistics_amount_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_amount_by_interval.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_amount(). - */ -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_lookup_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/lookup_statistics_counter_by_bucket.c b/src/backenddb/lookup_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/lookup_statistics_counter_by_bucket.c - * @brief Implementation of the lookup_statistics_counter_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_counter_by_bucket.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_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_lookup_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/lookup_statistics_counter_by_bucket_range.c b/src/backenddb/lookup_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/lookup_statistics_counter_by_bucket_range.c - * @brief Implementation of the lookup_statistics_counter_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range(). - */ -struct LookupCounterStatisticsContext2 -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb; - - /** - * Closure for @a cb. - */ - void *cb_cls; - - /** - * Did database result extraction fail? - */ - bool extract_failed; - - /** - * Postgres context for array lookups - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about token families. - * - * @param[in,out] cls of type `struct LookupCounterStatisticsContext2 *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_statistics_counter_by_bucket_cb2 (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupCounterStatisticsContext2 *tflc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = tflc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - size_t num_slugs; - char *slugs; - size_t num_counters; - uint64_t *counters; - uint64_t bucket_start_epoch; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("bucket_start", - &bucket_start_epoch), - GNUNET_PQ_result_spec_array_uint64 (pg->conn, - "counters", - &num_counters, - &counters), - GNUNET_PQ_result_spec_array_string (pg->conn, - "slugs", - &num_slugs, - &slugs), - GNUNET_PQ_result_spec_end - }; - struct GNUNET_TIME_Timestamp bucket_start; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - if (num_slugs != num_counters) - { - GNUNET_break (0); - tflc->extract_failed = true; - GNUNET_PQ_cleanup_result (rs); - return; - } - { - const char *slugptrs[num_slugs]; - const char *pos = slugs; - - for (size_t j = 0; j<num_slugs; j++) - { - slugptrs[j] = pos; - pos += strlen (pos) + 1; - } - - bucket_start = GNUNET_TIME_timestamp_from_s (bucket_start_epoch); - tflc->cb (tflc->cb_cls, - bucket_start, - num_slugs, - slugptrs, - counters); - } - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *prefix, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb, - void *cb_cls) -{ - struct LookupCounterStatisticsContext2 context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_statistics_counter_by_bucket_cb2 */ - .extract_failed = false, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (prefix), - GNUNET_PQ_query_param_string (granularity), - GNUNET_PQ_query_param_uint64 (&counter), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " msbc.bucket_start" - ",ARRAY_AGG(msbm.slug) AS slugs" - ",ARRAY_AGG(msbc.cumulative_number) AS counters" - " FROM merchant_statistic_bucket_counter msbc" - " JOIN merchant_statistic_bucket_meta msbm" - " USING (bmeta_serial_id)" - " WHERE msbm.slug LIKE $1" - " AND msbc.bucket_range=$2::TEXT::merchant.statistic_range" - " AND msbm.stype = 'number'" - " GROUP BY msbc.bucket_start" - " ORDER BY msbc.bucket_start DESC" - " LIMIT $3"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_statistics_counter_by_bucket_cb2, - &context); - /* If there was an error inside the cb, return a hard error. */ - if (context.extract_failed) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; -} diff --git a/src/backenddb/lookup_statistics_counter_by_interval.c b/src/backenddb/lookup_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/lookup_statistics_counter_by_interval.c - * @brief Implementation of the lookup_statistics_counter_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_statistics_counter_by_interval.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_statistics_counter(). - */ -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_lookup_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/lookup_template.c b/src/backenddb/lookup_template.c @@ -1,77 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 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/lookup_template.c - * @brief Implementation of the lookup_template function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_template.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_template ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *template_id, - struct TALER_MERCHANTDB_TemplateDetails *td) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (template_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("template_description", - &td->template_description), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("otp_id", - &td->otp_id), - NULL), - TALER_PQ_result_spec_json ("template_contract", - &td->template_contract), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("editable_defaults", - &td->editable_defaults), - NULL), - 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" - " mt.template_description" - ",mod.otp_id" - ",mt.template_contract::TEXT" - ",mt.editable_defaults::TEXT" - " FROM merchant_template mt" - " LEFT JOIN merchant_otp_devices mod" - " ON (mod.otp_serial = mt.otp_device_id)" - " WHERE mt.template_id=$1"); - memset (td, - 0, - sizeof (*td)); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - GNUNET_PQ_cleanup_query_params_closures (params); - return qs; -} diff --git a/src/backenddb/lookup_templates.c b/src/backenddb/lookup_templates.c @@ -1,128 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_templates.c - * @brief Implementation of the lookup_templates function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_templates.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_templates(). - */ -struct LookupTemplateContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_TemplatesCallback 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 template. - * - * @param[in,out] cls of type `struct LookupTemplateContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_templates_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTemplateContext *tlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *template_id; - char *template_description; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("template_id", - &template_id), - GNUNET_PQ_result_spec_string ("template_description", - &template_description), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tlc->extract_failed = true; - return; - } - tlc->cb (tlc->cb_cls, - template_id, - template_description); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_templates ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_TemplatesCallback cb, - void *cb_cls) -{ - struct LookupTemplateContext tlc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_template_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - " template_id" - ",template_description" - " FROM merchant_template"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_templates_cb, - &tlc); - /* If there was an error inside lookup_templates_cb, return a hard error. */ - if (tlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_token_families.c b/src/backenddb/lookup_token_families.c @@ -1,157 +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/lookup_token_families.c - * @brief Implementation of the lookup_token_families function for Postgres - * @author Christian Blättler - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_token_families.h" -#include "helper.h" -#include "merchantdb_lib.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_token_families(). - */ -struct LookupTokenFamiliesContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_TokenFamiliesCallback 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 LookupTokenFamiliesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_token_families_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTokenFamiliesContext *tflc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *slug; - char *name; - char *description; - json_t *description_i18n = NULL; - char *kind; - struct GNUNET_TIME_Timestamp valid_after; - struct GNUNET_TIME_Timestamp valid_before; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("slug", - &slug), - GNUNET_PQ_result_spec_string ("name", - &name), - GNUNET_PQ_result_spec_string ("description", - &description), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("description_i18n", - &description_i18n), - NULL), - GNUNET_PQ_result_spec_timestamp ("valid_after", - &valid_after), - GNUNET_PQ_result_spec_timestamp ("valid_before", - &valid_before), - GNUNET_PQ_result_spec_string ("kind", - &kind), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - tflc->extract_failed = true; - return; - } - - tflc->cb (tflc->cb_cls, - slug, - name, - description, - description_i18n, - valid_after, - valid_before, - kind); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_families ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_TokenFamiliesCallback cb, - void *cb_cls) -{ - struct LookupTokenFamiliesContext context = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_token_families_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - " slug" - ",name" - ",description" - ",description_i18n::TEXT" - ",valid_after" - ",valid_before" - ",kind" - " FROM merchant_token_families"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_token_families_cb, - &context); - /* If there was an error inside lookup_token_families_cb, return a hard error. */ - if (context.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_token_family.c b/src/backenddb/lookup_token_family.c @@ -1,119 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 2024, 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_token_family.c - * @brief Implementation of the lookup_token_family function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_token_family.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct TALER_MERCHANTDB_TokenFamilyDetails *details) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (token_family_slug), - GNUNET_PQ_query_param_end - }; - char *kind; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("slug", - &details->slug), - GNUNET_PQ_result_spec_string ("name", - &details->name), - GNUNET_PQ_result_spec_string ("cipher_choice", - &details->cipher_spec), - GNUNET_PQ_result_spec_string ("description", - &details->description), - TALER_PQ_result_spec_json ("description_i18n", - &details->description_i18n), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("extra_data", - &details->extra_data), - NULL), - GNUNET_PQ_result_spec_timestamp ("valid_after", - &details->valid_after), - GNUNET_PQ_result_spec_timestamp ("valid_before", - &details->valid_before), - GNUNET_PQ_result_spec_relative_time ("duration", - &details->duration), - GNUNET_PQ_result_spec_relative_time ("validity_granularity", - &details->validity_granularity), - GNUNET_PQ_result_spec_relative_time ("start_offset", - &details->start_offset), - GNUNET_PQ_result_spec_string ("kind", - &kind), - GNUNET_PQ_result_spec_uint64 ("issued", - &details->issued), - GNUNET_PQ_result_spec_uint64 ("used", - &details->used), - 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" - " slug" - ",name" - ",cipher_choice" - ",description" - ",description_i18n::TEXT" - ",extra_data::TEXT" - ",valid_after" - ",valid_before" - ",duration" - ",validity_granularity" - ",start_offset" - ",kind" - ",issued" - ",used" - " FROM merchant_token_families" - " WHERE slug=$1"); - memset (details, - 0, - sizeof (*details)); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - { - if (0 == strcmp (kind, - "discount")) - details->kind = TALER_MERCHANTDB_TFK_Discount; - else if (0 == strcmp (kind, - "subscription")) - details->kind = TALER_MERCHANTDB_TFK_Subscription; - else - { - GNUNET_break (0); - GNUNET_PQ_cleanup_result (rs); - return GNUNET_DB_STATUS_HARD_ERROR; - } - GNUNET_free (kind); - } - return qs; -} diff --git a/src/backenddb/lookup_token_family_key.c b/src/backenddb/lookup_token_family_key.c @@ -1,168 +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/lookup_token_family_key.c - * @brief Implementation of the lookup_token_family_key function for Postgres - * @author Christian Blättler - */ -#include "platform.h" -#include <gnunet/gnunet_pq_lib.h> -#include <gnunet/gnunet_time_lib.h> -#include <string.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_token_family_key.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family_key ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct GNUNET_TIME_Timestamp valid_at, - struct GNUNET_TIME_Timestamp sign_until, - struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (token_family_slug), - GNUNET_PQ_query_param_timestamp (&valid_at), - GNUNET_PQ_query_param_timestamp (&sign_until), - GNUNET_PQ_query_param_end - }; - char *kind; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_blind_sign_pub ("pub", - &details->pub.public_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_blind_sign_priv ("priv", - &details->priv.private_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("signature_validity_start", - &details->signature_validity_start), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("signature_validity_end", - &details->signature_validity_end), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("private_key_deleted_at", - &details->private_key_deleted_at), - NULL), - GNUNET_PQ_result_spec_string ("slug", - &details->token_family.slug), - GNUNET_PQ_result_spec_string ("name", - &details->token_family.name), - GNUNET_PQ_result_spec_string ("cipher_choice", - &details->token_family.cipher_spec), - GNUNET_PQ_result_spec_string ("description", - &details->token_family.description), - TALER_PQ_result_spec_json ("description_i18n", - &details->token_family.description_i18n), - GNUNET_PQ_result_spec_timestamp ("valid_after", - &details->token_family.valid_after), - GNUNET_PQ_result_spec_timestamp ("valid_before", - &details->token_family.valid_before), - GNUNET_PQ_result_spec_relative_time ("duration", - &details->token_family.duration), - GNUNET_PQ_result_spec_relative_time ("validity_granularity", - &details->token_family. - validity_granularity), - GNUNET_PQ_result_spec_relative_time ("start_offset", - &details->token_family.start_offset), - GNUNET_PQ_result_spec_string ("kind", - &kind), - GNUNET_PQ_result_spec_uint64 ("issued", - &details->token_family.issued), - GNUNET_PQ_result_spec_uint64 ("used", - &details->token_family.used), - 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" - " h_pub" - ",pub" - ",priv" - ",cipher_choice" - ",mtfk.signature_validity_start" - ",mtfk.signature_validity_end" - ",mtfk.private_key_deleted_at" - ",slug" - ",name" - ",description" - ",description_i18n::TEXT" - ",mtf.valid_after" - ",mtf.valid_before" - ",duration" - ",validity_granularity" - ",start_offset" - ",kind" - ",issued" - ",used" - " FROM merchant_token_families mtf" - " LEFT JOIN merchant_token_family_keys mtfk" - " ON ( (mtf.token_family_serial = mtfk.token_family_serial)" - " AND ($2 >= mtfk.signature_validity_start)" - " AND ($2 <= mtfk.signature_validity_end)" - " AND ($3 <= mtfk.private_key_deleted_at) )" - " WHERE slug=$1" - " ORDER BY mtfk.signature_validity_start ASC" - " LIMIT 1"); - memset (details, - 0, - sizeof (*details)); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) - { - if (0 == strcmp (kind, - "discount")) - { - details->token_family.kind = TALER_MERCHANTDB_TFK_Discount; - } - else if (0 == strcmp (kind, - "subscription")) - { - details->token_family.kind = TALER_MERCHANTDB_TFK_Subscription; - } - else - { - GNUNET_free (kind); - GNUNET_free (details->token_family.slug); - GNUNET_free (details->token_family.name); - GNUNET_free (details->token_family.description); - json_decref (details->token_family.description_i18n); - GNUNET_CRYPTO_blind_sign_pub_decref (details->pub.public_key); - GNUNET_CRYPTO_blind_sign_priv_decref (details->priv.private_key); - GNUNET_free (details->token_family.cipher_spec); - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - GNUNET_free (kind); - } - return qs; -} diff --git a/src/backenddb/lookup_token_family_keys.c b/src/backenddb/lookup_token_family_keys.c @@ -1,224 +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/lookup_token_family_keys.c - * @brief Implementation of the lookup_token_family_keys function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_token_family_keys.h" -#include "helper.h" - - -/** - * Closure for lookup_token_keys_cb(). - */ -struct Context -{ - /** - * Postgres handle. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call on each result. - */ - TALER_MERCHANTDB_TokenKeyCallback cb; - - /** - * Closure for @e 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 products. - * - * @param[in,out] cls of type `struct LookupProductsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_token_keys_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct Context *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_MERCHANTDB_TokenFamilyKeyDetails details; - char *kind; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_blind_sign_pub ("pub", - &details.pub.public_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_blind_sign_priv ("priv", - &details.priv.private_key), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("signature_validity_start", - &details.signature_validity_start), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("signature_validity_end", - &details.signature_validity_end), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("private_key_deleted_at", - &details.private_key_deleted_at), - NULL), - GNUNET_PQ_result_spec_string ("slug", - &details.token_family.slug), - GNUNET_PQ_result_spec_string ("name", - &details.token_family.name), - GNUNET_PQ_result_spec_string ("description", - &details.token_family.description), - GNUNET_PQ_result_spec_string ("cipher_choice", - &details.token_family.cipher_spec), - TALER_PQ_result_spec_json ("description_i18n", - &details.token_family.description_i18n), - GNUNET_PQ_result_spec_timestamp ("valid_after", - &details.token_family.valid_after), - GNUNET_PQ_result_spec_timestamp ("valid_before", - &details.token_family.valid_before), - GNUNET_PQ_result_spec_relative_time ("duration", - &details.token_family.duration), - GNUNET_PQ_result_spec_relative_time ("validity_granularity", - &details.token_family. - validity_granularity), - GNUNET_PQ_result_spec_relative_time ("start_offset", - &details.token_family.start_offset), - GNUNET_PQ_result_spec_string ("kind", - &kind), - GNUNET_PQ_result_spec_uint64 ("issued", - &details.token_family.issued), - GNUNET_PQ_result_spec_uint64 ("used", - &details.token_family.used), - GNUNET_PQ_result_spec_end - }; - - memset (&details, - 0, - sizeof (details)); - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->extract_failed = true; - return; - } - if (0 == strcmp (kind, - "discount")) - details.token_family.kind = TALER_MERCHANTDB_TFK_Discount; - else if (0 == strcmp (kind, - "subscription")) - details.token_family.kind = TALER_MERCHANTDB_TFK_Subscription; - else - { - GNUNET_break (0); - GNUNET_free (kind); - GNUNET_PQ_cleanup_result (rs); - return; - } - ctx->cb (ctx->cb_cls, - &details); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family_keys ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct GNUNET_TIME_Timestamp start_time, - struct GNUNET_TIME_Timestamp end_time, - TALER_MERCHANTDB_TokenKeyCallback cb, - void *cb_cls) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (token_family_slug), - GNUNET_PQ_query_param_timestamp (&start_time), - GNUNET_PQ_query_param_timestamp (&end_time), - GNUNET_PQ_query_param_end - }; - struct Context ctx = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls - }; - 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" - " h_pub" - ",mtfk.pub" - ",mtfk.priv" - ",cipher_choice" - ",mtfk.signature_validity_start" - ",mtfk.signature_validity_end" - ",mtfk.private_key_deleted_at" - ",slug" - ",name" - ",description" - ",description_i18n::TEXT" - ",mtf.valid_after" - ",mtf.valid_before" - ",duration" - ",validity_granularity" - ",start_offset" - ",kind" - ",issued" - ",used" - " FROM merchant_token_families mtf" - " LEFT JOIN merchant_token_family_keys mtfk" - " USING (token_family_serial)" - " WHERE slug=$1" - " AND COALESCE ($2 <= mtfk.signature_validity_end, TRUE)" - " AND COALESCE ($3 >= mtfk.signature_validity_start, TRUE);"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_token_keys_cb, - &ctx); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Lookup of MTFK %s with valid [%llu,%llu] got %d\n", - token_family_slug, - (unsigned long long) start_time.abs_time.abs_value_us, - (unsigned long long) end_time.abs_time.abs_value_us, - (int) qs); - if (ctx.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_tos_accepted_early.c b/src/backenddb/lookup_tos_accepted_early.c @@ -1,56 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_tos_accepted_early.c - * @brief Implementation of the lookup_tos_accepted_early function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_tos_accepted_early.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_tos_accepted_early ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *merchant_id, - const char *exchange_url, - char **tos_version) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("tos_version", - tos_version), - GNUNET_PQ_result_spec_end - }; - - *tos_version = NULL; - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (merchant_id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT tos_version" - " FROM merchant_tos_accepted" - " WHERE exchange_url=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/lookup_transfer_details.c b/src/backenddb/lookup_transfer_details.c @@ -1,153 +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/lookup_transfer_details.c - * @brief Implementation of the lookup_transfer_details function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_transfer_details.h" -#include "helper.h" - -/** - * Closure for #lookup_transfer_details_cb(). - */ -struct LookupTransferDetailsContext -{ - /** - * Function to call for each order that was aggregated. - */ - TALER_MERCHANTDB_TransferDetailsCallback 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 LookupTransferDetailsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_transfer_details_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTransferDetailsContext *ltdc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - uint64_t current_offset; - struct TALER_TrackTransferDetails ttd; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("offset_in_exchange_list", - &current_offset), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &ttd.h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &ttd.coin_pub), - TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_value", - &ttd.coin_value), - TALER_PQ_result_spec_amount_with_currency ("exchange_deposit_fee", - &ttd.coin_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, - (unsigned int) current_offset, - &ttd); - GNUNET_PQ_cleanup_result (rs); - } - ltdc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_transfer_details ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_MERCHANTDB_TransferDetailsCallback 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 LookupTransferDetailsContext 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" - " mterm.h_contract_terms" - ",mtcoin.offset_in_exchange_list" - ",dep.coin_pub" - ",mtcoin.exchange_deposit_value" - ",mtcoin.exchange_deposit_fee" - " FROM merchant_expected_transfer_to_coin mtcoin" - " JOIN merchant_deposits dep" - " USING (deposit_serial)" - " JOIN merchant_deposit_confirmations mcon" - " USING (deposit_confirmation_serial)" - " JOIN merchant_contract_terms mterm" - " USING (order_serial)" - " JOIN merchant_expected_transfers met" - " USING (expected_credit_serial)" - " WHERE met.wtid=$2" - " AND met.exchange_url=$1"); - - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_transfer_details_cb, - &ltdc); - if (0 >= qs) - return qs; - return ltdc.qs; -} diff --git a/src/backenddb/lookup_transfer_details_by_order.c b/src/backenddb/lookup_transfer_details_by_order.c @@ -1,237 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 2025, 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_transfer_details_by_order.c - * @brief Implementation of the lookup_transfer_details_by_order function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_transfer_details_by_order.h" -#include "helper.h" - -/** - * Closure for lookup_transfer_details_by_order_cb(). - */ -struct LookupTransferDetailsByOrderContext -{ - - /** - * Plugin context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with all results. - */ - TALER_MERCHANTDB_OrderTransferDetailsCallback 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. We SELECT by coin, - * but because that's not useful for the UI, we combine all coins - * that were deposited in the same wire transfer into a single - * record before calling the callback. - * - * @param cls of type `struct LookupTransferDetailsByOrderContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_transfer_details_by_order_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTransferDetailsByOrderContext *ltdo = cls; - struct TALER_WireTransferIdentifierRawP last_wtid; - char *last_exchange_url = NULL; - struct GNUNET_TIME_Timestamp last_execution_time; - struct TALER_Amount last_deposit_value; - struct TALER_Amount last_deposit_fee; - bool last_confirmed; - uint64_t last_expected_credit_serial; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_WireTransferIdentifierRawP wtid; - char *exchange_url; - struct GNUNET_TIME_Timestamp execution_time; - struct TALER_Amount deposit_value; - struct TALER_Amount deposit_fee; - bool confirmed; - uint64_t expected_credit_serial; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("deposit_timestamp", - &execution_time), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_bool ("confirmed", - &confirmed), - GNUNET_PQ_result_spec_auto_from_type ("wtid", - &wtid), - GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", - &expected_credit_serial), - 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); - ltdo->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - if (0 == i) - { - last_wtid = wtid; - last_exchange_url = exchange_url; - last_execution_time = execution_time; - last_deposit_value = deposit_value; - last_deposit_fee = deposit_fee; - last_confirmed = confirmed; - last_expected_credit_serial = expected_credit_serial; - continue; - } - if ( (0 == - GNUNET_memcmp (&wtid, - &last_wtid)) && - (0 == strcmp (exchange_url, - last_exchange_url)) && - (expected_credit_serial == - last_expected_credit_serial) && - (GNUNET_TIME_timestamp_cmp (execution_time, - ==, - last_execution_time)) && - (last_confirmed == confirmed) && - (GNUNET_OK == - TALER_amount_cmp_currency (&deposit_value, - &last_deposit_value)) ) - { - GNUNET_assert (0 <= - TALER_amount_add (&last_deposit_value, - &last_deposit_value, - &deposit_value)); - GNUNET_assert (0 <= - TALER_amount_add (&last_deposit_fee, - &last_deposit_fee, - &deposit_fee)); - GNUNET_free (exchange_url); - continue; - } - ltdo->cb (ltdo->cb_cls, - &last_wtid, - last_exchange_url, - last_execution_time, - &last_deposit_value, - &last_deposit_fee, - last_confirmed, - last_expected_credit_serial); - GNUNET_free (last_exchange_url); - last_wtid = wtid; - last_exchange_url = exchange_url; - last_execution_time = execution_time; - last_deposit_value = deposit_value; - last_deposit_fee = deposit_fee; - last_confirmed = confirmed; - last_expected_credit_serial = expected_credit_serial; - } - if (num_results > 0) - { - ltdo->cb (ltdo->cb_cls, - &last_wtid, - last_exchange_url, - last_execution_time, - &last_deposit_value, - &last_deposit_fee, - last_confirmed, - last_expected_credit_serial); - } - GNUNET_free (last_exchange_url); - ltdo->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_transfer_details_by_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_OrderTransferDetailsCallback cb, - void *cb_cls) -{ - struct LookupTransferDetailsByOrderContext ltdo = { - .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" - " md.deposit_serial" - ",mcon.exchange_url" - ",met.wtid" - ",mtc.exchange_deposit_value" - ",mtc.exchange_deposit_fee" - ",mcon.deposit_timestamp" - ",met.confirmed" - ",met.expected_credit_serial" - " FROM merchant_expected_transfer_to_coin mtc" - " JOIN merchant_deposits md" - " USING (deposit_serial)" - " JOIN merchant_deposit_confirmations mcon" - " USING (deposit_confirmation_serial)" - " JOIN merchant_expected_transfers met" - " USING (expected_credit_serial)" - " JOIN merchant_accounts acc" - " ON (acc.account_serial = met.account_serial)" - " JOIN merchant_contract_terms contracts" - " USING (order_serial)" - " WHERE mcon.order_serial=$1" - " ORDER BY met.wtid"); - - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_transfer_details_by_order_cb, - &ltdo); - if (qs < 0) - return qs; - return ltdo.qs; -} diff --git a/src/backenddb/lookup_transfer_summary.c b/src/backenddb/lookup_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/lookup_transfer_summary.c - * @brief Implementation of the lookup_transfer_summary function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_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_lookup_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/lookup_transfers.c b/src/backenddb/lookup_transfers.c @@ -1,239 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-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/lookup_transfers.c - * @brief Implementation of the lookup_transfers function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_transfers.h" -#include "helper.h" - - -/** - * Closure for #lookup_transfers_cb(). - */ -struct LookupTransfersContext -{ - /** - * Function to call on results. - */ - TALER_MERCHANTDB_TransferCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Postgres context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Transaction status (set). - */ - 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 LookupTransfersContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_transfers_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupTransfersContext *ltc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_Amount credit_amount; - struct TALER_WireTransferIdentifierRawP wtid; - struct TALER_FullPayto payto_uri; - char *exchange_url; - uint64_t transfer_serial_id; - uint64_t expected_transfer_serial_id = 0; - struct GNUNET_TIME_Absolute execution_time; - bool expected; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount_with_currency ("credit_amount", - &credit_amount), - GNUNET_PQ_result_spec_auto_from_type ("wtid", - &wtid), - GNUNET_PQ_result_spec_string ("payto_uri", - &payto_uri.full_payto), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_uint64 ("credit_serial", - &transfer_serial_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("expected_credit_serial", - &expected_transfer_serial_id), - NULL), - GNUNET_PQ_result_spec_absolute_time ("execution_time", - &execution_time), - GNUNET_PQ_result_spec_bool ("expected", - &expected), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ltc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - ltc->cb (ltc->cb_cls, - &credit_amount, - &wtid, - payto_uri, - exchange_url, - transfer_serial_id, - expected_transfer_serial_id, - execution_time, - expected); - GNUNET_PQ_cleanup_result (rs); - } - ltc->qs = num_results; -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_transfers ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - struct GNUNET_TIME_Timestamp before, - struct GNUNET_TIME_Timestamp after, - int64_t limit, - uint64_t offset, - enum TALER_EXCHANGE_YesNoAll expected, - TALER_MERCHANTDB_TransferCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - bool by_time = ( (! GNUNET_TIME_absolute_is_never (before.abs_time)) || - (! GNUNET_TIME_absolute_is_zero (after.abs_time)) ); - struct LookupTransfersContext ltc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&before), - GNUNET_PQ_query_param_timestamp (&after), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - NULL == payto_uri.full_payto - ? GNUNET_PQ_query_param_null () /* NULL: do not filter by payto URI */ - : GNUNET_PQ_query_param_string (payto_uri.full_payto), - GNUNET_PQ_query_param_bool (! by_time), /* $6: filter by time? */ - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_ALL == expected), /* filter by expected? */ - GNUNET_PQ_query_param_bool (TALER_EXCHANGE_YNA_YES == expected), - - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " mt.credit_amount" - ",mt.wtid" - ",mac.payto_uri" - ",mt.exchange_url" - ",mt.credit_serial" - ",mt.execution_time" - ",mt.expected" - ",met.expected_credit_serial" - " FROM merchant_transfers mt" - " JOIN merchant_accounts mac" - " USING (account_serial)" - " LEFT JOIN merchant_expected_transfers met" - " ON mt.wtid = met.wtid" - " AND mt.account_serial = met.account_serial" - " AND mt.exchange_url = met.exchange_url" - " AND mt.expected" - " WHERE ( $6 OR " - " (mt.execution_time < $1 AND" - " mt.execution_time >= $2) )" - " AND ( (CAST($5 AS TEXT) IS NULL) OR " - " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" - " =REGEXP_REPLACE($5,'\\?.*','')) )" - " AND ( $7 OR " - " (mt.expected = $8) )" - " AND (mt.credit_serial > $3)" - " ORDER BY mt.credit_serial ASC" - " LIMIT $4"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " mt.credit_amount" - ",mt.wtid" - ",mac.payto_uri" - ",mt.exchange_url" - ",mt.credit_serial" - ",mt.execution_time" - ",mt.expected" - ",met.expected_credit_serial" - " FROM merchant_transfers mt" - " JOIN merchant_accounts mac" - " USING (account_serial)" - " LEFT JOIN merchant_expected_transfers met" - " ON mt.wtid = met.wtid" - " AND mt.account_serial = met.account_serial" - " AND mt.exchange_url = met.exchange_url" - " AND mt.expected" - " WHERE ( $6 OR " - " (mt.execution_time < $1 AND" - " mt.execution_time >= $2) )" - " AND ( (CAST($5 AS TEXT) IS NULL) OR " - " (REGEXP_REPLACE(mac.payto_uri,'\\?.*','')" - " =REGEXP_REPLACE($5,'\\?.*','')) )" - " AND ( $7 OR " - " (mt.expected = $8) )" - " AND (mt.credit_serial < $3)" - " ORDER BY mt.credit_serial DESC" - " LIMIT $4"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_transfers_cb, - &ltc); - if (0 >= qs) - return qs; - return ltc.qs; -} diff --git a/src/backenddb/lookup_units.c b/src/backenddb/lookup_units.c @@ -1,144 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/lookup_units.c - * @brief Implementation of the lookup_units function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_units.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_units(). - */ -struct LookupUnitsContext -{ - TALER_MERCHANTDB_UnitsCallback cb; - void *cb_cls; - bool extract_failed; -}; - - -static void -lookup_units_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupUnitsContext *luc = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_MERCHANTDB_UnitDetails ud = { 0 }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("unit_serial", - &ud.unit_serial), - GNUNET_PQ_result_spec_string ("unit", - &ud.unit), - GNUNET_PQ_result_spec_string ("unit_name_long", - &ud.unit_name_long), - GNUNET_PQ_result_spec_string ("unit_name_short", - &ud.unit_name_short), - TALER_PQ_result_spec_json ("unit_name_long_i18n", - &ud.unit_name_long_i18n), - TALER_PQ_result_spec_json ("unit_name_short_i18n", - &ud.unit_name_short_i18n), - GNUNET_PQ_result_spec_bool ("unit_allow_fraction", - &ud.unit_allow_fraction), - GNUNET_PQ_result_spec_uint32 ("unit_precision_level", - &ud.unit_precision_level), - GNUNET_PQ_result_spec_bool ("unit_active", - &ud.unit_active), - GNUNET_PQ_result_spec_bool ("unit_builtin", - &ud.unit_builtin), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - luc->extract_failed = true; - return; - } - luc->cb (luc->cb_cls, - ud.unit_serial, - &ud); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_units ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_UnitsCallback cb, - void *cb_cls) -{ - struct LookupUnitsContext luc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false - }; - struct GNUNET_PQ_QueryParam params[] = { - 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 cu.unit_serial" - " ,cu.unit" - " ,cu.unit_name_long" - " ,cu.unit_name_short" - " ,cu.unit_name_long_i18n" - " ,cu.unit_name_short_i18n" - " ,cu.unit_allow_fraction" - " ,cu.unit_precision_level" - " ,cu.unit_active" - " ,FALSE AS unit_builtin" - " FROM merchant_custom_units cu" - " UNION ALL " - "SELECT bu.unit_serial" - " ,bu.unit" - " ,bu.unit_name_long" - " ,bu.unit_name_short" - " ,bu.unit_name_long_i18n" - " ,bu.unit_name_short_i18n" - " ,COALESCE(bo.override_allow_fraction, bu.unit_allow_fraction)" - " ,COALESCE(bo.override_precision_level, bu.unit_precision_level)" - " ,COALESCE(bo.override_active, bu.unit_active)" - " ,TRUE AS unit_builtin" - " FROM merchant.merchant_builtin_units bu" - " LEFT JOIN merchant_builtin_unit_overrides bo" - " ON bo.builtin_unit_serial = bu.unit_serial" - " ORDER BY unit"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_units_cb, - &luc); - if (luc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_webhook.c b/src/backenddb/lookup_webhook.c @@ -1,88 +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/lookup_webhook.c - * @brief Implementation of the lookup_webhook function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_webhook.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhook ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *webhook_id, - struct TALER_MERCHANTDB_WebhookDetails *wb) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (webhook_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, - "SELECT" - " event_type" - ",url" - ",http_method" - ",header_template" - ",body_template" - " FROM merchant_webhook" - " WHERE webhook_id=$1"); - - if (NULL == wb) // fIXME: is this case needed? - { - struct GNUNET_PQ_ResultSpec rs_null[] = { - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs_null); - } - else - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("event_type", - &wb->event_type), - GNUNET_PQ_result_spec_string ("url", - &wb->url), - GNUNET_PQ_result_spec_string ("http_method", - &wb->http_method), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("header_template", - &wb->header_template), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("body_template", - &wb->body_template), - NULL), - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - } -} diff --git a/src/backenddb/lookup_webhook_by_event.c b/src/backenddb/lookup_webhook_by_event.c @@ -1,154 +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/lookup_webhook_by_event.c - * @brief Implementation of the lookup_webhook_by_event function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_webhook_by_event.h" -#include "helper.h" - -/** - * Context used for lookup_webhook_by_event_cb(). - */ -struct LookupWebhookDetailContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_WebhookDetailCallback 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 LookupPendingWebhookContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_webhook_by_event_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupWebhookDetailContext *wlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t webhook_serial; - char *event_type; - char *url; - char *http_method; - char *header_template; - char *body_template; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("webhook_serial", - &webhook_serial), - GNUNET_PQ_result_spec_string ("event_type", - &event_type), - GNUNET_PQ_result_spec_string ("url", - &url), - GNUNET_PQ_result_spec_string ("http_method", - &http_method), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("header_template", - &header_template), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("body_template", - &body_template), - NULL), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - wlc->extract_failed = true; - return; - } - wlc->cb (wlc->cb_cls, - webhook_serial, - event_type, - url, - http_method, - header_template, - body_template); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhook_by_event ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *event_type, - TALER_MERCHANTDB_WebhookDetailCallback cb, - void *cb_cls) -{ - struct LookupWebhookDetailContext wlc = { - .cb = cb, - .cb_cls = cb_cls, - .extract_failed = false, - }; - - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (event_type), - 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" - " webhook_serial" - ",event_type" - ",url" - ",http_method" - ",header_template" - ",body_template" - " FROM merchant_webhook" - " WHERE event_type=$1"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_webhook_by_event_cb, - &wlc); - - if (wlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_webhooks.c b/src/backenddb/lookup_webhooks.c @@ -1,128 +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/lookup_webhooks.c - * @brief Implementation of the lookup_webhooks function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_webhooks.h" -#include "helper.h" - -/** - * Context used for postgres_lookup_webhooks(). - */ -struct LookupWebhookContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_WebhooksCallback 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 LookupWebhookContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_webhooks_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupWebhookContext *wlc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *webhook_id; - char *event_type; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("webhook_id", - &webhook_id), - GNUNET_PQ_result_spec_string ("event_type", - &event_type), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - wlc->extract_failed = true; - return; - } - wlc->cb (wlc->cb_cls, - webhook_id, - event_type); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhooks ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_WebhooksCallback cb, - void *cb_cls) -{ - struct LookupWebhookContext wlc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_webhook_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - 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" - " webhook_id" - ",event_type" - " FROM merchant_webhook"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &lookup_webhooks_cb, - &wlc); - /* If there was an error inside lookup_webhook_cb, return a hard error. */ - if (wlc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/lookup_wire_fee.c b/src/backenddb/lookup_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/lookup_wire_fee.c - * @brief Implementation of the lookup_wire_fee function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/lookup_wire_fee.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_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/meson.build b/src/backenddb/meson.build @@ -20,7 +20,7 @@ libtalermerchantdb = library( 'insert_kyc_failure.c', 'insert_kyc_status.c', 'activate_account.c', - 'check_transfer_exists.c', + 'get_exists_transfer.c', 'delete_category.c', 'delete_contract_terms.c', 'delete_exchange_accounts.c', @@ -72,103 +72,103 @@ libtalermerchantdb = library( 'insert_transfer_details.c', 'insert_webhook.c', 'delete_unit.c', - 'lookup_units.c', - 'lookup_custom_units_by_names.c', - 'select_unit.c', - 'lookup_mfa_challenge.c', + 'iterate_units.c', + 'iterate_custom_units_by_names.c', + 'get_unit.c', + 'get_mfa_challenge.c', 'solve_mfa_challenge.c', 'update_mfa_challenge.c', 'create_mfa_challenge.c', 'insert_report.c', 'delete_report.c', 'update_report.c', - 'check_report.c', - 'select_reports.c', - 'lookup_reports_pending.c', + 'get_report_by_token.c', + 'iterate_reports.c', + 'iterate_reports_pending.c', 'update_report_status.c', - 'select_report.c', + 'get_report.c', 'insert_product_group.c', 'delete_product_group.c', 'update_product_group.c', - 'select_product_groups.c', + 'iterate_product_groups.c', 'insert_unclaim_signature.c', - 'lookup_reconciliation_details.c', - 'lookup_expected_transfer.c', + 'iterate_reconciliation_details.c', + 'get_expected_transfer.c', 'insert_money_pot.c', 'delete_money_pot.c', 'update_money_pot.c', - 'check_money_pots.c', - 'select_money_pots.c', - 'select_money_pot.c', + 'get_missing_money_pot.c', + 'iterate_money_pots.c', + 'get_money_pot.c', 'lock_product.c', - 'lookup_account.c', - 'lookup_all_products.c', - 'lookup_categories.c', - 'lookup_categories_by_ids.c', - 'lookup_contract_terms.c', - 'lookup_contract_terms_pos.c', - 'lookup_contract_terms_status.c', - 'lookup_deposits.c', - 'lookup_deposits_by_contract_and_coin.c', - 'lookup_deposits_by_order.c', - 'lookup_expected_transfers.c', - 'lookup_instance_auth.c', - 'lookup_instances.c', - 'lookup_inventory_products.c', - 'lookup_inventory_products_filtered.c', - 'lookup_login_tokens.c', - 'lookup_order.c', - 'lookup_order_by_fulfillment.c', - 'lookup_order_status.c', - 'lookup_order_status_by_serial.c', - 'lookup_order_summary.c', - 'lookup_orders.c', - 'lookup_otp_devices.c', - 'lookup_pending_deposits.c', - 'lookup_pending_webhooks.c', - 'lookup_product.c', - 'lookup_product_image_by_hash.c', - 'lookup_products.c', - 'lookup_refund_proof.c', - 'lookup_refunds.c', - 'lookup_refunds_detailed.c', - 'lookup_spent_tokens_by_order.c', - 'lookup_statistics_amount_by_bucket_range.c', - 'lookup_statistics_counter_by_bucket_range.c', - 'lookup_template.c', - 'lookup_templates.c', - 'lookup_token_families.c', - 'lookup_token_family.c', - 'lookup_token_family_key.c', - 'lookup_token_family_keys.c', - 'lookup_transfer_details.c', - 'lookup_transfer_details_by_order.c', - 'lookup_transfer_summary.c', - 'lookup_transfers.c', - 'lookup_webhook.c', - 'lookup_webhook_by_event.c', - 'lookup_all_webhooks.c', - 'lookup_webhooks.c', - 'lookup_wire_fee.c', + 'get_account_serial.c', + 'iterate_all_products.c', + 'iterate_categories.c', + 'iterate_categories_by_ids.c', + 'get_contract_terms.c', + 'get_contract_terms_pos.c', + 'get_contract_terms_status.c', + 'iterate_deposits.c', + 'iterate_deposits_by_contract_and_coin.c', + 'iterate_deposits_by_order.c', + 'iterate_expected_transfers.c', + 'get_instance_auth.c', + 'iterate_instances.c', + 'iterate_inventory_products.c', + 'iterate_inventory_products_filtered.c', + 'iterate_login_tokens.c', + 'get_order.c', + 'get_order_by_fulfillment.c', + 'get_order_status.c', + 'get_order_status_by_serial.c', + 'get_order_summary.c', + 'iterate_orders.c', + 'iterate_otp_devices.c', + 'iterate_pending_deposits.c', + 'iterate_pending_webhooks.c', + 'get_product.c', + 'get_product_image_by_hash.c', + 'iterate_products.c', + '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', + 'get_template.c', + 'iterate_templates.c', + 'iterate_token_families.c', + 'get_token_family.c', + 'get_token_family_key.c', + 'iterate_token_family_keys.c', + 'iterate_transfer_details.c', + 'iterate_transfer_details_by_order.c', + 'iterate_transfer_summary.c', + 'iterate_transfers.c', + 'get_webhook.c', + 'iterate_webhooks_by_event.c', + 'iterate_all_webhooks.c', + 'iterate_webhooks.c', + 'get_wire_fee.c', 'mark_contract_paid.c', 'mark_order_wired.c', - 'select_order_blinded_sigs.c', + 'iterate_order_blinded_sigs.c', 'purge_instance.c', 'refund_coin.c', - 'select_account.c', - 'select_account_by_uri.c', - 'select_accounts.c', - 'select_accounts_by_instance.c', - 'select_accounts_by_exchange.c', - 'select_category.c', - 'select_category_by_name.c', - 'select_exchange_keys.c', - 'select_exchanges.c', - 'select_login_token.c', - 'select_open_transfers.c', - 'select_otp.c', - 'select_otp_serial.c', - 'select_wirewatch_accounts.c', + 'get_account.c', + 'get_account_by_uri.c', + 'iterate_accounts.c', + 'iterate_accounts_by_instance.c', + 'iterate_accounts_by_exchange.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_wirewatch_accounts.c', 'store_wire_fee_by_exchange.c', 'unlock_inventory.c', 'update_account.c', @@ -190,19 +190,19 @@ libtalermerchantdb = library( 'insert_order_blinded_sigs.c', 'update_webhook.c', 'update_wirewatch_progress.c', - 'lookup_statistics_counter_by_bucket.c', - 'lookup_statistics_counter_by_interval.c', - 'lookup_statistics_amount_by_bucket.c', - 'lookup_statistics_amount_by_interval.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', 'insert_donau_instance.c', - 'check_donau_instance.c', - 'select_donau_instances.c', - 'select_all_donau_instances.c', - 'select_donau_instances_filtered.c', - 'select_donau_instance_by_serial.c', - 'lookup_donau_keys.c', - 'lookup_order_charity.c', - 'lookup_tos_accepted_early.c', + 'get_exists_donau_instance.c', + 'iterate_donau_instances.c', + 'iterate_all_donau_instances.c', + 'iterate_donau_instances_filtered.c', + 'get_donau_instance_by_serial.c', + 'get_donau_keys.c', + 'get_order_charity.c', + 'get_tos_accepted_early.c', 'upsert_donau_keys.c', 'update_donau_instance.c', 'merchantdb_helper.c', diff --git a/src/backenddb/select_account.c b/src/backenddb/select_account.c @@ -1,79 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023, 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/select_account.c - * @brief Implementation of the select_account function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_account.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_account ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - const struct TALER_MerchantWireHashP *h_wire, - struct TALER_MERCHANTDB_AccountDetails *ad) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (h_wire), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("salt", - &ad->salt), - GNUNET_PQ_result_spec_string ("payto_uri", - &ad->payto_uri.full_payto), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("credit_facade_url", - &ad->credit_facade_url), - NULL), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("credit_facade_credentials", - &ad->credit_facade_credentials), - NULL), - GNUNET_PQ_result_spec_bool ("active", - &ad->active), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata", - &ad->extra_wire_subject_metadata), - NULL), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (id, - pg->current_merchant_id)); - ad->h_wire = *h_wire; - ad->instance_id = id; - TMH_PQ_prepare_anon (pg, - "SELECT" - " salt" - ",payto_uri" - ",credit_facade_url" - ",credit_facade_credentials::TEXT" - ",active" - ",extra_wire_subject_metadata" - " FROM merchant_accounts" - " WHERE h_wire=$1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_account_by_uri.c b/src/backenddb/select_account_by_uri.c @@ -1,77 +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/select_account_by_uri.c - * @brief Implementation of the select_account_by_uri function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_account_by_uri.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_account_by_uri ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - struct TALER_FullPayto payto_uri, - struct TALER_MERCHANTDB_AccountDetails *ad) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (payto_uri.full_payto), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("salt", - &ad->salt), - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &ad->h_wire), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("credit_facade_url", - &ad->credit_facade_url), - NULL), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("credit_facade_credentials", - &ad->credit_facade_credentials), - NULL), - GNUNET_PQ_result_spec_bool ("active", - &ad->active), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (id, - pg->current_merchant_id)); - ad->credit_facade_url = NULL; - ad->credit_facade_credentials = NULL; - ad->payto_uri.full_payto - = GNUNET_strdup (payto_uri.full_payto); - ad->instance_id = id; - TMH_PQ_prepare_anon (pg, - "SELECT" - " salt" - ",h_wire" - ",credit_facade_url" - ",credit_facade_credentials::TEXT" - ",active" - " FROM merchant_accounts" - " WHERE payto_uri = $1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_accounts.c b/src/backenddb/select_accounts.c @@ -1,170 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/select_accounts.c - * @brief Implementation of the select_accounts function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_accounts.h" -#include "helper.h" - - -/** - * Context for select_accounts(). - */ -struct SelectAccountsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AccountCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Database context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Set to the return value on errors. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * 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 SelectAccountsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_account_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectAccountsContext *lic = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_FullPayto payto; - char *instance_id; - char *facade_url = NULL; - char *extra_wire_subject_metadata = NULL; - json_t *credential = NULL; - struct TALER_MERCHANTDB_AccountDetails acc; - struct TALER_MerchantPrivateKeyP merchant_priv; - bool no_priv; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("out_h_wire", - &acc.h_wire), - GNUNET_PQ_result_spec_auto_from_type ("out_salt", - &acc.salt), - GNUNET_PQ_result_spec_string ("out_payto_uri", - &payto.full_payto), - GNUNET_PQ_result_spec_string ("out_merchant_id", - &instance_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("out_credit_facade_url", - &facade_url), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("out_extra_wire_subject_metadata", - &extra_wire_subject_metadata), - NULL), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("out_credit_facade_credentials", - &credential), - NULL), - GNUNET_PQ_result_spec_bool ("out_active", - &acc.active), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("out_merchant_priv", - &merchant_priv), - &no_priv), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - acc.instance_id = instance_id; - acc.payto_uri = payto; - acc.credit_facade_url = facade_url; - acc.credit_facade_credentials = credential; - acc.extra_wire_subject_metadata = extra_wire_subject_metadata; - if (NULL != lic->cb) - lic->cb (lic->cb_cls, - no_priv ? NULL : &merchant_priv, - &acc); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_accounts ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_AccountCallback cb, - void *cb_cls) -{ - struct SelectAccountsContext lic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_accounts", - "SELECT" - " out_merchant_id" - " ,out_merchant_priv" - " ,out_h_wire" - " ,out_salt" - " ,out_payto_uri" - " ,out_credit_facade_url" - " ,out_credit_facade_credentials::TEXT" - " ,out_extra_wire_subject_metadata" - " ,out_active" - " FROM merchant.select_accounts()"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "select_accounts", - params, - &select_account_cb, - &lic); - if (0 > lic.qs) - return lic.qs; - return qs; -} diff --git a/src/backenddb/select_accounts_by_exchange.c b/src/backenddb/select_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/select_accounts_by_exchange.c - * @brief Implementation of the select_accounts_by_exchange function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_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_select_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/select_accounts_by_instance.c b/src/backenddb/select_accounts_by_instance.c @@ -1,175 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/select_accounts_by_instance.c - * @brief Implementation of the select_accounts_by_instance function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_accounts_by_instance.h" -#include "helper.h" - - -/** - * Context for select_accounts(). - */ -struct SelectAccountsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_AccountCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Database context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Merchant instance ID. - */ - const char *id; - - /** - * Set to the return value on errors. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * 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 SelectAccountsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_account_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectAccountsContext *lic = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_FullPayto payto; - char *facade_url = NULL; - char *extra_wire_subject_metadata = NULL; - json_t *credential = NULL; - struct TALER_MERCHANTDB_AccountDetails acc; - struct TALER_MerchantPrivateKeyP merchant_priv; - bool no_priv; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_wire", - &acc.h_wire), - GNUNET_PQ_result_spec_auto_from_type ("salt", - &acc.salt), - GNUNET_PQ_result_spec_string ("payto_uri", - &payto.full_payto), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("credit_facade_url", - &facade_url), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata", - &extra_wire_subject_metadata), - NULL), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("credit_facade_credentials", - &credential), - NULL), - GNUNET_PQ_result_spec_bool ("active", - &acc.active), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("merchant_priv", - &merchant_priv), - &no_priv), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lic->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; - } - acc.instance_id = lic->id; - acc.payto_uri = payto; - acc.credit_facade_url = facade_url; - acc.credit_facade_credentials = credential; - acc.extra_wire_subject_metadata = extra_wire_subject_metadata; - if (NULL != lic->cb) - lic->cb (lic->cb_cls, - no_priv ? NULL : &merchant_priv, - &acc); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_accounts_by_instance ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - TALER_MERCHANTDB_AccountCallback cb, - void *cb_cls) -{ - struct SelectAccountsContext lic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - .id = id - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (id), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - TMH_PQ_prepare_anon (pg, - "SELECT" - " ma.h_wire" - ",ma.salt" - ",ma.payto_uri" - ",ma.credit_facade_url" - ",ma.credit_facade_credentials::TEXT" - ",ma.extra_wire_subject_metadata" - ",ma.active" - ",mi.merchant_priv" - " FROM merchant_accounts ma" - " JOIN merchant.merchant_instances mi" - " ON (mi.merchant_id=$1)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &select_account_cb, - &lic); - if (0 > lic.qs) - return lic.qs; - return qs; -} diff --git a/src/backenddb/select_all_donau_instances.c b/src/backenddb/select_all_donau_instances.c @@ -1,165 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024, 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/select_all_donau_instances.c - * @brief Implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_all_donau_instances.h" -#include "helper.h" - -/** - * Context for select_donau_instances(). - */ -struct SelectDonauInstanceContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_DonauInstanceCallback cb; - - /** - * Closure for @e 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 donau instances. - * - * @param[in, out] cls of type `struct SelectDonauInstanceContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_donau_instance_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectDonauInstanceContext *sdc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t donau_instance_serial; - char *donau_url; - char *charity_name; - struct DONAU_CharityPublicKeyP charity_pub_key; - uint64_t charity_id; - struct TALER_Amount charity_max_per_year; - struct TALER_Amount charity_receipts_to_date; - int64_t current_year; - json_t *donau_keys_json = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("out_donau_instances_serial", - &donau_instance_serial), - GNUNET_PQ_result_spec_string ("out_donau_url", - &donau_url), - GNUNET_PQ_result_spec_string ("out_charity_name", - &charity_name), - GNUNET_PQ_result_spec_auto_from_type ("out_charity_pub_key", - &charity_pub_key), - GNUNET_PQ_result_spec_uint64 ("out_charity_id", - &charity_id), - TALER_PQ_result_spec_amount_with_currency ("out_charity_max_per_year", - &charity_max_per_year), - TALER_PQ_result_spec_amount_with_currency ("out_charity_receipts_to_date", - &charity_receipts_to_date), - GNUNET_PQ_result_spec_int64 ("out_current_year", - &current_year), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("out_keys_json", - &donau_keys_json), - NULL), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - sdc->extract_failed = true; - return; - } - sdc->cb (sdc->cb_cls, - donau_instance_serial, - donau_url, - charity_name, - &charity_pub_key, - charity_id, - &charity_max_per_year, - &charity_receipts_to_date, - current_year, - donau_keys_json); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_all_donau_instances ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_DonauInstanceCallback cb, - void *cb_cls) -{ - struct SelectDonauInstanceContext sdc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the select_donau_instance_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_all_donau_instances", - "SELECT" - " out_donau_instances_serial" - " ,out_donau_url" - " ,out_charity_name" - " ,out_charity_pub_key" - " ,out_charity_id" - " ,out_charity_max_per_year" - " ,out_charity_receipts_to_date" - " ,out_current_year" - " ,out_keys_json::TEXT" - " FROM merchant.select_all_donau_instances()"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "select_all_donau_instances", - params, - &select_donau_instance_cb, - &sdc); - - /* If there was an error inside select_donau_instance_cb, return a hard error. */ - if (sdc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - - return qs; -} diff --git a/src/backenddb/select_category.c b/src/backenddb/select_category.c @@ -1,77 +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/select_category.c - * @brief Implementation of the select_category function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_category.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_category ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t category_id, - struct TALER_MERCHANTDB_CategoryDetails *cd, - size_t *num_products, - char **products) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&category_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("category_name", - &cd->category_name), - TALER_PQ_result_spec_json ("category_name_i18n", - &cd->category_name_i18n), - GNUNET_PQ_result_spec_array_string (pg->conn, - "products", - num_products, - products), - 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" - " category_name" - ",category_name_i18n::TEXT" - ",t.product_array AS products" - " FROM merchant_categories mc" - ",LATERAL (" - " SELECT ARRAY (" - " SELECT " - " mi.product_id AS product_id" - " FROM merchant_product_categories mpc" - " JOIN merchant_inventory mi" - " USING (product_serial)" - " WHERE mpc.category_serial = mc.category_serial" - " ) AS product_array" - " ) t" - " WHERE mc.category_serial=$1"); - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_category_by_name.c b/src/backenddb/select_category_by_name.c @@ -1,61 +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/select_category_by_name.c - * @brief Implementation of the select_category_by_name function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_category_by_name.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_category_by_name ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *category_name, - json_t **name_i18n, - uint64_t *category_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (category_name), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("category_serial", - category_id), - TALER_PQ_result_spec_json ("category_name_i18n", - name_i18n), - 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" - " category_serial" - ",category_name_i18n::TEXT" - " FROM merchant_categories" - " WHERE category_name=$1"); - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_donau_instance_by_serial.c b/src/backenddb/select_donau_instance_by_serial.c @@ -1,59 +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/select_donau_instance_by_serial.c - * @brief Implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_donau_instance_by_serial.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instance_by_serial ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t serial, - char **donau_url, - uint64_t *charity_id) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&serial), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("donau_url", - donau_url), - GNUNET_PQ_result_spec_uint64 ("charity_id", - charity_id), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - TMH_PQ_prepare_anon (pg, - "SELECT donau_url" - " ,charity_id" - " FROM merchant_donau_instances" - " WHERE donau_instances_serial = $1"); - - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_donau_instances.c b/src/backenddb/select_donau_instances.c @@ -1,179 +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/select_donau_instances.c - * @brief Implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include <donau/donau_util.h> -#include "merchant-database/select_donau_instances.h" -#include "helper.h" - -/** - * Context for select_donau_instances(). - */ -struct SelectDonauInstanceContext -{ - /** - * Database connection. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_DonauInstanceCallback cb; - - /** - * Closure for @e 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 donau instances. - * - * @param[in, out] cls of type `struct SelectDonauInstanceContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_donau_instance_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectDonauInstanceContext *sdc = cls; - struct TALER_MERCHANTDB_PostgresContext *pg = sdc->pg; - struct DONAU_CharityPublicKeyP charity_pub_key; - - GNUNET_static_assert (sizeof (charity_pub_key) == - sizeof (pg->current_merchant_pub)); - memcpy (&charity_pub_key, - &pg->current_merchant_pub, - sizeof (charity_pub_key)); - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t donau_instance_serial; - char *donau_url; - char *charity_name; - uint64_t charity_id; - struct TALER_Amount charity_max_per_year; - struct TALER_Amount charity_receipts_to_date; - int64_t current_year; - json_t *donau_keys_json = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("donau_instances_serial", - &donau_instance_serial), - GNUNET_PQ_result_spec_string ("donau_url", - &donau_url), - GNUNET_PQ_result_spec_string ("charity_name", - &charity_name), - GNUNET_PQ_result_spec_uint64 ("charity_id", - &charity_id), - 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_int64 ("current_year", - &current_year), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("keys_json", - &donau_keys_json), - NULL), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - sdc->extract_failed = true; - return; - } - sdc->cb (sdc->cb_cls, - donau_instance_serial, - donau_url, - charity_name, - &charity_pub_key, - charity_id, - &charity_max_per_year, - &charity_receipts_to_date, - current_year, - donau_keys_json); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instances ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - TALER_MERCHANTDB_DonauInstanceCallback cb, - void *cb_cls) -{ - struct SelectDonauInstanceContext sdc = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the select_donau_instance_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " di.donau_instances_serial" - ",di.donau_url" - ",di.charity_name" - ",di.charity_id" - ",di.charity_max_per_year" - ",di.charity_receipts_to_date" - ",di.current_year" - ",dk.keys_json::TEXT" - " FROM merchant_donau_instances di" - " LEFT JOIN merchant.merchant_donau_keys dk" - " ON di.donau_url = dk.donau_url"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &select_donau_instance_cb, - &sdc); - - /* If there was an error inside select_donau_instance_cb, return a hard error. */ - if (sdc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - - return qs; -} diff --git a/src/backenddb/select_donau_instances_filtered.c b/src/backenddb/select_donau_instances_filtered.c @@ -1,123 +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/select_donau_instances_filtered.c - * @brief Implementation of the select_donau_instances_filtered function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_donau_instances_filtered.h" -#include "helper.h" - - -/** - * Context for select_donau_instances_filtered(). - */ -struct SelectDonauInstanceContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_DonauInstanceFilteredCallback cb; - - /** - * Closure for @e 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 donau instances. - * - * @param[in, out] cls of type `struct SelectDonauInstanceContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -select_donau_instance_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectDonauInstanceContext *sdc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *donau_url; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("donau_url", - &donau_url), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - sdc->extract_failed = true; - return; - } - sdc->cb (sdc->cb_cls, - donau_url); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instances_filtered ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *currency, - TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, - void *cb_cls) -{ - struct SelectDonauInstanceContext sdc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the select_donau_instance_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (currency), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - TMH_PQ_prepare_anon (pg, - "SELECT donau_url" - " FROM merchant_donau_instances" - " WHERE (charity_max_per_year).curr = $1"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "", - params, - &select_donau_instance_cb, - &sdc); - - /* If there was an error inside select_donau_instance_cb, return a hard error. */ - if (sdc.extract_failed) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/select_exchange_keys.c b/src/backenddb/select_exchange_keys.c @@ -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/backenddb/select_exchange_keys.c - * @brief Implementation of the select_exchange_keys function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include <taler/taler_exchange_service.h> -#include "merchant-database/select_exchange_keys.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_exchange_keys ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - struct GNUNET_TIME_Absolute *first_retry, - struct TALER_EXCHANGE_Keys **keys) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_end - }; - json_t *jkeys = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_absolute_time ("first_retry", - first_retry), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("keys_json", - &jkeys), - NULL), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - *keys = NULL; - PREPARE (pg, - "select_exchange_keys", - "SELECT" - " first_retry" - ",keys_json::TEXT" - " FROM merchant.merchant_exchange_keys" - " WHERE exchange_url=$1;"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "select_exchange_keys", - params, - rs); - if (qs <= 0) - return qs; - if (NULL != jkeys) - { - *keys = TALER_EXCHANGE_keys_from_json (jkeys); - json_decref (jkeys); - } - return qs; -} diff --git a/src/backenddb/select_exchanges.c b/src/backenddb/select_exchanges.c @@ -1,150 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/backenddb/select_exchanges.c - * @brief Implementation of the select_exchanges function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_exchanges.h" -#include "helper.h" - -/** - * Context used for TALER_MERCHANTDB_lookup_exchanges(). - */ -struct LookupExchangesContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ExchangesCallback 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 product exchanges. - * - * @param[in,out] cls of type `struct LookupExchangesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_exchanges_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupExchangesContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *exchange_url; - json_t *keys = NULL; - struct GNUNET_TIME_Absolute next_download; - struct GNUNET_TIME_Absolute keys_expiration; - uint32_t hc; - uint32_t ec; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_absolute_time ("first_retry", - &next_download), - GNUNET_PQ_result_spec_absolute_time ("expiration_time", - &keys_expiration), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("keys_json", - &keys), - NULL), - GNUNET_PQ_result_spec_uint32 ("exchange_http_status", - &hc), - GNUNET_PQ_result_spec_uint32 ("exchange_ec_code", - &ec), - 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, - exchange_url, - keys, - next_download, - keys_expiration, - (unsigned int) hc, - (enum TALER_ErrorCode) ec); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_exchanges ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_ExchangesCallback cb, - void *cb_cls) -{ - struct LookupExchangesContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_exchanges_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_exchanges", - "SELECT" - " exchange_url" - " ,first_retry" - " ,expiration_time" - " ,keys_json::TEXT" - " ,exchange_http_status" - " ,exchange_ec_code" - " FROM merchant.merchant_exchange_keys"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "select_exchanges", - params, - &lookup_exchanges_cb, - &plc); - /* If there was an error inside lookup_exchanges_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/select_login_token.c b/src/backenddb/select_login_token.c @@ -1,60 +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/select_login_token.c - * @brief Implementation of the select_login_token function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_login_token.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_login_token ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - const struct TALER_MERCHANTDB_LoginTokenP *token, - struct GNUNET_TIME_Timestamp *expiration_time, - uint32_t *validity_scope) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (token), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("expiration_time", - expiration_time), - GNUNET_PQ_result_spec_uint32 ("validity_scope", - validity_scope), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (id, - pg->current_merchant_id)); - TMH_PQ_prepare_anon (pg, - "SELECT" - " expiration_time" - ",validity_scope" - " FROM merchant_login_tokens" - " WHERE token=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_money_pot.c b/src/backenddb/select_money_pot.c @@ -1,69 +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/select_money_pot.c - * @brief Implementation of the select_money_pot function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_money_pot.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_money_pot ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t money_pot_id, - char **name, - char **description, - size_t *pot_total_len, - struct TALER_Amount **pot_totals) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&money_pot_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("money_pot_name", - name), - GNUNET_PQ_result_spec_string ("money_pot_description", - description), - TALER_PQ_result_spec_array_amount_with_currency (pg->conn, - "merchant", - "pot_totals", - pot_total_len, - pot_totals), - 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" - " money_pot_name" - " ,money_pot_description" - " ,pot_totals" - " FROM merchant_money_pots" - " WHERE money_pot_serial=$1;"); - return GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_money_pots.c b/src/backenddb/select_money_pots.c @@ -1,171 +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/select_money_pots.c - * @brief Implementation of the select_money_pots function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_money_pots.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_money_pots(). - */ -struct LookupMoneyPotsContext -{ - /** - * DB context. - */ - struct TALER_MERCHANTDB_PostgresContext *pg; - - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_MoneyPotsCallback 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 money pots. - * - * @param[in,out] cls of type `struct LookupMoneyPotsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_money_pots_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupMoneyPotsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t money_pot_serial; - char *money_pot_name; - size_t pot_total_len; - struct TALER_Amount *pot_totals; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("money_pot_serial", - &money_pot_serial), - GNUNET_PQ_result_spec_string ("money_pot_name", - &money_pot_name), - TALER_PQ_result_spec_array_amount_with_currency (plc->pg->conn, - "merchant", - "pot_totals", - &pot_total_len, - &pot_totals), - 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, - money_pot_serial, - money_pot_name, - pot_total_len, - pot_totals); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_money_pots ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_MoneyPotsCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct LookupMoneyPotsContext plc = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_money_pots_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " money_pot_serial" - " ,money_pot_name" - " ,pot_totals" - " FROM merchant_money_pots" - " WHERE money_pot_serial > $1" - " ORDER BY money_pot_serial ASC" - " LIMIT $2"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " money_pot_serial" - " ,money_pot_name" - " ,pot_totals" - " FROM merchant_money_pots" - " WHERE money_pot_serial < $1" - " ORDER BY money_pot_serial DESC" - " LIMIT $2"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_money_pots_cb, - &plc); - /* If there was an error inside lookup_money_pots_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/select_open_transfers.c b/src/backenddb/select_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/select_open_transfers.c - * @brief Implementation of the select_open_transfers function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_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_select_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/select_order_blinded_sigs.c b/src/backenddb/select_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/select_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/select_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_select_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/select_otp.c b/src/backenddb/select_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/select_otp.c - * @brief Implementation of the select_otp function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_otp.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_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/select_otp_serial.c b/src/backenddb/select_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/select_otp_serial.c - * @brief Implementation of the select_otp_serial function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_otp_serial.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_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/select_product_groups.c b/src/backenddb/select_product_groups.c @@ -1,160 +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/select_product_groups.c - * @brief Implementation of the select_product_groups function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_product_groups.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_lookup_product_groups(). - */ -struct LookupProductGroupsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ProductGroupsCallback 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 product groups. - * - * @param[in,out] cls of type `struct LookupProductGroupsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_product_groups_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupProductGroupsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t product_group_serial; - char *product_group_name; - char *product_group_description; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("product_group_serial", - &product_group_serial), - GNUNET_PQ_result_spec_string ("product_group_name", - &product_group_name), - GNUNET_PQ_result_spec_string ("product_group_description", - &product_group_description), - 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, - product_group_serial, - product_group_name, - product_group_description); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_product_groups ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_ProductGroupsCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct LookupProductGroupsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the lookup_product_groups_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " product_group_serial" - " ,product_group_name" - " ,product_group_description" - " FROM merchant_product_groups" - " WHERE product_group_serial > $1" - " ORDER BY product_group_serial ASC" - " LIMIT $2"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " product_group_serial" - " ,product_group_name" - " ,product_group_description" - " FROM merchant_product_groups" - " WHERE product_group_serial < $1" - " ORDER BY product_group_serial DESC" - " LIMIT $2"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &lookup_product_groups_cb, - &plc); - /* If there was an error inside lookup_product_groups_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/select_report.c b/src/backenddb/select_report.c @@ -1,103 +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/select_report.c - * @brief Implementation of the select_report function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_report.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_report ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t report_id, - char **report_program_section, - char **report_description, - char **mime_type, - char **data_source, - char **target_address, - struct GNUNET_TIME_Relative *frequency, - struct GNUNET_TIME_Relative *frequency_shift, - struct GNUNET_TIME_Absolute *next_transmission, - enum TALER_ErrorCode *last_error_code, - char **last_error_detail) -{ - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&report_id), - GNUNET_PQ_query_param_end - }; - uint32_t code; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("report_program_section", - report_program_section), - GNUNET_PQ_result_spec_string ("report_description", - report_description), - GNUNET_PQ_result_spec_string ("mime_type", - mime_type), - GNUNET_PQ_result_spec_string ("data_source", - data_source), - GNUNET_PQ_result_spec_string ("target_address", - target_address), - GNUNET_PQ_result_spec_relative_time ("frequency", - frequency), - GNUNET_PQ_result_spec_relative_time ("frequency_shift", - frequency_shift), - GNUNET_PQ_result_spec_absolute_time ("next_transmission", - next_transmission), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("last_error_code", - &code), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("last_error_detail", - last_error_detail), - NULL), - 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)); - *last_error_detail = NULL; - code = TALER_EC_NONE; - TMH_PQ_prepare_anon (pg, - "SELECT" - " report_program_section" - " ,report_description" - " ,mime_type" - " ,data_source" - " ,target_address" - " ,frequency" - " ,frequency_shift" - " ,next_transmission" - " ,last_error_code" - " ,last_error_detail" - " FROM merchant_reports" - " WHERE report_serial=$1;"); - qs = GNUNET_PQ_eval_prepared_singleton_select ( - pg->conn, - "", - params, - rs); - *last_error_code = (enum TALER_ErrorCode) code; - return qs; -} diff --git a/src/backenddb/select_reports.c b/src/backenddb/select_reports.c @@ -1,162 +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/select_reports.c - * @brief Implementation of the select_reports function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_reports.h" -#include "helper.h" - - -/** - * Context used for TALER_MERCHANTDB_select_reports(). - */ -struct SelectReportsContext -{ - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_ReportsCallback 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_reports_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SelectReportsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t report_serial; - char *report_description; - struct GNUNET_TIME_Relative frequency; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("report_serial", - &report_serial), - GNUNET_PQ_result_spec_string ("report_description", - &report_description), - GNUNET_PQ_result_spec_relative_time ("frequency", - &frequency), - 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, - report_serial, - report_description, - frequency); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_reports ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_ReportsCallback cb, - void *cb_cls) -{ - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct SelectReportsContext plc = { - .cb = cb, - .cb_cls = cb_cls, - /* Can be overwritten by the select_reports_cb */ - .extract_failed = false, - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - 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)); - if (limit > 0) - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " report_serial" - " ,report_description" - " ,frequency" - " FROM merchant_reports" - " WHERE report_serial > $1" - " AND NOT one_shot_hidden" - " ORDER BY report_serial ASC" - " LIMIT $2"); - } - else - { - TMH_PQ_prepare_anon (pg, - "SELECT" - " report_serial" - " ,report_description" - " ,frequency" - " FROM merchant_reports" - " WHERE report_serial < $1" - " AND NOT one_shot_hidden" - " ORDER BY report_serial DESC" - " LIMIT $2"); - } - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "", - params, - &select_reports_cb, - &plc); - /* If there was an error inside select_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/select_unit.c b/src/backenddb/select_unit.c @@ -1,110 +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/select_unit.c - * @brief Implementation of the select_unit function for Postgres - * @author Bohdan Potuzhnyi - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_unit.h" -#include "helper.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_unit ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *unit_id, - struct TALER_MERCHANTDB_UnitDetails *ud) -{ - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (unit_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("unit_serial", - &ud->unit_serial), - GNUNET_PQ_result_spec_string ("unit", - &ud->unit), - GNUNET_PQ_result_spec_string ("unit_name_long", - &ud->unit_name_long), - GNUNET_PQ_result_spec_string ("unit_name_short", - &ud->unit_name_short), - TALER_PQ_result_spec_json ("unit_name_long_i18n", - &ud->unit_name_long_i18n), - TALER_PQ_result_spec_json ("unit_name_short_i18n", - &ud->unit_name_short_i18n), - GNUNET_PQ_result_spec_bool ("unit_allow_fraction", - &ud->unit_allow_fraction), - GNUNET_PQ_result_spec_uint32 ("unit_precision_level", - &ud->unit_precision_level), - GNUNET_PQ_result_spec_bool ("unit_active", - &ud->unit_active), - GNUNET_PQ_result_spec_bool ("unit_builtin", - &ud->unit_builtin), - GNUNET_PQ_result_spec_end - }; - - GNUNET_assert (NULL != pg->current_merchant_id); - GNUNET_assert (0 == strcmp (instance_id, - pg->current_merchant_id)); - // FIXME: combine both SELECT statements into a single statement! - TMH_PQ_prepare_anon (pg, - "SELECT" - " cu.unit_serial" - " ,cu.unit" - " ,cu.unit_name_long" - " ,cu.unit_name_short" - " ,cu.unit_name_long_i18n" - " ,cu.unit_name_short_i18n" - " ,cu.unit_allow_fraction" - " ,cu.unit_precision_level" - " ,cu.unit_active" - " ,FALSE AS unit_builtin" - " FROM merchant_custom_units cu" - " WHERE cu.unit=$1"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs) - return qs; - TMH_PQ_prepare_anon (pg, - "SELECT" - " bu.unit_serial" - " ,bu.unit" - " ,bu.unit_name_long" - " ,bu.unit_name_short" - " ,bu.unit_name_long_i18n" - " ,bu.unit_name_short_i18n" - " ,COALESCE(bo.override_allow_fraction, bu.unit_allow_fraction)" - " AS unit_allow_fraction" - " ,COALESCE(bo.override_precision_level, bu.unit_precision_level)" - " AS unit_precision_level" - " ,COALESCE(bo.override_active, bu.unit_active)" - " AS unit_active" - " ,TRUE AS unit_builtin" - " FROM merchant.merchant_builtin_units bu" - " LEFT JOIN merchant_builtin_unit_overrides bo" - " ON bo.builtin_unit_serial = bu.unit_serial" - " WHERE bu.unit=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "", - params, - rs); -} diff --git a/src/backenddb/select_wirewatch_accounts.c b/src/backenddb/select_wirewatch_accounts.c @@ -1,139 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 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/select_wirewatch_accounts.c - * @brief Implementation of the select_wirewatch_accounts function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include <taler/taler_pq_lib.h> -#include "merchant-database/select_wirewatch_accounts.h" -#include "helper.h" - - -/** - * Closure for #handle_results(). - */ -struct Context -{ - /** - * Function to call with results. - */ - TALER_MERCHANTDB_WirewatchWorkCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Set to true if the parsing failed. - */ - bool failure; -}; - - -/** - * 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 Context *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -handle_results (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct Context *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - char *instance; - struct TALER_FullPayto payto_uri; - char *facade_url; - json_t *credential = NULL; - uint64_t last_serial; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("out_merchant_id", - &instance), - GNUNET_PQ_result_spec_string ("out_payto_uri", - &payto_uri.full_payto), - GNUNET_PQ_result_spec_string ("out_credit_facade_url", - &facade_url), - GNUNET_PQ_result_spec_allow_null ( - TALER_PQ_result_spec_json ("out_credit_facade_credentials", - &credential), - NULL), - GNUNET_PQ_result_spec_uint64 ("out_last_bank_serial", - &last_serial), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->failure = true; - return; - } - ctx->cb (ctx->cb_cls, - instance, - payto_uri, - facade_url, - credential, - last_serial); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_wirewatch_accounts ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_WirewatchWorkCallback cb, - void *cb_cls) -{ - struct Context ctx = { - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_wirewatch_accounts", - "SELECT" - " out_last_bank_serial" - " ,out_merchant_id" - " ,out_payto_uri" - " ,out_credit_facade_url" - " ,out_credit_facade_credentials::TEXT" - " FROM merchant.select_wirewatch_accounts()"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "select_wirewatch_accounts", - params, - &handle_results, - &ctx); - if (ctx.failure) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/backenddb/sql-schema/meson.build b/src/backenddb/sql-schema/meson.build @@ -7,16 +7,16 @@ sql_global_procedures = [ '../pg_base32_crockford.sql', '../pg_uri_escape.sql', '../pg_replace_placeholder.sql', - '../check_report.sql', + '../get_report_by_token.sql', '../create_tables.sql', '../pg_fixup_instance_schema.sql', '../iterate_outdated_kyc_statuses.sql', - '../select_wirewatch_accounts.sql', - '../select_open_transfers.sql', - '../select_all_donau_instances.sql', + '../iterate_wirewatch_accounts.sql', + '../iterate_open_transfers.sql', + '../iterate_all_donau_instances.sql', '../solve_mfa_challenge.sql', - '../lookup_pending_deposits.sql', - '../lookup_reports_pending.sql', + '../iterate_pending_deposits.sql', + '../iterate_reports_pending.sql', '../pg_select_accounts.sql', '../pg_create_instance_schema.sql', '../pg_create_instance_trigger.sql', @@ -39,8 +39,8 @@ sql_instance_procedures = [ '../delete_unit.sql', '../insert_unit.sql', '../update_unit.sql', - '../lookup_statistics_amount_by_interval.sql', - '../lookup_statistics_counter_by_interval.sql', + '../iterate_statistics_amount_by_interval.sql', + '../iterate_statistics_counter_by_interval.sql', '../insert_deposit_to_transfer.sql', '../insert_product.sql', '../insert_issued_token.sql', diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -56,34 +56,34 @@ #include "merchant-database/insert_transfer_details.h" #include "merchant-database/insert_webhook.h" #include "merchant-database/lock_product.h" -#include "merchant-database/lookup_account.h" -#include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_deposits.h" -#include "merchant-database/lookup_deposits_by_contract_and_coin.h" -#include "merchant-database/lookup_deposits_by_order.h" -#include "merchant-database/lookup_instances.h" -#include "merchant-database/lookup_order.h" -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "merchant-database/lookup_order_status.h" -#include "merchant-database/lookup_orders.h" -#include "merchant-database/lookup_all_webhooks.h" -#include "merchant-database/lookup_pending_webhooks.h" -#include "merchant-database/lookup_product.h" -#include "merchant-database/lookup_products.h" -#include "merchant-database/lookup_refund_proof.h" -#include "merchant-database/lookup_refunds.h" -#include "merchant-database/lookup_refunds_detailed.h" -#include "merchant-database/lookup_template.h" -#include "merchant-database/lookup_templates.h" -#include "merchant-database/lookup_transfer_details.h" -#include "merchant-database/lookup_transfer_details_by_order.h" -#include "merchant-database/lookup_transfer_summary.h" -#include "merchant-database/lookup_transfers.h" -#include "merchant-database/lookup_webhook.h" -#include "merchant-database/lookup_webhook_by_event.h" -#include "merchant-database/lookup_webhooks.h" -#include "merchant-database/lookup_wire_fee.h" +#include "merchant-database/get_account_serial.h" +#include "merchant-database/get_contract_terms.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/iterate_deposits.h" +#include "merchant-database/iterate_deposits_by_contract_and_coin.h" +#include "merchant-database/iterate_deposits_by_order.h" +#include "merchant-database/iterate_instances.h" +#include "merchant-database/get_order.h" +#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.h" +#include "merchant-database/get_product.h" +#include "merchant-database/iterate_products.h" +#include "merchant-database/get_refund_proof.h" +#include "merchant-database/iterate_refunds.h" +#include "merchant-database/iterate_refunds_detailed.h" +#include "merchant-database/get_template.h" +#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_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/mark_contract_paid.h" #include "merchant-database/mark_order_wired.h" #include "merchant-database/refund_coin.h" @@ -476,10 +476,10 @@ test_lookup_instances (bool active_only, .results_length = 0 }; memset (results_matching, 0, sizeof (unsigned int) * instances_length); - if (0 > TALER_MERCHANTDB_lookup_instances (pg, - active_only, - &lookup_instances_cb, - &cmp)) + if (0 > TALER_MERCHANTDB_iterate_instances (pg, + active_only, + &lookup_instances_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup instances failed\n"); @@ -726,10 +726,10 @@ run_test_instances (struct TestInstances_Closure *cls) instances)); /* Test lookup account */ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - TALER_MERCHANTDB_lookup_account (pg, - cls->instances[0].instance.id, - cls->accounts[0].payto_uri, - &account_serial)) + TALER_MERCHANTDB_get_account_serial (pg, + cls->instances[0].instance.id, + cls->accounts[0].payto_uri, + &account_serial)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup account failed\n"); @@ -742,12 +742,12 @@ run_test_instances (struct TestInstances_Closure *cls) return 1; } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_account (pg, - cls->instances[0].instance.id, - (struct TALER_FullPayto) { + TALER_MERCHANTDB_get_account_serial (pg, + cls->instances[0].instance.id, + (struct TALER_FullPayto) { (char *) "payto://other-uri" }, - &account_serial)) + &account_serial)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup account failed: account found where there is none\n"); @@ -1069,12 +1069,12 @@ test_lookup_product (const struct InstanceData *instance, uint64_t *categories = NULL; TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_product (pg, - instance->instance.id, - product->id, - &lookup_result, - &num_categories, - &categories)) + if (0 > TALER_MERCHANTDB_get_product (pg, + instance->instance.id, + product->id, + &lookup_result, + &num_categories, + &categories)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup product failed\n"); @@ -1176,16 +1176,16 @@ test_lookup_products (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (unsigned int) * products_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_products (pg, - instance->instance.id, - 0, - 20, - NULL, - NULL, - NULL, - 0, - &lookup_products_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_products (pg, + instance->instance.id, + 0, + 20, + NULL, + NULL, + NULL, + 0, + &lookup_products_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup products failed\n"); @@ -1380,12 +1380,12 @@ run_test_products (struct TestProducts_Closure *cls) uint64_t *categories = NULL; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_product (pg, - cls->instance.instance.id, - "nonexistent_product", - NULL, - &num_categories, - &categories)) + TALER_MERCHANTDB_get_product (pg, + cls->instance.instance.id, + "nonexistent_product", + NULL, + &num_categories, + &categories)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup product failed\n"); @@ -1749,12 +1749,12 @@ test_lookup_order (const struct InstanceData *instance, sizeof (wh)); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - TALER_MERCHANTDB_lookup_order (pg, - instance->instance.id, - order->id, - &ct, - &oh, - &lookup_terms)) + TALER_MERCHANTDB_get_order (pg, + instance->instance.id, + order->id, + &ct, + &oh, + &lookup_terms)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order failed\n"); @@ -1866,11 +1866,11 @@ test_lookup_orders (const struct InstanceData *instance, 0, sizeof (bool) * orders_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_orders (pg, - instance->instance.id, - filter, - &lookup_orders_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_orders (pg, + instance->instance.id, + filter, + &lookup_orders_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup orders failed\n"); @@ -1964,11 +1964,11 @@ get_order_serial (const struct InstanceData *instance, GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance (pg, instance->instance.id)); - GNUNET_assert (0 < TALER_MERCHANTDB_lookup_orders (pg, - instance->instance.id, - &filter, - &get_order_serial_cb, - &lookup_cls)); + GNUNET_assert (0 < TALER_MERCHANTDB_iterate_orders (pg, + instance->instance.id, + &filter, + &get_order_serial_cb, + &lookup_cls)); GNUNET_assert (0 != lookup_cls.serial); return lookup_cls.serial; @@ -2066,12 +2066,12 @@ test_lookup_contract_terms (const struct InstanceData *instance, TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - TALER_MERCHANTDB_lookup_contract_terms (pg, - instance->instance.id, - order->id, - &contract, - &order_serial, - NULL)) + TALER_MERCHANTDB_get_contract_terms (pg, + instance->instance.id, + order->id, + &contract, + &order_serial, + NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup contract terms failed\n"); @@ -2166,11 +2166,11 @@ test_lookup_order_status (const struct InstanceData *instance, TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - TALER_MERCHANTDB_lookup_order_status (pg, - instance->instance.id, - order->id, - &h_contract_terms, - &order_paid)) + TALER_MERCHANTDB_get_order_status (pg, + instance->instance.id, + order->id, + &h_contract_terms, + &order_paid)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order status failed\n"); @@ -2211,12 +2211,12 @@ test_lookup_order_by_fulfillment (const struct InstanceData *instance, GNUNET_assert (NULL != fulfillment_url); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - TALER_MERCHANTDB_lookup_order_by_fulfillment (pg, - instance->instance.id, - fulfillment_url, - session_id, - false, - &order_id)) + TALER_MERCHANTDB_get_order_by_fulfillment (pg, + instance->instance.id, + fulfillment_url, + session_id, + false, + &order_id)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order by fulfillment failed\n"); @@ -2260,17 +2260,17 @@ test_lookup_payment_status (const char *instance_id, TEST_SET_INSTANCE (instance_id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - TALER_MERCHANTDB_lookup_contract_terms_status (pg, - instance_id, - order_id, - session_id, - NULL, - &os, - &paid, - &wired, - &matches, - NULL, - &choice_index), + TALER_MERCHANTDB_get_contract_terms_status (pg, + instance_id, + order_id, + session_id, + NULL, + &os, + &paid, + &wired, + &matches, + NULL, + &choice_index), "Lookup payment status failed\n"); if ( (NULL != session_id) && (! matches) ) { @@ -2430,12 +2430,12 @@ run_test_orders (struct TestOrders_Closure *cls) struct TALER_MerchantPostDataHashP unused; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_order (pg, - cls->instance.instance.id, - cls->orders[1].id, - NULL, - &unused, - NULL)) + TALER_MERCHANTDB_get_order (pg, + cls->instance.instance.id, + cls->orders[1].id, + NULL, + &unused, + NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order failed\n"); @@ -2489,12 +2489,12 @@ run_test_orders (struct TestOrders_Closure *cls) uint64_t lookup_order_serial; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_contract_terms (pg, - cls->instance.instance.id, - cls->orders[1].id, - &lookup_contract, - &lookup_order_serial, - NULL)) + TALER_MERCHANTDB_get_contract_terms (pg, + cls->instance.instance.id, + cls->orders[1].id, + &lookup_contract, + &lookup_order_serial, + NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup contract terms failed\n"); @@ -2521,11 +2521,11 @@ run_test_orders (struct TestOrders_Closure *cls) bool order_paid = false; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_order_status (pg, - cls->instance.instance.id, - cls->orders[1].id, - &h_contract_terms, - &order_paid)) + TALER_MERCHANTDB_get_order_status (pg, + cls->instance.instance.id, + cls->orders[1].id, + &h_contract_terms, + &order_paid)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order status failed\n"); @@ -2544,11 +2544,11 @@ run_test_orders (struct TestOrders_Closure *cls) bool order_paid; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_order_status (pg, - cls->instance.instance.id, - cls->orders[1].id, - &h_contract_terms, - &order_paid)) + TALER_MERCHANTDB_get_order_status (pg, + cls->instance.instance.id, + cls->orders[1].id, + &h_contract_terms, + &order_paid)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order status failed\n"); @@ -2581,12 +2581,12 @@ run_test_orders (struct TestOrders_Closure *cls) { char *order_id; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_order_by_fulfillment (pg, - cls->instance.instance.id, - "fulfillment_url", - "test_orders_session", - false, - &order_id)) + TALER_MERCHANTDB_get_order_by_fulfillment (pg, + cls->instance.instance.id, + "fulfillment_url", + "test_orders_session", + false, + &order_id)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup order by fulfillment failed\n"); @@ -3067,11 +3067,11 @@ test_lookup_deposits (const struct InstanceData *instance, sizeof (unsigned int) * deposits_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); TEST_COND_RET_ON_FAIL (0 <= - TALER_MERCHANTDB_lookup_deposits (pg, - instance->instance.id, - h_contract_terms, - &lookup_deposits_cb, - &cmp), + TALER_MERCHANTDB_iterate_deposits (pg, + instance->instance.id, + h_contract_terms, + &lookup_deposits_cb, + &cmp), "Lookup deposits failed\n"); if (deposits_length != cmp.results_length) { @@ -3196,7 +3196,7 @@ test_lookup_deposits_contract_and_coin ( TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); TEST_COND_RET_ON_FAIL ( GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - TALER_MERCHANTDB_lookup_deposits_by_contract_and_coin ( + TALER_MERCHANTDB_iterate_deposits_by_contract_and_coin ( pg, instance->instance.id, h_contract, @@ -3297,10 +3297,10 @@ test_lookup_deposits_by_order (uint64_t order_serial, 0, sizeof (unsigned int) * deposits_length); if (deposits_length != - TALER_MERCHANTDB_lookup_deposits_by_order (pg, - order_serial, - &lookup_deposits_order_cb, - &cmp)) + TALER_MERCHANTDB_iterate_deposits_by_order (pg, + order_serial, + &lookup_deposits_order_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup deposits by order failed\n"); @@ -3410,10 +3410,10 @@ get_deposit_serial (const struct InstanceData *instance, }; GNUNET_assert (0 < - TALER_MERCHANTDB_lookup_deposits_by_order (pg, - order_serial, - &get_deposit_serial_cb, - &lookup_cls)); + TALER_MERCHANTDB_iterate_deposits_by_order (pg, + order_serial, + &get_deposit_serial_cb, + &lookup_cls)); GNUNET_assert (0 != lookup_cls.serial); return lookup_cls.serial; @@ -3873,11 +3873,11 @@ test_lookup_transfer_summary ( .deposit_fee = expected_deposit_fee, .result = 0 }; - if (1 != TALER_MERCHANTDB_lookup_transfer_summary (pg, - exchange_url, - wtid, - &lookup_transfer_summary_cb, - &cmp)) + if (1 != TALER_MERCHANTDB_iterate_transfer_summary (pg, + exchange_url, + wtid, + &lookup_transfer_summary_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup transfer summary failed\n"); @@ -3985,11 +3985,11 @@ test_lookup_transfer_details ( memset (results_matching, 0, sizeof (unsigned int) * details_length); - if (1 != TALER_MERCHANTDB_lookup_transfer_details (pg, - exchange_url, - wtid, - &lookup_transfer_details_cb, - &cmp)) + if (1 != TALER_MERCHANTDB_iterate_transfer_details (pg, + exchange_url, + wtid, + &lookup_transfer_details_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup transfer details failed\n"); @@ -4122,7 +4122,7 @@ test_lookup_transfer_details_by_order ( 0, sizeof (unsigned int) * transfers_length); if (transfers_length != - TALER_MERCHANTDB_lookup_transfer_details_by_order ( + TALER_MERCHANTDB_iterate_transfer_details_by_order ( pg, order_serial, &lookup_transfer_details_order_cb, @@ -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_lookup_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_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"); @@ -4332,16 +4332,16 @@ test_lookup_transfers (const struct InstanceData *instance, 0, sizeof (unsigned int) * transfers_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (1 != TALER_MERCHANTDB_lookup_transfers (pg, - instance->instance.id, - account->payto_uri, - before, - after, - limit, - offset, - TALER_EXCHANGE_YNA_ALL, - &lookup_transfers_cb, - &cmp)) + if (1 != TALER_MERCHANTDB_iterate_transfers (pg, + instance->instance.id, + account->payto_uri, + before, + after, + limit, + offset, + TALER_EXCHANGE_YNA_ALL, + &lookup_transfers_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup transfers 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_lookup_wire_fee (pg, - &cls->signkey.master_pub, - cls->wire_fee[0].wire_method, - GNUNET_TIME_timestamp_get (), - &fees, - NULL, - NULL, - NULL), + TALER_MERCHANTDB_get_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, @@ -4825,11 +4825,11 @@ test_lookup_refunds (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (unsigned int) * refunds_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (1 != TALER_MERCHANTDB_lookup_refunds (pg, - instance->instance.id, - h_contract_terms, - &lookup_refunds_cb, - &cmp)) + if (1 != TALER_MERCHANTDB_iterate_refunds (pg, + instance->instance.id, + h_contract_terms, + &lookup_refunds_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup refunds failed\n"); @@ -5035,11 +5035,11 @@ test_lookup_refunds_detailed ( }; memset (results_matching, 0, sizeof (unsigned int) * refunds_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_refunds_detailed (pg, - instance->instance.id, - h_contract_terms, - &lookup_refunds_detailed_cb, - &cmp)) + if (0 > TALER_MERCHANTDB_iterate_refunds_detailed (pg, + instance->instance.id, + h_contract_terms, + &lookup_refunds_detailed_cb, + &cmp)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup refunds detailed failed\n"); @@ -5148,11 +5148,11 @@ get_refund_serial (const struct InstanceData *instance, GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == TALER_MERCHANTDB_set_instance (pg, instance->instance.id)); - GNUNET_assert (0 < TALER_MERCHANTDB_lookup_refunds_detailed (pg, - instance->instance.id, - h_contract_terms, - &get_refund_serial_cb, - &lookup_cls)); + GNUNET_assert (0 < TALER_MERCHANTDB_iterate_refunds_detailed (pg, + instance->instance.id, + h_contract_terms, + &get_refund_serial_cb, + &lookup_cls)); GNUNET_assert (0 != lookup_cls.serial); return lookup_cls.serial; @@ -5176,10 +5176,10 @@ test_lookup_refund_proof (uint64_t refund_serial, { struct TALER_ExchangeSignatureP exchange_sig; struct TALER_ExchangePublicKeyP exchange_pub; - if (1 != TALER_MERCHANTDB_lookup_refund_proof (pg, - refund_serial, - &exchange_sig, - &exchange_pub)) + if (1 != TALER_MERCHANTDB_get_refund_proof (pg, + refund_serial, + &exchange_sig, + &exchange_pub)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup refund proof failed\n"); @@ -6079,10 +6079,10 @@ test_lookup_template (const struct InstanceData *instance, struct TALER_MERCHANTDB_TemplateDetails lookup_result; TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_template (pg, - instance->instance.id, - template->id, - &lookup_result)) + if (0 > TALER_MERCHANTDB_get_template (pg, + instance->instance.id, + template->id, + &lookup_result)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup template failed\n"); @@ -6182,10 +6182,10 @@ test_lookup_templates (const struct InstanceData *instance, 0, sizeof (unsigned int) * templates_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_templates (pg, - instance->instance.id, - &lookup_templates_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_templates (pg, + instance->instance.id, + &lookup_templates_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup templates failed\n"); @@ -6320,10 +6320,10 @@ run_test_templates (struct TestTemplates_Closure *cls) struct TALER_MERCHANTDB_TemplateDetails tx; if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_template (pg, - cls->instance.instance.id, - "nonexistent_template", - &tx)) + TALER_MERCHANTDB_get_template (pg, + cls->instance.instance.id, + "nonexistent_template", + &tx)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup template failed\n"); @@ -6533,10 +6533,10 @@ test_lookup_webhook (const struct InstanceData *instance, struct TALER_MERCHANTDB_WebhookDetails lookup_result; TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_webhook (pg, - instance->instance.id, - webhook->id, - &lookup_result)) + if (0 > TALER_MERCHANTDB_get_webhook (pg, + instance->instance.id, + webhook->id, + &lookup_result)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup webhook failed\n"); @@ -6632,10 +6632,10 @@ test_lookup_webhooks (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (unsigned int) * webhooks_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_webhooks (pg, - instance->instance.id, - &lookup_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_webhooks (pg, + instance->instance.id, + &lookup_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup webhooks failed\n"); @@ -6718,11 +6718,11 @@ test_lookup_webhook_by_event (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (unsigned int) * webhooks_length); TEST_SET_INSTANCE (instance->instance.id, GNUNET_DB_STATUS_SUCCESS_ONE_RESULT); - if (0 > TALER_MERCHANTDB_lookup_webhook_by_event (pg, - instance->instance.id, - webhooks->webhook.event_type, - &lookup_webhook_by_event_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_webhooks_by_event (pg, + instance->instance.id, + webhooks->webhook.event_type, + &lookup_webhook_by_event_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup webhooks by event failed\n"); @@ -6864,10 +6864,10 @@ run_test_webhooks (struct TestWebhooks_Closure *cls) &cls->webhooks[0])); /* Make sure it fails correctly for webhooks that don't exist */ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != - TALER_MERCHANTDB_lookup_webhook (pg, - cls->instance.instance.id, - "nonexistent_webhook", - NULL)) + TALER_MERCHANTDB_get_webhook (pg, + cls->instance.instance.id, + "nonexistent_webhook", + NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup webhook failed\n"); @@ -7062,7 +7062,7 @@ struct LookupPendingWebhookSerial_Closure /** * Function called after calling @e test_lookup_all_webhook, - * test_lookup_pending_webhooks_next and test_lookup_pending_webhook + * test_iterate_pending_webhooks_next and test_lookup_pending_webhook * * @param cls a pointer to the lookup closure. * @param webhook_serial reference to the configured webhook template. @@ -7122,12 +7122,12 @@ get_pending_serial (const struct InstanceData *instance, TALER_MERCHANTDB_set_instance (pg, instance->instance.id)); GNUNET_assert (0 < - TALER_MERCHANTDB_lookup_all_webhooks (pg, - instance->instance.id, - 0, - INT_MAX, - &get_pending_serial_cb, - &lpw)); + TALER_MERCHANTDB_iterate_all_webhooks (pg, + instance->instance.id, + 0, + INT_MAX, + &get_pending_serial_cb, + &lpw)); GNUNET_assert (0 != lpw.webhook_pending_serial); return lpw.webhook_pending_serial; @@ -7163,7 +7163,7 @@ struct TestLookupPendingWebhooks_Closure /** * Function called after calling @e test_lookup_all_webhook, - * test_lookup_pending_webhooks_next and test_lookup_pending_webhook + * test_iterate_pending_webhooks_next and test_lookup_pending_webhook * * @param cls a pointer to the lookup closure. * @param webhook_serial reference to the configured webhook template. @@ -7220,10 +7220,10 @@ test_lookup_pending_webhooks (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (results_matching)); - if (0 > TALER_MERCHANTDB_lookup_pending_webhooks (pg, - 1024, /* limit */ - &lookup_pending_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_pending_webhooks (pg, + 1024, /* limit */ + &lookup_pending_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup pending webhook failed\n"); @@ -7257,9 +7257,9 @@ test_lookup_pending_webhooks (const struct InstanceData *instance, * @return 0 when successful, 1 otherwise. */ static int -test_lookup_pending_webhooks_next (const struct InstanceData *instance, - unsigned int pwebhooks_length, - const struct PendingWebhookData *pwebhooks) +test_iterate_pending_webhooks_next (const struct InstanceData *instance, + unsigned int pwebhooks_length, + const struct PendingWebhookData *pwebhooks) { unsigned int results_matching[pwebhooks_length]; struct TestLookupPendingWebhooks_Closure cls = { @@ -7270,9 +7270,9 @@ test_lookup_pending_webhooks_next (const struct InstanceData *instance, }; memset (results_matching, 0, sizeof (results_matching)); - if (0 > TALER_MERCHANTDB_lookup_pending_webhooks_next (pg, - &lookup_pending_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_pending_webhooks_next (pg, + &lookup_pending_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup future webhook failed\n"); @@ -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_lookup_all_webhooks (pg, - instance->instance.id, - min_row, - max_results, - &lookup_pending_webhooks_cb, - &cls)) + if (0 > TALER_MERCHANTDB_iterate_all_webhooks (pg, + instance->instance.id, + min_row, + max_results, + &lookup_pending_webhooks_cb, + &cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup all webhooks failed\n"); @@ -7486,9 +7486,9 @@ run_test_pending_webhooks (struct TestPendingWebhooks_Closure *cls) TEST_RET_ON_FAIL (test_update_pending_webhook (&cls->instance, &cls->pwebhooks[0], GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); - TEST_RET_ON_FAIL (test_lookup_pending_webhooks_next (&cls->instance, - 1, - &cls->pwebhooks[1])); + TEST_RET_ON_FAIL (test_iterate_pending_webhooks_next (&cls->instance, + 1, + &cls->pwebhooks[1])); TEST_RET_ON_FAIL (test_update_pending_webhook (&cls->instance, &cls->pwebhooks[1], GNUNET_DB_STATUS_SUCCESS_NO_RESULTS)); diff --git a/src/include/merchant-database/all.h b/src/include/merchant-database/all.h @@ -9,10 +9,10 @@ #include "merchant-database/insert_kyc_failure.h" #include "merchant-database/insert_kyc_status.h" #include "merchant-database/activate_account.h" -#include "merchant-database/check_donau_instance.h" -#include "merchant-database/check_money_pots.h" -#include "merchant-database/check_report.h" -#include "merchant-database/check_transfer_exists.h" +#include "merchant-database/get_exists_donau_instance.h" +#include "merchant-database/get_missing_money_pot.h" +#include "merchant-database/get_report_by_token.h" +#include "merchant-database/get_exists_transfer.h" #include "merchant-database/create_mfa_challenge.h" #include "merchant-database/create_tables.h" #include "merchant-database/delete_category.h" @@ -80,98 +80,98 @@ #include "merchant-database/insert_unit.h" #include "merchant-database/insert_webhook.h" #include "merchant-database/lock_product.h" -#include "merchant-database/lookup_account.h" -#include "merchant-database/lookup_all_products.h" -#include "merchant-database/lookup_all_webhooks.h" -#include "merchant-database/lookup_categories.h" -#include "merchant-database/lookup_categories_by_ids.h" -#include "merchant-database/lookup_contract_terms.h" -#include "merchant-database/lookup_contract_terms_pos.h" -#include "merchant-database/lookup_contract_terms_status.h" -#include "merchant-database/lookup_custom_units_by_names.h" -#include "merchant-database/lookup_deposits.h" -#include "merchant-database/lookup_deposits_by_contract_and_coin.h" -#include "merchant-database/lookup_deposits_by_order.h" -#include "merchant-database/lookup_donau_keys.h" -#include "merchant-database/lookup_expected_transfer.h" -#include "merchant-database/lookup_expected_transfers.h" -#include "merchant-database/lookup_instance_auth.h" -#include "merchant-database/lookup_instances.h" -#include "merchant-database/lookup_inventory_products.h" -#include "merchant-database/lookup_inventory_products_filtered.h" -#include "merchant-database/lookup_login_tokens.h" -#include "merchant-database/lookup_mfa_challenge.h" -#include "merchant-database/lookup_order.h" -#include "merchant-database/lookup_order_by_fulfillment.h" -#include "merchant-database/lookup_order_charity.h" -#include "merchant-database/lookup_order_status.h" -#include "merchant-database/lookup_order_status_by_serial.h" -#include "merchant-database/lookup_order_summary.h" -#include "merchant-database/lookup_orders.h" -#include "merchant-database/lookup_otp_devices.h" -#include "merchant-database/lookup_pending_deposits.h" -#include "merchant-database/lookup_pending_webhooks.h" -#include "merchant-database/lookup_product.h" -#include "merchant-database/lookup_product_image_by_hash.h" -#include "merchant-database/lookup_products.h" -#include "merchant-database/lookup_reconciliation_details.h" -#include "merchant-database/lookup_refund_proof.h" -#include "merchant-database/lookup_refunds.h" -#include "merchant-database/lookup_refunds_detailed.h" -#include "merchant-database/lookup_reports_pending.h" -#include "merchant-database/lookup_spent_tokens_by_order.h" -#include "merchant-database/lookup_statistics_amount_by_bucket.h" -#include "merchant-database/lookup_statistics_amount_by_bucket_range.h" -#include "merchant-database/lookup_statistics_amount_by_interval.h" -#include "merchant-database/lookup_statistics_counter_by_bucket.h" -#include "merchant-database/lookup_statistics_counter_by_bucket_range.h" -#include "merchant-database/lookup_statistics_counter_by_interval.h" -#include "merchant-database/lookup_template.h" -#include "merchant-database/lookup_templates.h" -#include "merchant-database/lookup_token_families.h" -#include "merchant-database/lookup_token_family.h" -#include "merchant-database/lookup_token_family_key.h" -#include "merchant-database/lookup_token_family_keys.h" -#include "merchant-database/lookup_tos_accepted_early.h" -#include "merchant-database/lookup_transfer_details.h" -#include "merchant-database/lookup_transfer_details_by_order.h" -#include "merchant-database/lookup_transfer_summary.h" -#include "merchant-database/lookup_transfers.h" -#include "merchant-database/lookup_units.h" -#include "merchant-database/lookup_webhook.h" -#include "merchant-database/lookup_webhook_by_event.h" -#include "merchant-database/lookup_webhooks.h" -#include "merchant-database/lookup_wire_fee.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_categories.h" +#include "merchant-database/iterate_categories_by_ids.h" +#include "merchant-database/get_contract_terms.h" +#include "merchant-database/get_contract_terms_pos.h" +#include "merchant-database/get_contract_terms_status.h" +#include "merchant-database/iterate_custom_units_by_names.h" +#include "merchant-database/iterate_deposits.h" +#include "merchant-database/iterate_deposits_by_contract_and_coin.h" +#include "merchant-database/iterate_deposits_by_order.h" +#include "merchant-database/get_donau_keys.h" +#include "merchant-database/get_expected_transfer.h" +#include "merchant-database/iterate_expected_transfers.h" +#include "merchant-database/get_instance_auth.h" +#include "merchant-database/iterate_instances.h" +#include "merchant-database/iterate_inventory_products.h" +#include "merchant-database/iterate_inventory_products_filtered.h" +#include "merchant-database/iterate_login_tokens.h" +#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_order_status.h" +#include "merchant-database/get_order_status_by_serial.h" +#include "merchant-database/get_order_summary.h" +#include "merchant-database/iterate_orders.h" +#include "merchant-database/iterate_otp_devices.h" +#include "merchant-database/iterate_pending_deposits.h" +#include "merchant-database/iterate_pending_webhooks.h" +#include "merchant-database/get_product.h" +#include "merchant-database/get_product_image_by_hash.h" +#include "merchant-database/iterate_products.h" +#include "merchant-database/iterate_reconciliation_details.h" +#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/get_template.h" +#include "merchant-database/iterate_templates.h" +#include "merchant-database/iterate_token_families.h" +#include "merchant-database/get_token_family.h" +#include "merchant-database/get_token_family_key.h" +#include "merchant-database/iterate_token_family_keys.h" +#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_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/mark_contract_paid.h" #include "merchant-database/mark_order_wired.h" #include "merchant-database/preflight.h" #include "merchant-database/purge_instance.h" #include "merchant-database/refund_coin.h" -#include "merchant-database/select_account.h" -#include "merchant-database/select_account_by_uri.h" -#include "merchant-database/select_accounts.h" -#include "merchant-database/select_accounts_by_exchange.h" -#include "merchant-database/select_accounts_by_instance.h" -#include "merchant-database/select_all_donau_instances.h" -#include "merchant-database/select_category.h" -#include "merchant-database/select_category_by_name.h" -#include "merchant-database/select_donau_instance_by_serial.h" -#include "merchant-database/select_donau_instances.h" -#include "merchant-database/select_donau_instances_filtered.h" -#include "merchant-database/select_exchange_keys.h" -#include "merchant-database/select_exchanges.h" -#include "merchant-database/select_login_token.h" -#include "merchant-database/select_money_pot.h" -#include "merchant-database/select_money_pots.h" -#include "merchant-database/select_open_transfers.h" -#include "merchant-database/select_order_blinded_sigs.h" -#include "merchant-database/select_otp.h" -#include "merchant-database/select_otp_serial.h" -#include "merchant-database/select_product_groups.h" -#include "merchant-database/select_report.h" -#include "merchant-database/select_reports.h" -#include "merchant-database/select_unit.h" -#include "merchant-database/select_wirewatch_accounts.h" +#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_accounts_by_instance.h" +#include "merchant-database/iterate_all_donau_instances.h" +#include "merchant-database/get_category.h" +#include "merchant-database/get_category_by_name.h" +#include "merchant-database/get_donau_instance_by_serial.h" +#include "merchant-database/iterate_donau_instances.h" +#include "merchant-database/iterate_donau_instances_filtered.h" +#include "merchant-database/get_exchange_keys.h" +#include "merchant-database/iterate_exchanges.h" +#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_product_groups.h" +#include "merchant-database/get_report.h" +#include "merchant-database/iterate_reports.h" +#include "merchant-database/get_unit.h" +#include "merchant-database/iterate_wirewatch_accounts.h" #include "merchant-database/set_instance.h" #include "merchant-database/solve_mfa_challenge.h" #include "merchant-database/start.h" diff --git a/src/include/merchant-database/check_donau_instance.h b/src/include/merchant-database/check_donau_instance.h @@ -1,45 +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/check_donau_instance.h - * @brief implementation of the check_donau_instance function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_CHECK_DONAU_INSTANCE_H -#define MERCHANT_DATABASE_CHECK_DONAU_INSTANCE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Check if information about a Donau instance exists. - * - * @param pg database context - * @param merchant_pub public key of the instance - * @param donau_url URL of the Donau instance - * @param charity_id charity ID of the Donau instance - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_donau_instance (struct TALER_MERCHANTDB_PostgresContext *pg, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const char *donau_url, - uint64_t charity_id - ); - -#endif diff --git a/src/include/merchant-database/check_money_pots.h b/src/include/merchant-database/check_money_pots.h @@ -1,52 +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/check_money_pots.h - * @brief implementation of the check_money_pots function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_CHECK_MONEY_POTS_H -#define MERCHANT_DATABASE_CHECK_MONEY_POTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Check that all of the money pots given exist at the instance, - * returning one that does *not* exist (for generating an error) - * if the check fails. - * - * @param pg database context - * @param instance_id instance to lookup token families for - * @param pots_len length of the @a pots array - * @param pots money pot identifiers to check if they exist - * @param[out] pot_missing set to ID of pot not known at the instance - * @return transaction status, - * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means that all pots exist - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates that - * @a pot_missing was initialized to a missing pot - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_money_pots (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - unsigned int pots_len, - uint64_t pots[static pots_len], - uint64_t *pot_missing); - -#endif diff --git a/src/include/merchant-database/check_report.h b/src/include/merchant-database/check_report.h @@ -1,52 +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/check_report.h - * @brief implementation of the check_report function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_CHECK_REPORT_H -#define MERCHANT_DATABASE_CHECK_REPORT_H - -#include <taler/taler_util.h> -#include "taler/taler_merchant_util.h" -#include "merchantdb_lib.h" - - -/** - * Check that a particular report is scheduled under the - * given @a report_id and @a report_token. Does not - * validate that the report is actually due. - * - * @param pg database context - * @param report_id serial number of the report to lookup - * @param report_token report token to check - * @param mime_type mime type to request from the @a data_source - * @param[out] instance_id instance to lookup reports for - * @param[out] data_source relative URL (to instance base URL) - * to request report data from - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_report ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t report_id, - const struct TALER_MERCHANT_ReportToken *report_token, - const char *mime_type, - char **instance_id, - char **data_source); - -#endif diff --git a/src/include/merchant-database/check_transfer_exists.h b/src/include/merchant-database/check_transfer_exists.h @@ -1,45 +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/check_transfer_exists.h - * @brief implementation of the check_transfer_exists function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_CHECK_TRANSFER_EXISTS_H -#define MERCHANT_DATABASE_CHECK_TRANSFER_EXISTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Check if information about a transfer exists with the - * backend. Returns no data, only the query status. - * - * @param pg database context - * @param instance_id instance to delete transfer of - * @param transfer_serial_id transfer to delete - * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT - * if the transfer record exists - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_check_transfer_exists (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t transfer_serial_id); - -#endif diff --git a/src/include/merchant-database/delete_tos_accepted_early.h b/src/include/merchant-database/delete_tos_accepted_early.h @@ -32,7 +32,7 @@ * of the regular KYC flow (via the ``POST /private/accept-tos-early`` * endpoint). This effectively sets the accepted * ``Taler-Terms-Version`` back to NULL so that a subsequent - * #TALER_MERCHANTDB_lookup_tos_accepted_early returns + * #TALER_MERCHANTDB_get_tos_accepted_early returns * ``GNUNET_DB_STATUS_SUCCESS_NO_RESULTS``. * * @param pg database context diff --git a/src/include/merchant-database/get_account.h b/src/include/merchant-database/get_account.h @@ -0,0 +1,45 @@ +/* + 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_account.h + * @brief implementation of the get_account function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_ACCOUNT_H +#define MERCHANT_DATABASE_GET_ACCOUNT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Obtain information about an instance's accounts. + * + * @param pg database context + * @param id identifier of the instance + * @param h_wire wire hash of the account + * @param[out] ad account details returned + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + const struct TALER_MerchantWireHashP *h_wire, + struct TALER_MERCHANTDB_AccountDetails *ad); + +#endif diff --git a/src/include/merchant-database/get_account_by_uri.h b/src/include/merchant-database/get_account_by_uri.h @@ -0,0 +1,45 @@ +/* + 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_account_by_uri.h + * @brief implementation of the get_account_by_uri function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_ACCOUNT_BY_URI_H +#define MERCHANT_DATABASE_GET_ACCOUNT_BY_URI_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Obtain information about an instance's accounts. + * + * @param pg database context + * @param id identifier of the instance + * @param payto_uri URI of the account + * @param[out] ad account details returned + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account_by_uri (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + struct TALER_FullPayto payto_uri, + struct TALER_MERCHANTDB_AccountDetails *ad); + +#endif diff --git a/src/include/merchant-database/get_account_serial.h b/src/include/merchant-database/get_account_serial.h @@ -0,0 +1,45 @@ +/* + 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_account_serial.h + * @brief implementation of the get_account_serial function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ACCOUNT_SERIAL_H +#define MERCHANT_DATABASE_GET_ACCOUNT_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup account serial by payto URI. + * + * @param pg database context + * @param instance_id instance to lookup the account from + * @param payto_uri what is the merchant's bank account to lookup + * @param[out] account_serial serial number of the account + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_account_serial (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + uint64_t *account_serial); + +#endif diff --git a/src/include/merchant-database/get_category.h b/src/include/merchant-database/get_category.h @@ -0,0 +1,50 @@ +/* + 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/get_category.h + * @brief implementation of the get_category function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_CATEGORY_H +#define MERCHANT_DATABASE_GET_CATEGORY_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about product category. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param category_id category to update + * @param[out] cd set to the category details on success, can be NULL + * (in that case we only want to check if the category exists) + * @param[out] num_products set to length of @a products array + * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it. + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_category (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t category_id, + struct TALER_MERCHANTDB_CategoryDetails *cd, + size_t *num_products, + char **products); + +#endif diff --git a/src/include/merchant-database/get_category_by_name.h b/src/include/merchant-database/get_category_by_name.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/get_category_by_name.h + * @brief implementation of the get_category_by_name function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_CATEGORY_BY_NAME_H +#define MERCHANT_DATABASE_GET_CATEGORY_BY_NAME_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about product category by name. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param category_name category name to look for + * @param[out] name_i18n category name translation + * @param[out] category_id category ID + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_category_by_name (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *category_name, + json_t **name_i18n, + uint64_t *category_id); + +#endif diff --git a/src/include/merchant-database/get_contract_terms.h b/src/include/merchant-database/get_contract_terms.h @@ -0,0 +1,49 @@ +/* + 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_contract_terms.h + * @brief implementation of the get_contract_terms function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_CONTRACT_TERMS_H +#define MERCHANT_DATABASE_GET_CONTRACT_TERMS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order_id used to lookup. + * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number + * @param[out] claim_token set to token to use for access control + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + struct TALER_ClaimTokenP *claim_token); + +#endif diff --git a/src/include/merchant-database/get_contract_terms_pos.h b/src/include/merchant-database/get_contract_terms_pos.h @@ -0,0 +1,56 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/get_contract_terms_pos.h + * @brief implementation of the get_contract_terms_pos function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_CONTRACT_TERMS_POS_H +#define MERCHANT_DATABASE_GET_CONTRACT_TERMS_POS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order_id used to lookup. + * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number + * @param[out] paid set to true if the order is fully paid + * @param[out] claim_token set to the claim token, NULL to only check for existence + * @param[out] pos_key encoded key for payment verification + * @param[out] pos_algorithm algorithm to compute the payment verification + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms_pos ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + struct TALER_ClaimTokenP *claim_token, + char **pos_key, + enum TALER_MerchantConfirmationAlgorithm *pos_algorithm); + +#endif diff --git a/src/include/merchant-database/get_contract_terms_status.h b/src/include/merchant-database/get_contract_terms_status.h @@ -0,0 +1,60 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/get_contract_terms_status.h + * @brief implementation of the get_contract_terms_status function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_CONTRACT_TERMS_STATUS_H +#define MERCHANT_DATABASE_GET_CONTRACT_TERMS_STATUS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order_id used to lookup. + * @param session_id session_id to compare, can be NULL + * @param[out] contract_terms where to store the result, NULL to only check for existence + * @param[out] order_serial set to the order's serial number + * @param[out] paid set to true if the order is fully paid + * @param[out] wired set to true if the exchange wired the funds + * @param[out] session_matches set to true if @a session_id matches session stored for this contract + * @param[out] claim_token set to token to use for access control + * @param[out] choice_index set to the choice index, -1 if not set + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_contract_terms_status ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + const char *session_id, + json_t **contract_terms, + uint64_t *order_serial, + bool *paid, + bool *wired, + bool *session_matches, + struct TALER_ClaimTokenP *claim_token, + int16_t *choice_index); + +#endif diff --git a/src/include/merchant-database/get_donau_instance_by_serial.h b/src/include/merchant-database/get_donau_instance_by_serial.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/get_donau_instance_by_serial.h + * @brief implementation of the get_donau_instance_by_serial function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef MERCHANT_DATABASE_GET_DONAU_INSTANCE_BY_SERIAL_H +#define MERCHANT_DATABASE_GET_DONAU_INSTANCE_BY_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" +#include "donau/donau_util.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Select Donau instance from the database by serial. + * + * @param pg database context + * @param serial the serial of the Donau instance to select + * @param[out] donau_url Donau URL + * @param[out] charity_id charity ID + * @return status of the PG + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_instance_by_serial (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t serial, + char **donau_url, + uint64_t *charity_id); + +#endif diff --git a/src/include/merchant-database/get_donau_keys.h b/src/include/merchant-database/get_donau_keys.h @@ -0,0 +1,49 @@ +/* + 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/get_donau_keys.h + * @brief implementation of the get_donau_keys function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef MERCHANT_DATABASE_GET_DONAU_KEYS_H +#define MERCHANT_DATABASE_GET_DONAU_KEYS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" +#include "donau/donau_service.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve donau's keys from the database. + * + * @param pg database context + * @param donau_url base URL of the exchange + * @param first_retry if the query fails, this is set to the + * time when the next retry should be attempted + * @param[out] keys set to the keys of the exchange + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_donau_keys (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *donau_url, + struct GNUNET_TIME_Absolute *first_retry, + struct DONAU_Keys **keys); + + +#endif diff --git a/src/include/merchant-database/get_exchange_keys.h b/src/include/merchant-database/get_exchange_keys.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_exchange_keys.h + * @brief implementation of the get_exchange_keys function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_EXCHANGE_KEYS_H +#define MERCHANT_DATABASE_GET_EXCHANGE_KEYS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve exchange's keys from the database. + * + * @param pg database context + * @param exchange_url base URL of the exchange + * @param[out] first_retry set to earliest we may retry fetching the keys + * @param[out] keys set to the keys of the exchange + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exchange_keys (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + struct GNUNET_TIME_Absolute *first_retry, + struct TALER_EXCHANGE_Keys **keys); + + +#endif diff --git a/src/include/merchant-database/get_exists_donau_instance.h b/src/include/merchant-database/get_exists_donau_instance.h @@ -0,0 +1,45 @@ +/* + 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_exists_donau_instance.h + * @brief implementation of the get_exists_donau_instance function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_EXISTS_DONAU_INSTANCE_H +#define MERCHANT_DATABASE_GET_EXISTS_DONAU_INSTANCE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Check if information about a Donau instance exists. + * + * @param pg database context + * @param merchant_pub public key of the instance + * @param donau_url URL of the Donau instance + * @param charity_id charity ID of the Donau instance + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exists_donau_instance (struct TALER_MERCHANTDB_PostgresContext *pg, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const char *donau_url, + uint64_t charity_id + ); + +#endif diff --git a/src/include/merchant-database/get_exists_transfer.h b/src/include/merchant-database/get_exists_transfer.h @@ -0,0 +1,45 @@ +/* + 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_exists_transfer.h + * @brief implementation of the get_exists_transfer function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_EXISTS_TRANSFER_H +#define MERCHANT_DATABASE_GET_EXISTS_TRANSFER_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Check if information about a transfer exists with the + * backend. Returns no data, only the query status. + * + * @param pg database context + * @param instance_id instance to delete transfer of + * @param transfer_serial_id transfer to delete + * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT + * if the transfer record exists + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_exists_transfer (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t transfer_serial_id); + +#endif diff --git a/src/include/merchant-database/get_expected_transfer.h b/src/include/merchant-database/get_expected_transfer.h @@ -0,0 +1,60 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/get_expected_transfer.h + * @brief implementation of the get_expected_transfer function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_EXPECTED_TRANSFER_H +#define MERCHANT_DATABASE_GET_EXPECTED_TRANSFER_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Obtain information about an expected incoming wire transfer. + * + * @param pg database context + * @param instance_id instance to lookup payments for + * @param expected_incoming_serial serial number of the transfer + * @param[out] expected_time expected date of the transfer + * @param[out] expected_credit_amount expected amount to be credited + * @param[out] wtid expected wire transfer subject + * @param[out] payto_uri target bank account + * @param[out] exchange_url URL of the exchange + * @param[out] execution_time set to 0 if unknown + * @param[out] confirmed set if the transfer was confirmed + * @param[out] master_pub master public key of the exchange + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_expected_transfer (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t expected_incoming_serial, + struct GNUNET_TIME_Timestamp *expected_time, + struct TALER_Amount *expected_credit_amount, + struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto *payto_uri, + char **exchange_url, + struct GNUNET_TIME_Timestamp *execution_time, + bool *confirmed, + struct TALER_MasterPublicKeyP *master_pub); + + +#endif diff --git a/src/include/merchant-database/get_instance_auth.h b/src/include/merchant-database/get_instance_auth.h @@ -0,0 +1,42 @@ +/* + 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_instance_auth.h + * @brief implementation of the get_instance_auth function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_INSTANCE_AUTH_H +#define MERCHANT_DATABASE_GET_INSTANCE_AUTH_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup authentication data of an instance. + * + * @param pg database context + * @param instance_id instance to query + * @param[out] ias where to store the auth data + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_instance_auth (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_MERCHANTDB_InstanceAuthSettings *ias); + +#endif diff --git a/src/include/merchant-database/get_login_token.h b/src/include/merchant-database/get_login_token.h @@ -0,0 +1,48 @@ +/* + 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_login_token.h + * @brief implementation of the get_login_token function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_LOGIN_TOKEN_H +#define MERCHANT_DATABASE_GET_LOGIN_TOKEN_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup information about a login token from database. + * + * @param pg database context + * @param id identifier of the instance + * @param token value of the token + * @param[out] expiration_time set to expiration time + * @param[out] validity_scope set to scope of the token + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_login_token (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + const struct TALER_MERCHANTDB_LoginTokenP *token, + struct GNUNET_TIME_Timestamp *expiration_time, + uint32_t *validity_scope); + + +#endif diff --git a/src/include/merchant-database/get_mfa_challenge.h b/src/include/merchant-database/get_mfa_challenge.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/get_mfa_challenge.h + * @brief implementation of the get_mfa_challenge function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_MFA_CHALLENGE_H +#define MERCHANT_DATABASE_GET_MFA_CHALLENGE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Check if a new multi-factor authorization (MFA) challenge + * matching the body exists in the database. + * + * @param pg database context + * @param challenge_id set to the ID of the challenge + * @param h_body hash of the request body + * @param[out] salt salt used to compute @a h_body + * @param[out] required_address set to where the challenge is to be send + * @param[out] op operation that triggered the MFA request + * @param[out] confirmation_date when was the challenge solved, + * set to "GNUNET_TIME_ABSOLUTE_NEVER" if unsolved + * @param[out] retransmission_date set to when a fresh challenge + * may be transmitted + * @param[out] retry_counter set to the number of attempts that remain + * for solving the challenge (after this time) + * @param[out] tan_channel which channel was used + * @param[out] instance_name name of the instance for which the + * challenge is being issued + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_mfa_challenge (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t challenge_id, + const struct TALER_MERCHANT_MFA_BodyHash *h_body, + struct TALER_MERCHANT_MFA_BodySalt *salt, + char **required_address, + enum TALER_MERCHANT_MFA_CriticalOperation *op, + struct GNUNET_TIME_Absolute *confirmation_date, + struct GNUNET_TIME_Absolute *retransmission_date, + uint32_t *retry_counter, + enum TALER_MERCHANT_MFA_Channel *tan_channel, + char **instance_name); + + +#endif diff --git a/src/include/merchant-database/get_missing_money_pot.h b/src/include/merchant-database/get_missing_money_pot.h @@ -0,0 +1,52 @@ +/* + 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_missing_money_pot.h + * @brief implementation of the get_missing_money_pot function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_MISSING_MONEY_POT_H +#define MERCHANT_DATABASE_GET_MISSING_MONEY_POT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Check that all of the money pots given exist at the instance, + * returning one that does *not* exist (for generating an error) + * if the check fails. + * + * @param pg database context + * @param instance_id instance to lookup token families for + * @param pots_len length of the @a pots array + * @param pots money pot identifiers to check if they exist + * @param[out] pot_missing set to ID of pot not known at the instance + * @return transaction status, + * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means that all pots exist + * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT indicates that + * @a pot_missing was initialized to a missing pot + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_missing_money_pot (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + unsigned int pots_len, + uint64_t pots[static pots_len], + uint64_t *pot_missing); + +#endif diff --git a/src/include/merchant-database/get_money_pot.h b/src/include/merchant-database/get_money_pot.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/get_money_pot.h + * @brief implementation of the get_money_pot function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_MONEY_POT_H +#define MERCHANT_DATABASE_GET_MONEY_POT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about a particular money pot. + * + * @param pg database context + * @param instance_id instance to lookup token family for + * @param money_pot_id serial number of the pot to lookup + * @param [out] name set to name of the pot + * @param[out] description set to description of the pot + * @param[out] pot_total_len set to length of @a pot_totals + * @param[out] pot_totals set to amount currently in the pot + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_money_pot (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t money_pot_id, + char **name, + char **description, + size_t *pot_total_len, + struct TALER_Amount **pot_totals); + +#endif diff --git a/src/include/merchant-database/get_order.h b/src/include/merchant-database/get_order.h @@ -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/include/merchant-database/get_order.h + * @brief implementation of the get_order function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ORDER_H +#define MERCHANT_DATABASE_GET_ORDER_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve order given its @a order_id and the @a instance_id. + * + * @param pg database context + * @param instance_id instance to obtain order of + * @param order_id order id used to perform the lookup + * @param[out] claim_token the claim token generated for the order, + * NULL to only test if the order exists + * @param[out] h_post_data set to the hash of the POST data that created the order + * @param[out] contract_terms where to store the retrieved contract terms, + * NULL to only test if the order exists + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct TALER_ClaimTokenP *claim_token, + struct TALER_MerchantPostDataHashP *h_post_data, + json_t **contract_terms); + +#endif diff --git a/src/include/merchant-database/get_order_by_fulfillment.h b/src/include/merchant-database/get_order_by_fulfillment.h @@ -0,0 +1,51 @@ +/* + 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_order_by_fulfillment.h + * @brief implementation of the get_order_by_fulfillment function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ORDER_BY_FULFILLMENT_H +#define MERCHANT_DATABASE_GET_ORDER_BY_FULFILLMENT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve the order ID that was used to pay for a resource within a session. + * + * @param pg database context + * @param instance_id identifying the instance + * @param fulfillment_url URL that canonically identifies the resource + * being paid for + * @param session_id session id + * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection + * @param[out] order_id where to store the order ID that was used when + * paying for the resource URL + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_by_fulfillment (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *fulfillment_url, + const char *session_id, + bool allow_refunded_for_repurchase, + char **order_id); + +#endif diff --git a/src/include/merchant-database/get_order_charity.h b/src/include/merchant-database/get_order_charity.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_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_order_status.h b/src/include/merchant-database/get_order_status.h @@ -0,0 +1,47 @@ +/* + 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_order_status.h + * @brief implementation of the get_order_status function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ORDER_STATUS_H +#define MERCHANT_DATABASE_GET_ORDER_STATUS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_id + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_id order to lookup contract for + * @param[out] h_contract_terms set to the hash of the contract. + * @param[out] paid set to the payment status of the contract + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_status (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct TALER_PrivateContractHashP *h_contract_terms, + bool *paid); + +#endif diff --git a/src/include/merchant-database/get_order_status_by_serial.h b/src/include/merchant-database/get_order_status_by_serial.h @@ -0,0 +1,50 @@ +/* + 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_order_status_by_serial.h + * @brief implementation of the get_order_status_by_serial function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ORDER_STATUS_BY_SERIAL_H +#define MERCHANT_DATABASE_GET_ORDER_STATUS_BY_SERIAL_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve contract terms given its @a order_serial + * + * @param pg database context + * @param instance_id instance's identifier + * @param order_serial serial ID of the order to look up + * @param[out] order_id set to ID of the order + * @param[out] h_contract_terms set to the hash of the contract. + * @param[out] paid set to the payment status of the contract + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_status_by_serial (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t order_serial, + char **order_id, + struct TALER_PrivateContractHashP * + h_contract_terms, + bool *paid); + +#endif diff --git a/src/include/merchant-database/get_order_summary.h b/src/include/merchant-database/get_order_summary.h @@ -0,0 +1,47 @@ +/* + 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_order_summary.h + * @brief implementation of the get_order_summary function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_ORDER_SUMMARY_H +#define MERCHANT_DATABASE_GET_ORDER_SUMMARY_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Retrieve order summary given its @a order_id and the @a instance_id. + * + * @param pg database context + * @param instance_id instance to obtain order of + * @param order_id order id used to perform the lookup + * @param[out] timestamp when was the order created + * @param[out] order_serial under which serial do we keep this order + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_order_summary (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *order_id, + struct GNUNET_TIME_Timestamp *timestamp, + uint64_t *order_serial); + +#endif diff --git a/src/include/merchant-database/get_otp.h b/src/include/merchant-database/get_otp.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.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_serial.h b/src/include/merchant-database/get_otp_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_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_product.h b/src/include/merchant-database/get_product.h @@ -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/include/merchant-database/get_product.h + * @brief implementation of the get_product function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_PRODUCT_H +#define MERCHANT_DATABASE_GET_PRODUCT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Lookup details about a particular product. + * + * @param pg database context + * @param instance_id instance to lookup products for + * @param product_id product to lookup + * @param[out] pd set to the product details on success, can be NULL + * (in that case we only want to check if the product exists) + * @param[out] num_categories set to length of @a categories array + * @param[out] categories set to array of categories the + * product is in, caller must free() it. + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_product ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *product_id, + struct TALER_MERCHANTDB_ProductDetails *pd, + size_t *num_categories, + uint64_t **categories); + +#endif diff --git a/src/include/merchant-database/get_product_image_by_hash.h b/src/include/merchant-database/get_product_image_by_hash.h @@ -0,0 +1,34 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file src/include/merchant-database/get_product_image_by_hash.h + * @brief declaration of lookup_product_image_by_hash for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_GET_PRODUCT_IMAGE_BY_HASH_H +#define MERCHANT_DATABASE_GET_PRODUCT_IMAGE_BY_HASH_H + +#include "merchantdb_lib.h" + + +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_product_image_by_hash ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *image_hash, + char **image); + +#endif diff --git a/src/include/merchant-database/get_refund_proof.h b/src/include/merchant-database/get_refund_proof.h @@ -0,0 +1,45 @@ +/* + 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_refund_proof.h + * @brief implementation of the get_refund_proof function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_REFUND_PROOF_H +#define MERCHANT_DATABASE_GET_REFUND_PROOF_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup refund proof data. + * + * @param pg database context + * @param refund_serial serial number of the refund + * @param[out] exchange_sig set to signature from exchange + * @param[out] exchange_pub signing key that was used for @a exchange_sig + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_refund_proof (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t refund_serial, + struct TALER_ExchangeSignatureP *exchange_sig, + struct TALER_ExchangePublicKeyP *exchange_pub); + +#endif diff --git a/src/include/merchant-database/get_report.h b/src/include/merchant-database/get_report.h @@ -0,0 +1,66 @@ +/* + 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_report.h + * @brief implementation of the get_report function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_REPORT_H +#define MERCHANT_DATABASE_GET_REPORT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about a particular report. + * + * @param pg database context + * @param instance_id instance to lookup reports for + * @param report_id serial number of the report to lookup + * @param[out] report_program_section configuration section of program + * for report generation + * @param[out] report_description text describing the report + * @param[out] mime_type mime type to request from the @a data_source + * @param[out] data_source relative URL (to instance base URL) + * to request report data from + * @param[out] target_address where to send report data + * @param[out] frequency report frequency + * @param[out] frequency_shift how much to shift the report time from a + * multiple of the report @a frequency + * @param[out] next_transmission when will the report be generated next + * @param[out] last_error_code status of the last report + * @param[out] last_error_detail details about failures of last generation + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_report (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t report_id, + char **report_program_section, + char **report_description, + char **mime_type, + char **data_source, + char **target_address, + struct GNUNET_TIME_Relative *frequency, + struct GNUNET_TIME_Relative *frequency_shift, + struct GNUNET_TIME_Absolute *next_transmission, + enum TALER_ErrorCode *last_error_code, + char **last_error_detail); + +#endif diff --git a/src/include/merchant-database/get_report_by_token.h b/src/include/merchant-database/get_report_by_token.h @@ -0,0 +1,52 @@ +/* + 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_report_by_token.h + * @brief implementation of the get_report_by_token function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_REPORT_BY_TOKEN_H +#define MERCHANT_DATABASE_GET_REPORT_BY_TOKEN_H + +#include <taler/taler_util.h> +#include "taler/taler_merchant_util.h" +#include "merchantdb_lib.h" + + +/** + * Check that a particular report is scheduled under the + * given @a report_id and @a report_token. Does not + * validate that the report is actually due. + * + * @param pg database context + * @param report_id serial number of the report to lookup + * @param report_token report token to check + * @param mime_type mime type to request from the @a data_source + * @param[out] instance_id instance to lookup reports for + * @param[out] data_source relative URL (to instance base URL) + * to request report data from + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_report_by_token ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t report_id, + const struct TALER_MERCHANT_ReportToken *report_token, + const char *mime_type, + char **instance_id, + char **data_source); + +#endif diff --git a/src/include/merchant-database/get_template.h b/src/include/merchant-database/get_template.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_template.h + * @brief implementation of the get_template function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_TEMPLATE_H +#define MERCHANT_DATABASE_GET_TEMPLATE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Lookup details about a particular template. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param template_id template to lookup + * @param[out] td set to the template details on success + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_template ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *template_id, + struct TALER_MERCHANTDB_TemplateDetails *td); + + +#endif diff --git a/src/include/merchant-database/get_token_family.h b/src/include/merchant-database/get_token_family.h @@ -0,0 +1,47 @@ +/* + 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_token_family.h + * @brief implementation of the get_token_family function for Postgres + * @author Christian Blättler + */ +#ifndef MERCHANT_DATABASE_GET_TOKEN_FAMILY_H +#define MERCHANT_DATABASE_GET_TOKEN_FAMILY_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about a particular token family. + * + * @param pg database context + * @param instance_id instance to lookup token family for + * @param token_family_slug token family to lookup + * @param[out] details set to the token family details on success, can be NULL + * (in that case we only want to check if the token family exists) + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_token_family (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct TALER_MERCHANTDB_TokenFamilyDetails *details) +; + +#endif diff --git a/src/include/merchant-database/get_token_family_key.h b/src/include/merchant-database/get_token_family_key.h @@ -0,0 +1,92 @@ +/* + 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/get_token_family_key.h + * @brief implementation of the get_token_family_key function for Postgres + * @author Christian Blättler + */ +#ifndef MERCHANT_DATABASE_GET_TOKEN_FAMILY_KEY_H +#define MERCHANT_DATABASE_GET_TOKEN_FAMILY_KEY_H + +#include <gnunet/gnunet_common.h> +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Details about a token key. + */ +struct TALER_MERCHANTDB_TokenFamilyKeyDetails +{ + /** + * Tokens signed with this key are valid from this date on. + * This is the time the key was created. + */ + struct GNUNET_TIME_Timestamp signature_validity_start; + + /** + * Tokens signed with this key are valid until this date. + */ + struct GNUNET_TIME_Timestamp signature_validity_end; + + /** + * Private key expires for use at this time. Signatures can + * only be created until this point. + */ + struct GNUNET_TIME_Timestamp private_key_deleted_at; + + /** + * Token family public key. + */ + struct TALER_TokenIssuePublicKey pub; + + /** + * Token family private key. + */ + struct TALER_TokenIssuePrivateKey priv; + + /** + * Details about the token family this key belongs to. + */ + struct TALER_MERCHANTDB_TokenFamilyDetails token_family; +}; + + +/** + * Lookup details about a particular token family key. The valid_after field + * of the key has to be >= @e min_valid_after and < @e max_valid_after. + * + * @param pg database context + * @param instance_id instance to lookup token family key for + * @param token_family_slug slug of token family to lookup + * @param valid_at find a key with a validity period that includes this time + * @param sign_until find a private key that can sign until this time + * @param[out] details set to the token family key details on success, can be NULL + * (in that case we only want to check if the token family key exists) + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_token_family_key ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct GNUNET_TIME_Timestamp valid_at, + struct GNUNET_TIME_Timestamp sign_until, + struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); + + +#endif diff --git a/src/include/merchant-database/get_tos_accepted_early.h b/src/include/merchant-database/get_tos_accepted_early.h @@ -0,0 +1,54 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/get_tos_accepted_early.h + * @brief implementation of the get_tos_accepted_early function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_GET_TOS_ACCEPTED_EARLY_H +#define MERCHANT_DATABASE_GET_TOS_ACCEPTED_EARLY_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; + +/** + * Look up the ``Taler-Terms-Version`` of the terms of + * service that the user has accepted early for a given + * exchange (via the ``POST /private/accept-tos-early`` + * endpoint). + * + * @param pg database context + * @param merchant_id merchant backend instance ID + * @param exchange_url base URL of the exchange to look up + * @param[out] tos_version set to a newly allocated string with the + * accepted ``Taler-Terms-Version``; caller must @a GNUNET_free + * it. Set to NULL if no acceptance is on record for this + * @a exchange_url, in which case the query status will be + * ``GNUNET_DB_STATUS_SUCCESS_NO_RESULTS``. + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_tos_accepted_early ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *merchant_id, + const char *exchange_url, + char **tos_version); + +#endif diff --git a/src/include/merchant-database/get_unit.h b/src/include/merchant-database/get_unit.h @@ -0,0 +1,45 @@ +/* + 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_unit.h + * @brief implementation of the get_unit function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_GET_UNIT_H +#define MERCHANT_DATABASE_GET_UNIT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup a measurement unit by identifier. + * + * @param pg database context + * @param instance_id instance owning the unit + * @param unit_id symbolic identifier + * @param[out] ud unit details on success; may be NULL to test for existence + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_unit (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *unit_id, + struct TALER_MERCHANTDB_UnitDetails *ud); + +#endif diff --git a/src/include/merchant-database/get_webhook.h b/src/include/merchant-database/get_webhook.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/get_webhook.h + * @brief implementation of the get_webhook function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_GET_WEBHOOK_H +#define MERCHANT_DATABASE_GET_WEBHOOK_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/** + * Lookup details about a particular webhook. + * + * @param pg database context + * @param instance_id instance to lookup webhook for + * @param webhook_id webhook to lookup + * @param[out] wb set to the webhook details on success, can be NULL + * (in that case we only want to check if the webhook exists) + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_get_webhook (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *webhook_id, + struct TALER_MERCHANTDB_WebhookDetails *wb); + +#endif diff --git a/src/include/merchant-database/get_wire_fee.h b/src/include/merchant-database/get_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_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/iterate_accounts.h b/src/include/merchant-database/iterate_accounts.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/iterate_accounts.h + * @brief implementation of the iterate_accounts function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_ACCOUNTS_H +#define MERCHANT_DATABASE_ITERATE_ACCOUNTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Callback invoked with information about a bank account. + * + * @param cls closure + * @param merchant_priv private key of the merchant instance + * @param ad details about the account + */ +typedef void +(*TALER_MERCHANTDB_AccountCallback)( + void *cls, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_AccountDetails *ad); + + +/** + * Obtain information about an instance's accounts. + * + * @param pg database context + * @param cb function to call on each account + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_AccountCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_accounts_by_exchange.h b/src/include/merchant-database/iterate_accounts_by_exchange.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_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_accounts_by_instance.h b/src/include/merchant-database/iterate_accounts_by_instance.h @@ -0,0 +1,58 @@ +/* + 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_instance.h + * @brief implementation of the iterate_accounts_by_instance function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_ACCOUNTS_BY_INSTANCE_H +#define MERCHANT_DATABASE_ITERATE_ACCOUNTS_BY_INSTANCE_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Callback invoked with information about a bank account. + * + * @param cls closure + * @param merchant_priv private key of the merchant instance + * @param ad details about the account + */ +typedef void +(*TALER_MERCHANTDB_AccountCallback)( + void *cls, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_AccountDetails *ad); + +/** + * Obtain information about an instance's accounts. + * + * @param pg database context + * @param id identifier of the instance + * @param cb function to call on each account + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_accounts_by_instance ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + TALER_MERCHANTDB_AccountCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_all_donau_instances.h b/src/include/merchant-database/iterate_all_donau_instances.h @@ -0,0 +1,75 @@ +/* + 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_all_donau_instances.h + * @brief implementation of the iterate_all_donau_instances function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef MERCHANT_DATABASE_ITERATE_ALL_DONAU_INSTANCES_H +#define MERCHANT_DATABASE_ITERATE_ALL_DONAU_INSTANCES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "donau/donau_util.h" +#include "merchantdb_lib.h" + + +/** + * Callback function typically used by `select_donau_instances` to handle + * the details of each Donau instance retrieved from the database. + * + * @param cls Closure to pass additional context or data to the callback function. + * @param donau_instance_serial Serial number of the Donau instance in the merchant database. + * @param donau_url The URL of the Donau instance. + * @param charity_name The name of the charity associated with the Donau instance. + * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. + * @param charity_id The unique identifier for the charity within the Donau instance. + * @param charity_max_per_year Maximum allowed donations to the charity for the current year. + * @param charity_receipts_to_date Total donations received by the charity so far in the current year. + * @param current_year The year for which the donation data is being tracked. + * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available. + */ +typedef void +(*TALER_MERCHANTDB_DonauInstanceCallback)( + void *cls, + uint64_t donau_instance_serial, + const char *donau_url, + const char *charity_name, + const struct DONAU_CharityPublicKeyP *charity_pub_key, + uint64_t charity_id, + const struct TALER_Amount *charity_max_per_year, + const struct TALER_Amount *charity_receipts_to_date, + int64_t current_year, + const json_t *donau_keys_json + ); + +/** + * Select all Donau instances from the database, regardless + * of instance or key status. + * + * @param pg database context + * @param cb callback function to call with each result + * @param cb_cls closure for the callback + * @return status of the PG + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_all_donau_instances ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_all_products.h b/src/include/merchant-database/iterate_all_products.h @@ -0,0 +1,65 @@ +/* + 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_all_products.h + * @brief implementation of the iterate_all_products function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_ALL_PRODUCTS_H +#define MERCHANT_DATABASE_ITERATE_ALL_PRODUCTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_all_products`. + * + * @param cls a `json_t *` JSON array to build + * @param product_serial row ID of the product + * @param product_id ID of the product + * @param pd full product details + * @param num_categories length of @a categories array + * @param categories array of categories the + * product is in + */ +typedef void +(*TALER_MERCHANTDB_ProductCallback)( + void *cls, + uint64_t product_serial, + const char *product_id, + const struct TALER_MERCHANTDB_ProductDetails *pd, + size_t num_categories, + const uint64_t *categories); + +/** + * Lookup all of the products the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup products for + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_all_products ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_ProductCallback 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 @@ -0,0 +1,73 @@ +/* + 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_categories.h b/src/include/merchant-database/iterate_categories.h @@ -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/include/merchant-database/iterate_categories.h + * @brief implementation of the iterate_categories function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_CATEGORIES_H +#define MERCHANT_DATABASE_ITERATE_CATEGORIES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_categories`. + * + * @param cls closure + * @param category_id ID of the category + * @param category_name name of the category + * @param category_name_i18n translations of the @a category_name + * @param product_count number of products in the category + */ +typedef void +(*TALER_MERCHANTDB_CategoriesCallback)( + void *cls, + uint64_t category_id, + const char *category_name, + const json_t *category_name_i18n, + uint64_t product_count); + + +/** + * Lookup all of the product categories the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup OTP devices for + * @param cb function to call on all categories found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_categories ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_CategoriesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_categories_by_ids.h b/src/include/merchant-database/iterate_categories_by_ids.h @@ -0,0 +1,64 @@ +/* + 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_categories_by_ids.h + * @brief Lookup product categories by ID + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_CATEGORIES_BY_IDS_H +#define MERCHANT_DATABASE_ITERATE_CATEGORIES_BY_IDS_H + +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_categories`. + * + * @param cls closure + * @param category_id ID of the category + * @param category_name name of the category + * @param category_name_i18n translations of the @a category_name + * @param product_count number of products in the category + */ +typedef void +(*TALER_MERCHANTDB_CategoriesCallback)( + void *cls, + uint64_t category_id, + const char *category_name, + const json_t *category_name_i18n, + uint64_t product_count); + +/** + * Lookup product categories by ID. + * + * @param pg database context + * @param instance_id instance to lookup categories for + * @param category_ids array of category IDs + * @param num_category_ids length of @a category_ids + * @param cb function to call on all categories found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_categories_by_ids ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const uint64_t *category_ids, + size_t num_category_ids, + TALER_MERCHANTDB_CategoriesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_custom_units_by_names.h b/src/include/merchant-database/iterate_custom_units_by_names.h @@ -0,0 +1,62 @@ +/* + 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_custom_units_by_names.h + * @brief Lookup custom measurement units by name + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_CUSTOM_UNITS_BY_NAMES_H +#define MERCHANT_DATABASE_ITERATE_CUSTOM_UNITS_BY_NAMES_H + +#include <taler/taler_util.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Typically called by `lookup_units`. + * + * @param cls closure + * @param unit_serial database identifier + * @param ud measurement unit details (borrowed) + */ +typedef void +(*TALER_MERCHANTDB_UnitsCallback)( + void *cls, + uint64_t unit_serial, + const struct TALER_MERCHANTDB_UnitDetails *ud); + +/** + * Lookup custom measurement units by name. + * + * @param pg database context + * @param instance_id instance to fetch units for + * @param units array of unit identifiers + * @param num_units length of @a units + * @param cb function to call with each unit + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_custom_units_by_names (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *const *units, + size_t num_units, + TALER_MERCHANTDB_UnitsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_deposits.h b/src/include/merchant-database/iterate_deposits.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_deposits.h + * @brief implementation of the iterate_deposits function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_DEPOSITS_H +#define MERCHANT_DATABASE_ITERATE_DEPOSITS_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 a coin that was deposited. + * + * @param cls closure + * @param exchange_url exchange where @a coin_pub was deposited + * @param coin_pub public key of the coin + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin + * @param refund_fee fee the exchange will charge for refunding this coin + * @param wire_fee fee the exchange will charge for the wire transfer + */ +typedef void +(*TALER_MERCHANTDB_DepositsCallback)( + void *cls, + const char *exchange_url, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const struct TALER_Amount *refund_fee, + const struct TALER_Amount *wire_fee); + +/** + * Lookup information about coins that were successfully deposited for a + * given contract. + * + * @param pg database context + * @param instance_id instance to lookup deposits for + * @param h_contract_terms proposal data's hashcode + * @param cb function to call with payment data + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct + TALER_PrivateContractHashP *h_contract_terms, + TALER_MERCHANTDB_DepositsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_deposits_by_contract_and_coin.h b/src/include/merchant-database/iterate_deposits_by_contract_and_coin.h @@ -0,0 +1,80 @@ +/* + 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_deposits_by_contract_and_coin.h + * @brief implementation of the iterate_deposits_by_contract_and_coin function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_DEPOSITS_BY_CONTRACT_AND_COIN_H +#define MERCHANT_DATABASE_ITERATE_DEPOSITS_BY_CONTRACT_AND_COIN_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a coin that was deposited. + * + * @param cls closure + * @param exchange_url URL of the exchange that issued the coin + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin + * @param refund_fee fee the exchange will charge for refunding this coin + * @param wire_fee wire fee the exchange charges + * @param h_wire hash of merchant's wire details + * @param deposit_timestamp when did the exchange receive the deposit + * @param refund_deadline until when are refunds allowed + * @param exchange_sig signature by the exchange + * @param exchange_pub exchange signing key used for @a exchange_sig + */ +typedef void +(*TALER_MERCHANTDB_CoinDepositCallback)( + void *cls, + const char *exchange_url, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const struct TALER_Amount *refund_fee, + const struct TALER_Amount *wire_fee, + const struct TALER_MerchantWireHashP *h_wire, + struct GNUNET_TIME_Timestamp deposit_timestamp, + struct GNUNET_TIME_Timestamp refund_deadline, + const struct TALER_ExchangeSignatureP *exchange_sig, + const struct TALER_ExchangePublicKeyP *exchange_pub); + + +/** + * Lookup information about coin payments by @a h_contract_terms and + * @a coin_pub. + * + * @param pg database context + * @param instance_id instance to lookup payments for + * @param h_contract_terms proposal data's hashcode + * @param coin_pub public key to use for the search + * @param cb function to call with payment data + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits_by_contract_and_coin ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_deposits_by_order.h b/src/include/merchant-database/iterate_deposits_by_order.h @@ -0,0 +1,68 @@ +/* + 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_deposits_by_order.h + * @brief implementation of the iterate_deposits_by_order function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_DEPOSITS_BY_ORDER_H +#define MERCHANT_DATABASE_ITERATE_DEPOSITS_BY_ORDER_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a coin that was deposited. + * + * @param cls closure + * @param deposit_serial which deposit operation is this about + * @param exchange_url URL of the exchange that issued the coin + * @param h_wire hash of merchant's wire details + * @param deposit_timestamp when was the deposit made + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin + * @param coin_pub public key of the coin + */ +typedef void +(*TALER_MERCHANTDB_DepositedCoinsCallback)( + void *cls, + uint64_t deposit_serial, + const char *exchange_url, + const struct TALER_MerchantWireHashP *h_wire, + struct GNUNET_TIME_Timestamp deposit_timestamp, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const struct TALER_CoinSpendPublicKeyP *coin_pub); + +/** + * Retrieve details about coins that were deposited for an order. + * + * @param pg database context + * @param order_serial identifies the order + * @param cb function to call for each deposited coin + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_deposits_by_order ( + struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_DepositedCoinsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_donau_instances.h b/src/include/merchant-database/iterate_donau_instances.h @@ -0,0 +1,76 @@ +/* + 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_donau_instances.h + * @brief implementation of the iterate_donau_instances function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_H +#define MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Callback function typically used by `select_donau_instances` to handle + * the details of each Donau instance retrieved from the database. + * + * @param cls Closure to pass additional context or data to the callback function. + * @param donau_instance_serial Serial number of the Donau instance in the merchant database. + * @param donau_url The URL of the Donau instance. + * @param charity_name The name of the charity associated with the Donau instance. + * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. + * @param charity_id The unique identifier for the charity within the Donau instance. + * @param charity_max_per_year Maximum allowed donations to the charity for the current year. + * @param charity_receipts_to_date Total donations received by the charity so far in the current year. + * @param current_year The year for which the donation data is being tracked. + * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available. + */ +typedef void +(*TALER_MERCHANTDB_DonauInstanceCallback)( + void *cls, + uint64_t donau_instance_serial, + const char *donau_url, + const char *charity_name, + const struct DONAU_CharityPublicKeyP *charity_pub_key, + uint64_t charity_id, + const struct TALER_Amount *charity_max_per_year, + const struct TALER_Amount *charity_receipts_to_date, + int64_t current_year, + const json_t *donau_keys_json + ); + +/** + * Select Donau instances from the database. + * + * @param pg database context + * @param id the ID of the merchant instance, NULL for all instances + * @param cb callback function to call with each result + * @param cb_cls closure for the callback + * @return status of the PG + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_donau_instances (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + TALER_MERCHANTDB_DonauInstanceCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_donau_instances_filtered.h b/src/include/merchant-database/iterate_donau_instances_filtered.h @@ -0,0 +1,62 @@ +/* + 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_donau_instances_filtered.h + * @brief implementation of the iterate_donau_instances_filtered function for Postgres + * @author Bohdan Potuzhnyi + * @author Vlada Svirsh + */ +#ifndef MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_FILTERED_H +#define MERCHANT_DATABASE_ITERATE_DONAU_INSTANCES_FILTERED_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" +#include "donau/donau_util.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Callback function typically used by `select_donau_instances` to handle + * the details of each Donau instance retrieved from the database. + * + * @param cls Closure to pass additional context or data to the callback function. + * @param donau_url The URL of the Donau instance. + */ +typedef void +(*TALER_MERCHANTDB_DonauInstanceFilteredCallback)( + void *cls, + const char *donau_url + ); + +/** + * Select multiple Donau instances from the database. + * + * @param pg database context + * @param currency currency to filter donau instances by + * @param cb callback function to call with each result + * @param cb_cls closure for the callback + * @return status of the PG + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_donau_instances_filtered (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *currency, + TALER_MERCHANTDB_DonauInstanceFilteredCallback cb + , + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_exchanges.h b/src/include/merchant-database/iterate_exchanges.h @@ -0,0 +1,67 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/iterate_exchanges.h + * @brief implementation of the iterate_exchanges function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_EXCHANGES_H +#define MERCHANT_DATABASE_ITERATE_EXCHANGES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called about the ``/keys`` status of every exchange + * we are working with. + * + * @param cls closure + * @param exchange_url base URL of the exchange + * @param keys keys of the exchange, NULL if we do not have any yet + * @param next_download when will be the next download + * @param keys_expiration when does the current ``/keys`` response expire + * @param http_status last HTTP status from ``/keys`` + * @param ec last error code from fetching ``/keys`` + */ +typedef void +(*TALER_MERCHANTDB_ExchangesCallback)( + void *cls, + const char *exchange_url, + const json_t *keys, + struct GNUNET_TIME_Absolute next_download, + struct GNUNET_TIME_Absolute keys_expiration, + unsigned int http_status, + enum TALER_ErrorCode ec); + + +/** + * Call @a cb on each exchange we have in the database. + * + * @param pg database context + * @param cb callback to invoke + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_exchanges ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_ExchangesCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_expected_transfers.h b/src/include/merchant-database/iterate_expected_transfers.h @@ -0,0 +1,93 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/iterate_expected_transfers.h + * @brief implementation of the iterate_expected_transfers function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_EXPECTED_TRANSFERS_H +#define MERCHANT_DATABASE_ITERATE_EXPECTED_TRANSFERS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about expected incoming wire transfers. + * + * @param cls closure with a `json_t *` array to build up the response + * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown + * @param wtid wire transfer identifier + * @param payto_uri target account that received the wire transfer + * @param exchange_url base URL of the exchange that made the wire transfer + * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend + * @param execution_time when did the exchange claim to have made the transfer + * @param confirmed true if the merchant confirmed this wire transfer + * false if it is so far only claimed to have been made by the exchange + * @param validated true if the reconciliation succeeded + * @param last_http_status HTTP status of our last request to the exchange for this transfer + * @param last_ec last error code we got back (otherwise #TALER_EC_NONE) + * @param last_error_detail last detail we got back (or NULL for none) + */ +typedef void +(*TALER_MERCHANTDB_IncomingCallback)( + void *cls, + const struct TALER_Amount *expected_credit_amount, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto payto_uri, + const char *exchange_url, + uint64_t expected_transfer_serial_id, + struct GNUNET_TIME_Timestamp execution_time, + bool confirmed, + bool validated, + unsigned int last_http_status, + enum TALER_ErrorCode last_ec, + const char *last_error_detail); + +/** + * Lookup expected incoming transfers. + * + * @param pg database context + * @param instance_id instance to lookup payments for + * @param payto_uri account that we are interested in transfers to + * @param before timestamp for the earliest transfer we care about + * @param after timestamp for the last transfer we care about + * @param limit number of entries to return, negative for descending in execution time, + * positive for ascending in execution time + * @param offset expected_transfer_serial number of the transfer we want to offset from + * @param confirmed filter by confirmation status + * @param verified filter by verification status + * @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_expected_transfers ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + struct GNUNET_TIME_Timestamp before, + struct GNUNET_TIME_Timestamp after, + int64_t limit, + uint64_t offset, + enum TALER_EXCHANGE_YesNoAll confirmed, + enum TALER_EXCHANGE_YesNoAll verified, + TALER_MERCHANTDB_IncomingCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_instances.h b/src/include/merchant-database/iterate_instances.h @@ -0,0 +1,78 @@ +/* + 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_instances.h + * @brief implementation of the iterate_instances function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_INSTANCES_H +#define MERCHANT_DATABASE_ITERATE_INSTANCES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + +/** + * Typically called by `lookup_instances`. + * + * @param cls closure + * @param merchant_pub public key of the instance + * @param merchant_priv private key of the instance, NULL if not available + * @param is general instance settings + * @param ias instance authentication settings + */ +typedef void +(*TALER_MERCHANTDB_InstanceCallback)( + void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_InstanceSettings *is, + const struct TALER_MERCHANTDB_InstanceAuthSettings *ias); + +/** + * Lookup all of the instances this backend has configured. + * + * @param pg database context + * @param active_only only find 'active' instances + * @param cb function to call on all instances found + * @param cb_cls closure for @a cb + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_instances ( + struct TALER_MERCHANTDB_PostgresContext *pg, + bool active_only, + TALER_MERCHANTDB_InstanceCallback cb, + void *cb_cls); + + +/** + * Lookup one of the instances this backend has configured. + * + * @param pg database context + * @param id instance ID to resolve + * @param active_only only find 'active' instances + * @param cb function to call on all instances found + * @param cb_cls closure for @a cb + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_instances_by_id ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *id, + bool active_only, + TALER_MERCHANTDB_InstanceCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_inventory_products.h b/src/include/merchant-database/iterate_inventory_products.h @@ -0,0 +1,62 @@ +/* + 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_inventory_products.h + * @brief Lookup inventory product details for templates + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_H +#define MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_H + +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Typically called by `lookup_inventory_products`. + * + * @param cls a `json_t *` JSON array to build + * @param product_id ID of the product + * @param pd inventory product details + * @param num_categories length of @a categories array + * @param categories array of categories the + * product is in + */ +typedef void +(*TALER_MERCHANTDB_InventoryProductCallback)( + void *cls, + const char *product_id, + const struct TALER_MERCHANTDB_InventoryProductDetails *pd, + size_t num_categories, + const uint64_t *categories); + +/** + * Lookup inventory details for all products of an instance. + * + * @param pg database context + * @param instance_id instance to lookup products for + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_inventory_products (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_InventoryProductCallback cb, + void *cb_cls); + +#endif /* MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_H */ diff --git a/src/include/merchant-database/iterate_inventory_products_filtered.h b/src/include/merchant-database/iterate_inventory_products_filtered.h @@ -0,0 +1,70 @@ +/* + 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_inventory_products_filtered.h + * @brief Lookup inventory product details for templates (filtered) + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_FILTERED_H +#define MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_FILTERED_H + +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Typically called by `lookup_inventory_products`. + * + * @param cls a `json_t *` JSON array to build + * @param product_id ID of the product + * @param pd inventory product details + * @param num_categories length of @a categories array + * @param categories array of categories the + * product is in + */ +typedef void +(*TALER_MERCHANTDB_InventoryProductCallback)( + void *cls, + const char *product_id, + const struct TALER_MERCHANTDB_InventoryProductDetails *pd, + size_t num_categories, + const uint64_t *categories); + +/** + * Lookup inventory details for a subset of products. + * + * @param pg database context + * @param instance_id instance to lookup products for + * @param product_ids product IDs to include (can be NULL/empty) + * @param num_product_ids number of entries in @a product_ids + * @param categories category IDs to include (can be NULL/empty) + * @param num_categories number of entries in @a categories + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_inventory_products_filtered (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *const *product_ids, + size_t num_product_ids, + const uint64_t *categories, + size_t num_categories, + TALER_MERCHANTDB_InventoryProductCallback cb, + void *cb_cls); + +#endif /* MERCHANT_DATABASE_ITERATE_INVENTORY_PRODUCTS_FILTERED_H */ diff --git a/src/include/merchant-database/iterate_login_tokens.h b/src/include/merchant-database/iterate_login_tokens.h @@ -0,0 +1,69 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/iterate_login_tokens.h + * @brief implementation of the iterate_login_tokens function for Postgres + * @author Martin Schanzenbach + */ +#ifndef MERCHANT_DATABASE_ITERATE_LOGIN_TOKENS_H +#define MERCHANT_DATABASE_ITERATE_LOGIN_TOKENS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_login_tokens`. + * + * @param cls a `json_t *` JSON array to build + * @param creation_time creation time of the token + * @param expiration_time expiration time of the token + * @param scope validity scope of the token + * @param description description of the token + * @param serial serial number of the token + */ +typedef void +(*TALER_MERCHANTDB_LoginTokensCallback)( + void *cls, + struct GNUNET_TIME_Timestamp creation_time, + struct GNUNET_TIME_Timestamp expiration_time, + uint32_t scope, + const char *description, + uint64_t serial); + +/** + * Lookup all of the tokens the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup tokens for + * @param offset transfer_serial number of the transfer we want to offset from + * @param limit number of entries to return, negative for descending, + * positive for ascending + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_login_tokens ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t offset, + int64_t limit, + TALER_MERCHANTDB_LoginTokensCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_money_pots.h b/src/include/merchant-database/iterate_money_pots.h @@ -0,0 +1,66 @@ +/* + 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_money_pots.h + * @brief implementation of the iterate_money_pots function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_MONEY_POTS_H +#define MERCHANT_DATABASE_ITERATE_MONEY_POTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `select_money_pots`. + * + * @param cls closure + * @param name set to name of the pot + * @param pot_total_len length of @a pot_totals array + * @param pot_totals amounts currently in the pot + */ +typedef void +(*TALER_MERCHANTDB_MoneyPotsCallback)( + void *cls, + uint64_t money_pot_id, + const char *name, + size_t pot_total_len, + const struct TALER_Amount *pot_totals); + +/** + * Lookup all of the money pots the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup token families for + * @param limit number of entries to return, negative for descending in execution time, + * positive for ascending in execution time + * @param offset expected_transfer_serial number of the transfer we want to offset from + * @param cb function to call on all money pots found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_money_pots ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_MoneyPotsCallback 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 @@ -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_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 @@ -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_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_orders.h b/src/include/merchant-database/iterate_orders.h @@ -0,0 +1,121 @@ +/* + 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_orders.h + * @brief implementation of the iterate_orders function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_ORDERS_H +#define MERCHANT_DATABASE_ITERATE_ORDERS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Filter preferences. + */ +struct TALER_MERCHANTDB_OrderFilter +{ + /** + * Filter orders by this fulfillment URL. + */ + const char *fulfillment_url; + + /** + * Filter orders by this session ID. + */ + const char *session_id; + + /** + * Filter by payment status. + */ + enum TALER_EXCHANGE_YesNoAll paid; + + /** + * Filter by refund status. + */ + enum TALER_EXCHANGE_YesNoAll refunded; + + /** + * Filter by wire transfer status. + */ + enum TALER_EXCHANGE_YesNoAll wired; + + /** + * Filter orders by date, exact meaning depends on @e delta. + */ + struct GNUNET_TIME_Timestamp date; + + /** + * Filter orders by order serial number, exact meaning depends on @e delta. + */ + uint64_t start_row; + + /** + * takes value of the form N (-N), so that at most N values strictly older + * (younger) than start and date are returned. + */ + int64_t delta; + + /** + * Timeout for long-polling. + */ + struct GNUNET_TIME_Relative timeout; + + /** + * Filter to apply on the summary of the order. + */ + const char *summary_filter; + +}; + + +/** + * Typically called by `lookup_orders`. + * + * @param cls a `json_t *` JSON array to build + * @param order_id ID of the order + * @param order_serial row of the order in the database + * @param timestamp creation time of the order in the database + */ +typedef void +(*TALER_MERCHANTDB_OrdersCallback)( + void *cls, + const char *order_id, + uint64_t order_serial, + struct GNUNET_TIME_Timestamp timestamp); + +/** + * Retrieve orders given the @a instance_id. + * + * @param pg database context + * @param instance_id instance to obtain order of + * @param of filter to apply when looking up orders + * @param cb callback to pass all the orders that are found + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_orders ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_MERCHANTDB_OrderFilter *of, + TALER_MERCHANTDB_OrdersCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_otp_devices.h b/src/include/merchant-database/iterate_otp_devices.h @@ -0,0 +1,60 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/iterate_otp_devices.h + * @brief implementation of the iterate_otp_devices function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_OTP_DEVICES_H +#define MERCHANT_DATABASE_ITERATE_OTP_DEVICES_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 `lookup_otp_devices`. + * + * @param cls closure + * @param otp_id ID of the OTP device + * @param otp_description description of the OTP device + */ +typedef void +(*TALER_MERCHANTDB_OtpDeviceCallback)( + void *cls, + const char *otp_id, + const char *otp_description); + +/** + * Lookup all of the OTP devices the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup OTP devices for + * @param cb function to call on all OTP devices found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_otp_devices (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_OtpDeviceCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_pending_deposits.h b/src/include/merchant-database/iterate_pending_deposits.h @@ -0,0 +1,80 @@ +/* + 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_deposits.h + * @brief implementation of the iterate_pending_deposits function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_PENDING_DEPOSITS_H +#define MERCHANT_DATABASE_ITERATE_PENDING_DEPOSITS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +struct TALER_MERCHANTDB_PostgresContext; +/* Callback typedefs */ +/** + * Callback for results from `lookup_pending_deposits`. + * + * @param cls NULL + * @param deposit_serial identifies the deposit operation + * @param wire_deadline when is the wire due + * @param retry_time when to next try the exchange again + * @param h_contract_terms hash of the contract terms + * @param merchant_priv private key of the merchant + * @param instance_id name of the instance + * @param h_wire hash of the merchant's wire account into + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin which the deposit was made + * @param coin_pub public key of the deposited coin + */ +typedef void +(*TALER_MERCHANTDB_PendingDepositsCallback) ( + void *cls, + uint64_t deposit_serial, + struct GNUNET_TIME_Absolute wire_deadline, + struct GNUNET_TIME_Absolute retry_time, + const struct TALER_PrivateContractHashP *h_contract_terms, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const char *instance_id, + const struct TALER_MerchantWireHashP *h_wire, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const struct TALER_CoinSpendPublicKeyP *coin_pub); + +/** + * Lookup deposits that are finished and awaiting a wire transfer. + * + * @param pg database context + * @param exchange_url exchange to filter deposits by + * @param limit maximum number of deposits to return + * @param allow_future true to allow deposits with wire deadline in the future + * @param cb function to call with deposit data + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_deposits (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + uint64_t limit, + bool allow_future, + TALER_MERCHANTDB_PendingDepositsCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_pending_webhooks.h b/src/include/merchant-database/iterate_pending_webhooks.h @@ -0,0 +1,88 @@ +/* + 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.h + * @brief implementation of the iterate_pending_webhooks function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_PENDING_WEBHOOKS_H +#define MERCHANT_DATABASE_ITERATE_PENDING_WEBHOOKS_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 `lookup_pending_webhooks`. + * + * @param cls a `json_t *` JSON array to build + * @param webhook_pending_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_PendingWebhooksCallback)( + void *cls, + uint64_t webhook_pending_serial, + struct GNUNET_TIME_Absolute + next_attempt, + uint32_t retries, + const char *url, + const char *http_method, + const char *header, + const char *body); + +/** + * Lookup the webhook that need to be send in priority. + * send. + * + * @param pg database context + * @param limit maximum number of webhooks to return + * @param cb pending webhook callback + * @param cb_cls callback closure + */ +// WHERE next_attempt <= now ORDER BY next_attempt ASC LIMIT limit +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_webhooks (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t limit, + TALER_MERCHANTDB_PendingWebhooksCallback cb, + void *cb_cls); + + +/** + * Lookup the next webhook in the pending webhooks that needs to be + * sent. With that we can know how long the system can 'sleep'. + * + * @param pg database context + * @param cb pending webhook callback + * @param cb_cls callback closure + */ +// ORDER BY next_attempt ASC LIMIT 1 +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_pending_webhooks_next ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_PendingWebhooksCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_product_groups.h b/src/include/merchant-database/iterate_product_groups.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_product_groups.h + * @brief implementation of the iterate_product_groups function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_PRODUCT_GROUPS_H +#define MERCHANT_DATABASE_ITERATE_PRODUCT_GROUPS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `select_product_groups`. + * + * @param cls closure + * @param product_group_id ID of the product group + * @param group_name set to name of the group + * @param group_description set to description of the group + */ +typedef void +(*TALER_MERCHANTDB_ProductGroupsCallback)( + void *cls, + uint64_t product_group_id, + const char *group_name, + const char *group_description); + + +/** + * Lookup all of the product groups the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup product groups for + * @param limit number of entries to return, negative for descending in execution time, + * positive for ascending in execution time + * @param offset expected_transfer_serial number of the transfer we want to offset from + * @param cb function to call on all groups found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_product_groups ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_ProductGroupsCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_products.h b/src/include/merchant-database/iterate_products.h @@ -0,0 +1,91 @@ +/* + 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_products.h + * @brief implementation of the iterate_products function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_PRODUCTS_H +#define MERCHANT_DATABASE_ITERATE_PRODUCTS_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 `lookup_products`. + * + * @param cls a `json_t *` JSON array to build + * @param product_serial row ID of the product + * @param product_id ID of the product + */ +typedef void +(*TALER_MERCHANTDB_ProductsCallback)( + void *cls, + uint64_t product_serial, + const char *product_id); + +/** + * Lookup all of the products the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup products for + * @param offset transfer_serial number of the transfer we want to offset from + * @param limit number of entries to return, negative for descending, + * positive for ascending + * @param category_filter filter products by category, NULL to not filter; + * uses the Postgresql "LIKE" pattern matcher, so + * "%" stands for any sequence of zero or more characters, + * "_" stands for any single character; + * use "\%" and "\_" to exactly match "%" or "_". + * We will always use case-insensitive searches, for case-sensitive + * matching the client should filter the result set. + * @param name_filter filter products by name, NULL to not filter + * uses the Postgresql "LIKE" pattern matcher, so + * "%" stands for any sequence of zero or more characters, + * "_" stands for any single character + * use "\%" and "\_" to exactly match "%" or "_". + * We will always use case-insensitive searches, for case-sensitive + * matching the client should filter the result set. + * @param description_filter filter products by description, NULL to not filter + * uses the Postgresql "LIKE" pattern matcher, so + * "%" stands for any sequence of zero or more characters, + * "_" stands for any single character + * use "\%" and "\_" to exactly match "%" or "_". + * We will always use case-insensitive searches, for case-sensitive + * matching the client should filter the result set. + * @param product_group_id_filter only return products in where the + * product group ID matches the given ID, 0 to not filter + * @param cb function to call on all products found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_products (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t offset, + int64_t limit, + const char *category_filter, + const char *name_filter, + const char *description_filter, + uint64_t product_group_id_filter, + TALER_MERCHANTDB_ProductsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_reconciliation_details.h b/src/include/merchant-database/iterate_reconciliation_details.h @@ -0,0 +1,66 @@ +/* + This file is part of TALER + Copyright (C) 2026 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file src/include/merchant-database/iterate_reconciliation_details.h + * @brief implementation of the iterate_reconciliation_details function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_RECONCILIATION_DETAILS_H +#define MERCHANT_DATABASE_ITERATE_RECONCILIATION_DETAILS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function returning reconciliation details for an + * expected incoming wire transfer. + * Called by `lookup_reconciliation_details`. + * + * @param cls closure + * @param order_id order that was paid and then aggregated + * @param remaining_deposit deposited amount minus any refunds + * @param deposit_fee deposit fees paid to the exchange for the order + */ +typedef void +(*TALER_MERCHANTDB_ReconciliationDetailsCallback)( + void *cls, + const char *order_id, + const struct TALER_Amount *remaining_deposit, + const struct TALER_Amount *deposit_fee); + + +/** + * Obtain reconciliation details for an expected incoming wire transfer. + * + * @param pg database context + * @param instance_id instance to lookup payments for + * @param expected_incoming_serial serial number of the transfer + * @param cb callback to invoke + * @param cb_cls closure for @a cb + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_reconciliation_details ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + uint64_t expected_incoming_serial, + TALER_MERCHANTDB_ReconciliationDetailsCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_refunds.h b/src/include/merchant-database/iterate_refunds.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_refunds.h + * @brief implementation of the iterate_refunds function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_REFUNDS_H +#define MERCHANT_DATABASE_ITERATE_REFUNDS_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 a refund. + * + * @param cls closure + * @param coin_pub public coin from which the refund comes from + * @param refund_amount refund amount which is being taken from @a coin_pub + */ +typedef void +(*TALER_MERCHANTDB_RefundCallback)( + void *cls, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *refund_amount); + +/** + * Obtain refunds associated with a contract. + * + * @param pg database context + * @param instance_id instance to lookup refunds for + * @param h_contract_terms hash code of the contract + * @param rc function to call for each coin on which there is a refund + * @param rc_cls closure for @a rc + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_refunds (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms, + TALER_MERCHANTDB_RefundCallback rc, + void *rc_cls); + +#endif diff --git a/src/include/merchant-database/iterate_refunds_detailed.h b/src/include/merchant-database/iterate_refunds_detailed.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_refunds_detailed.h + * @brief implementation of the iterate_refunds_detailed function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_REFUNDS_DETAILED_H +#define MERCHANT_DATABASE_ITERATE_REFUNDS_DETAILED_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 detailed information about a refund. + * + * @param cls closure + * @param refund_serial unique serial number of the refund + * @param timestamp time of the refund (for grouping of refunds in the wallet UI) + * @param coin_pub public coin from which the refund comes from + * @param exchange_url URL of the exchange that issued @a coin_pub + * @param rtransaction_id identificator of the refund + * @param reason human-readable explanation of the refund + * @param refund_amount refund amount which is being taken from @a coin_pub + * @param pending true if the this refund was not yet processed by the wallet/exchange + */ +typedef void +(*TALER_MERCHANTDB_RefundDetailCallback)( + void *cls, + uint64_t refund_serial, + struct GNUNET_TIME_Timestamp timestamp, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const char *exchange_url, + uint64_t rtransaction_id, + const char *reason, + const struct TALER_Amount *refund_amount, + bool pending); + +/** + * Obtain detailed refund data associated with a contract. + * + * @param pg database context + * @param instance_id instance to lookup refunds for + * @param h_contract_terms hash code of the contract + * @param rc function to call for each coin on which there is a refund + * @param rc_cls closure for @a rc + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_refunds_detailed (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const struct TALER_PrivateContractHashP *h_contract_terms + , + TALER_MERCHANTDB_RefundDetailCallback rc, + void *rc_cls); + +#endif diff --git a/src/include/merchant-database/iterate_reports.h b/src/include/merchant-database/iterate_reports.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_reports.h + * @brief implementation of the iterate_reports function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_REPORTS_H +#define MERCHANT_DATABASE_ITERATE_REPORTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `select_reports`. + * + * @param cls closure + * @param report_id ID of the report + * @param report_description description of the report + * @param frequency the report frequency + */ +typedef void +(*TALER_MERCHANTDB_ReportsCallback)( + void *cls, + uint64_t report_id, + const char *report_description, + struct GNUNET_TIME_Relative frequency); + + +/** + * Lookup all of the reports the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup reports for + * @param limit number of entries to return, negative for descending in execution time, + * positive for ascending in execution time + * @param offset expected_transfer_serial number of the transfer we want to offset from + * @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 ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + int64_t limit, + uint64_t offset, + TALER_MERCHANTDB_ReportsCallback 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 @@ -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_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 @@ -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_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_statistics_amount_by_bucket.h b/src/include/merchant-database/iterate_statistics_amount_by_bucket.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_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 @@ -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_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 @@ -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_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 @@ -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_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 @@ -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_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 @@ -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_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_templates.h b/src/include/merchant-database/iterate_templates.h @@ -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/include/merchant-database/iterate_templates.h + * @brief implementation of the iterate_templates function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_TEMPLATES_H +#define MERCHANT_DATABASE_ITERATE_TEMPLATES_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 `lookup_templates`. + * + * @param cls closure + * @param template_id ID of the template + * @param template_description description of the template + */ +typedef void +(*TALER_MERCHANTDB_TemplatesCallback)( + void *cls, + const char *template_id, + const char *template_description); + +/** + * Lookup all of the templates the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup template for + * @param cb function to call on all template found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_templates (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_TemplatesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_token_families.h b/src/include/merchant-database/iterate_token_families.h @@ -0,0 +1,67 @@ +/* + 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_token_families.h + * @brief implementation of the iterate_token_families function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_TOKEN_FAMILIES_H +#define MERCHANT_DATABASE_ITERATE_TOKEN_FAMILIES_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + +/** + * Typically called by `lookup_token_families`. + * + * @param cls closure + * @param slug slug of the token family + * @param name name of the token family + * @param description description of the token family + * @param description_i18n Internationalized token family description. + * @param start_time start time of the token family's validity period + * @param expiration end time of the token family's validity period + * @param kind kind of the token family + */ +typedef void +(*TALER_MERCHANTDB_TokenFamiliesCallback)( + void *cls, + const char *slug, + const char *name, + const char *description, + const json_t *description_i18n, + struct GNUNET_TIME_Timestamp start_time, + struct GNUNET_TIME_Timestamp expiration, + const char *kind); + +/** + * Lookup all of the token families the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup token families for + * @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_token_families ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_TokenFamiliesCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_token_family_keys.h b/src/include/merchant-database/iterate_token_family_keys.h @@ -0,0 +1,65 @@ +/* + 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_token_family_keys.h + * @brief implementation of the iterate_token_family_keys function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_TOKEN_FAMILY_KEYS_H +#define MERCHANT_DATABASE_ITERATE_TOKEN_FAMILY_KEYS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" +#include "merchant-database/get_token_family_key.h" + + +/** + * Function called with applicable token keys. + * + * @param cls closure + * @param details details about an applicable key + */ +typedef void +(*TALER_MERCHANTDB_TokenKeyCallback) ( + void *cls, + const struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); + + +/** + * Lookup token family keys that may be used for a payment. + * + * @param pg database context + * @param instance_id instance to lookup token family key for + * @param token_family_slug slug of token family to lookup + * @param start_time signature validity start the keys must fall into + * @param end_time signature validity end the keys must fall into + * @param cb function to call with each matching key + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_token_family_keys ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *token_family_slug, + struct GNUNET_TIME_Timestamp start_time, + struct GNUNET_TIME_Timestamp end_time, + TALER_MERCHANTDB_TokenKeyCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/iterate_transfer_details.h b/src/include/merchant-database/iterate_transfer_details.h @@ -0,0 +1,63 @@ +/* + 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_details.h + * @brief implementation of the iterate_transfer_details function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_TRANSFER_DETAILS_H +#define MERCHANT_DATABASE_ITERATE_TRANSFER_DETAILS_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 detailed information about a wire transfer and + * the underlying deposits that are being aggregated. + * + * @param cls closure + * @param current_offset offset in the exchange reply we are at + * @param ttd details about the transfer at @a current_offset + */ +typedef void +(*TALER_MERCHANTDB_TransferDetailsCallback)( + void *cls, + unsigned int current_offset, + const struct TALER_TrackTransferDetails *ttd); + +/** + * Lookup transfer details. + * + * @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_details (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *exchange_url, + const struct TALER_WireTransferIdentifierRawP * + wtid, + TALER_MERCHANTDB_TransferDetailsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_transfer_details_by_order.h b/src/include/merchant-database/iterate_transfer_details_by_order.h @@ -0,0 +1,73 @@ +/* + 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_details_by_order.h + * @brief implementation of the iterate_transfer_details_by_order function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_TRANSFER_DETAILS_BY_ORDER_H +#define MERCHANT_DATABASE_ITERATE_TRANSFER_DETAILS_BY_ORDER_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 `lookup_transfer_details_by_order`. + * + * @param cls closure + * @param wtid wire transfer subject of the wire transfer for the coin + * @param exchange_url base URL of the exchange that made the payment + * @param execution_time when was the payment made + * @param deposit_value contribution of the coin to the total wire transfer value + * @param deposit_fee deposit fee charged by the exchange for the coin + * @param transfer_confirmed did the merchant confirm that a wire transfer with + * @a wtid over the total amount happened? + * @param expected_credit_serial row of the expected wire transfer, usable + * as ``offset`` for the ``/private/incoming`` endpoint + */ +typedef void +(*TALER_MERCHANTDB_OrderTransferDetailsCallback)( + void *cls, + const struct TALER_WireTransferIdentifierRawP *wtid, + const char *exchange_url, + struct GNUNET_TIME_Timestamp execution_time, + const struct TALER_Amount *deposit_value, + const struct TALER_Amount *deposit_fee, + bool transfer_confirmed, + uint64_t expected_credit_serial); + +/** + * Retrieve wire transfer details for all deposits associated with + * a given @a order_serial. + * + * @param pg database context + * @param order_serial identifies the order + * @param cb function called with the wire transfer details + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_transfer_details_by_order (struct TALER_MERCHANTDB_PostgresContext *pg, + uint64_t order_serial, + TALER_MERCHANTDB_OrderTransferDetailsCallback + 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 @@ -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_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_transfers.h b/src/include/merchant-database/iterate_transfers.h @@ -0,0 +1,88 @@ +/* + 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_transfers.h + * @brief implementation of the iterate_transfers function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_TRANSFERS_H +#define MERCHANT_DATABASE_ITERATE_TRANSFERS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a wire transfer. + * + * @param cls closure with a `json_t *` array to build up the response + * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown + * @param wtid wire transfer identifier + * @param payto_uri target account that received the wire transfer + * @param exchange_url base URL of the exchange that made the wire transfer + * @param transfer_serial_id serial number identifying the transfer in the backend + * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend, 0 if not @a expected + * @param execution_time when did the exchange make the transfer, #GNUNET_TIME_UNIT_FOREVER_ABS + * if it did not yet happen + * @param expected true if the merchant acknowledged the wire transfer reception + */ +typedef void +(*TALER_MERCHANTDB_TransferCallback)( + void *cls, + const struct TALER_Amount *expected_credit_amount, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto payto_uri, + const char *exchange_url, + uint64_t transfer_serial_id, + uint64_t expected_transfer_serial_id, + struct GNUNET_TIME_Absolute execution_time, + bool expected); + +/** + * Lookup transfers. Note that filtering by @a verified status is done + * outside of SQL, as we already have 8 prepared statements and adding + * a filter on verified would further double the number of statements for + * a likely rather ineffective filter. So we apply that filter in + * #lookup_transfers_cb(). + * + * @param pg database context + * @param instance_id instance to lookup payments for + * @param payto_uri account that we are interested in transfers to + * @param before timestamp for the earliest transfer we care about + * @param after timestamp for the last transfer we care about + * @param limit number of entries to return, negative for descending in execution time, + * positive for ascending in execution time + * @param offset transfer_serial number of the transfer we want to offset from + * @param expected filter for transfers that were expected + * @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_transfers ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + struct TALER_FullPayto payto_uri, + struct GNUNET_TIME_Timestamp before, + struct GNUNET_TIME_Timestamp after, + int64_t limit, + uint64_t offset, + enum TALER_EXCHANGE_YesNoAll expected, + TALER_MERCHANTDB_TransferCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_units.h b/src/include/merchant-database/iterate_units.h @@ -0,0 +1,59 @@ +/* + 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_units.h + * @brief implementation of the iterate_units function for Postgres + * @author Bohdan Potuzhnyi + */ +#ifndef MERCHANT_DATABASE_ITERATE_UNITS_H +#define MERCHANT_DATABASE_ITERATE_UNITS_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 `lookup_units`. + * + * @param cls closure + * @param unit_serial database identifier + * @param ud measurement unit details (borrowed) + */ +typedef void +(*TALER_MERCHANTDB_UnitsCallback)( + void *cls, + uint64_t unit_serial, + const struct TALER_MERCHANTDB_UnitDetails *ud); + +/** + * Lookup all measurement units for an instance. + * + * @param pg database context + * @param instance_id instance to fetch units for + * @param cb function to call with each unit + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_units (struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_UnitsCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_webhooks.h b/src/include/merchant-database/iterate_webhooks.h @@ -0,0 +1,58 @@ +/* + 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_webhooks.h + * @brief implementation of the iterate_webhooks function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_WEBHOOKS_H +#define MERCHANT_DATABASE_ITERATE_WEBHOOKS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_webhooks`. + * + * @param cls a `json_t *` JSON array to build + * @param webhook_id ID of the webhook + * @param event_type event of the webhook + */ +typedef void +(*TALER_MERCHANTDB_WebhooksCallback)( + void *cls, + const char *webhook_id, + const char *event_type); + +/** + * Lookup all of the webhooks the given instance has configured. + * + * @param pg database context + * @param instance_id instance to lookup webhook for + * @param cb function to call on all webhook found + * @param cb_cls closure for @a cb + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_webhooks ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + TALER_MERCHANTDB_WebhooksCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_webhooks_by_event.h b/src/include/merchant-database/iterate_webhooks_by_event.h @@ -0,0 +1,68 @@ +/* + 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_webhooks_by_event.h + * @brief implementation of the iterate_webhooks_by_event function for Postgres + * @author Iván Ávalos + */ +#ifndef MERCHANT_DATABASE_ITERATE_WEBHOOKS_BY_EVENT_H +#define MERCHANT_DATABASE_ITERATE_WEBHOOKS_BY_EVENT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Typically called by `lookup_webhook_by_event`. + * + * @param cls a `json_t *` JSON array to build + * @param webhook_serial reference to the configured webhook template. + * @param event_type which type of event triggers this type of webhook + * @param url the HTTP URL to make the webhook request to + * @param http_method HTTP method use for the webhook + * @param header_template template for the header of the webhook + * @param body_template template for the body of the webhook + */ +typedef void +(*TALER_MERCHANTDB_WebhookDetailCallback)( + void *cls, + uint64_t webhook_serial, + const char *event_type, + const char *url, + const char *http_method, + const char *header_template, + const char *body_template); + +/** + * Lookup webhook by event + * + * @param pg database context + * @param instance_id instance to lookup webhook for + * @param event_type event that we need to put in the pending webhook + * @param[out] cb set to the webhook details on success + * @param cb_cls callback closure + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_webhooks_by_event ( + struct TALER_MERCHANTDB_PostgresContext *pg, + const char *instance_id, + const char *event_type, + TALER_MERCHANTDB_WebhookDetailCallback cb, + void *cb_cls); + +#endif diff --git a/src/include/merchant-database/iterate_wirewatch_accounts.h b/src/include/merchant-database/iterate_wirewatch_accounts.h @@ -0,0 +1,64 @@ +/* + 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_wirewatch_accounts.h + * @brief implementation of the iterate_wirewatch_accounts function for Postgres + * @author Christian Grothoff + */ +#ifndef MERCHANT_DATABASE_ITERATE_WIREWATCH_ACCOUNTS_H +#define MERCHANT_DATABASE_ITERATE_WIREWATCH_ACCOUNTS_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "merchantdb_lib.h" + + +/** + * Function called with information about a accounts + * the wirewatcher should monitor. + * + * @param cls closure + * @param instance instance that owns the account + * @param payto_uri account URI + * @param credit_facade_url URL for the credit facade + * @param credit_facade_credentials account access credentials + * @param last_serial last transaction serial (inclusive) we have seen from this account + */ +typedef void +(*TALER_MERCHANTDB_WirewatchWorkCallback)( + void *cls, + const char *instance, + struct TALER_FullPayto payto_uri, + const char *credit_facade_url, + const json_t *credit_facade_credentials, + uint64_t last_serial); + +/** + * Select information about progress made by taler-merchant-wirewatch. + * + * @param pg database context + * @param cb function to call with results + * @param cb_cls closure for @a cb + * @return transaction status + */ +enum GNUNET_DB_QueryStatus +TALER_MERCHANTDB_iterate_wirewatch_accounts ( + struct TALER_MERCHANTDB_PostgresContext *pg, + TALER_MERCHANTDB_WirewatchWorkCallback cb, + void *cb_cls); + + +#endif diff --git a/src/include/merchant-database/lookup_account.h b/src/include/merchant-database/lookup_account.h @@ -1,45 +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/lookup_account.h - * @brief implementation of the lookup_account function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ACCOUNT_H -#define MERCHANT_DATABASE_LOOKUP_ACCOUNT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup account serial by payto URI. - * - * @param pg database context - * @param instance_id instance to lookup the account from - * @param payto_uri what is the merchant's bank account to lookup - * @param[out] account_serial serial number of the account - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_account (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - uint64_t *account_serial); - -#endif diff --git a/src/include/merchant-database/lookup_all_products.h b/src/include/merchant-database/lookup_all_products.h @@ -1,65 +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/lookup_all_products.h - * @brief implementation of the lookup_all_products function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ALL_PRODUCTS_H -#define MERCHANT_DATABASE_LOOKUP_ALL_PRODUCTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_all_products`. - * - * @param cls a `json_t *` JSON array to build - * @param product_serial row ID of the product - * @param product_id ID of the product - * @param pd full product details - * @param num_categories length of @a categories array - * @param categories array of categories the - * product is in - */ -typedef void -(*TALER_MERCHANTDB_ProductCallback)( - void *cls, - uint64_t product_serial, - const char *product_id, - const struct TALER_MERCHANTDB_ProductDetails *pd, - size_t num_categories, - const uint64_t *categories); - -/** - * Lookup all of the products the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup products for - * @param cb function to call on all products found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_all_products ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_ProductCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_all_webhooks.h b/src/include/merchant-database/lookup_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/lookup_all_webhooks.h - * @brief implementation of the lookup_all_webhooks function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ALL_WEBHOOKS_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_categories.h b/src/include/merchant-database/lookup_categories.h @@ -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/include/merchant-database/lookup_categories.h - * @brief implementation of the lookup_categories function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CATEGORIES_H -#define MERCHANT_DATABASE_LOOKUP_CATEGORIES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_categories`. - * - * @param cls closure - * @param category_id ID of the category - * @param category_name name of the category - * @param category_name_i18n translations of the @a category_name - * @param product_count number of products in the category - */ -typedef void -(*TALER_MERCHANTDB_CategoriesCallback)( - void *cls, - uint64_t category_id, - const char *category_name, - const json_t *category_name_i18n, - uint64_t product_count); - - -/** - * Lookup all of the product categories the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup OTP devices for - * @param cb function to call on all categories found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_categories ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_CategoriesCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_categories_by_ids.h b/src/include/merchant-database/lookup_categories_by_ids.h @@ -1,64 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_categories_by_ids.h - * @brief Lookup product categories by ID - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CATEGORIES_BY_IDS_H -#define MERCHANT_DATABASE_LOOKUP_CATEGORIES_BY_IDS_H - -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_categories`. - * - * @param cls closure - * @param category_id ID of the category - * @param category_name name of the category - * @param category_name_i18n translations of the @a category_name - * @param product_count number of products in the category - */ -typedef void -(*TALER_MERCHANTDB_CategoriesCallback)( - void *cls, - uint64_t category_id, - const char *category_name, - const json_t *category_name_i18n, - uint64_t product_count); - -/** - * Lookup product categories by ID. - * - * @param pg database context - * @param instance_id instance to lookup categories for - * @param category_ids array of category IDs - * @param num_category_ids length of @a category_ids - * @param cb function to call on all categories found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_categories_by_ids ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const uint64_t *category_ids, - size_t num_category_ids, - TALER_MERCHANTDB_CategoriesCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_contract_terms.h b/src/include/merchant-database/lookup_contract_terms.h @@ -1,49 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_contract_terms.h - * @brief implementation of the lookup_contract_terms function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_H -#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order_id used to lookup. - * @param[out] contract_terms where to store the result, NULL to only check for existence - * @param[out] order_serial set to the order's serial number - * @param[out] claim_token set to token to use for access control - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - struct TALER_ClaimTokenP *claim_token); - -#endif diff --git a/src/include/merchant-database/lookup_contract_terms_pos.h b/src/include/merchant-database/lookup_contract_terms_pos.h @@ -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/include/merchant-database/lookup_contract_terms_pos.h - * @brief implementation of the lookup_contract_terms_pos function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_POS_H -#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_POS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order_id used to lookup. - * @param[out] contract_terms where to store the result, NULL to only check for existence - * @param[out] order_serial set to the order's serial number - * @param[out] paid set to true if the order is fully paid - * @param[out] claim_token set to the claim token, NULL to only check for existence - * @param[out] pos_key encoded key for payment verification - * @param[out] pos_algorithm algorithm to compute the payment verification - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms_pos ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - struct TALER_ClaimTokenP *claim_token, - char **pos_key, - enum TALER_MerchantConfirmationAlgorithm *pos_algorithm); - -#endif diff --git a/src/include/merchant-database/lookup_contract_terms_status.h b/src/include/merchant-database/lookup_contract_terms_status.h @@ -1,60 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_contract_terms_status.h - * @brief implementation of the lookup_contract_terms_status function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_STATUS_H -#define MERCHANT_DATABASE_LOOKUP_CONTRACT_TERMS_STATUS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order_id used to lookup. - * @param session_id session_id to compare, can be NULL - * @param[out] contract_terms where to store the result, NULL to only check for existence - * @param[out] order_serial set to the order's serial number - * @param[out] paid set to true if the order is fully paid - * @param[out] wired set to true if the exchange wired the funds - * @param[out] session_matches set to true if @a session_id matches session stored for this contract - * @param[out] claim_token set to token to use for access control - * @param[out] choice_index set to the choice index, -1 if not set - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_contract_terms_status ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - const char *session_id, - json_t **contract_terms, - uint64_t *order_serial, - bool *paid, - bool *wired, - bool *session_matches, - struct TALER_ClaimTokenP *claim_token, - int16_t *choice_index); - -#endif diff --git a/src/include/merchant-database/lookup_custom_units_by_names.h b/src/include/merchant-database/lookup_custom_units_by_names.h @@ -1,62 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_custom_units_by_names.h - * @brief Lookup custom measurement units by name - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_CUSTOM_UNITS_BY_NAMES_H -#define MERCHANT_DATABASE_LOOKUP_CUSTOM_UNITS_BY_NAMES_H - -#include <taler/taler_util.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Typically called by `lookup_units`. - * - * @param cls closure - * @param unit_serial database identifier - * @param ud measurement unit details (borrowed) - */ -typedef void -(*TALER_MERCHANTDB_UnitsCallback)( - void *cls, - uint64_t unit_serial, - const struct TALER_MERCHANTDB_UnitDetails *ud); - -/** - * Lookup custom measurement units by name. - * - * @param pg database context - * @param instance_id instance to fetch units for - * @param units array of unit identifiers - * @param num_units length of @a units - * @param cb function to call with each unit - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_custom_units_by_names (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *const *units, - size_t num_units, - TALER_MERCHANTDB_UnitsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_deposits.h b/src/include/merchant-database/lookup_deposits.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/lookup_deposits.h - * @brief implementation of the lookup_deposits function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_DEPOSITS_H -#define MERCHANT_DATABASE_LOOKUP_DEPOSITS_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 a coin that was deposited. - * - * @param cls closure - * @param exchange_url exchange where @a coin_pub was deposited - * @param coin_pub public key of the coin - * @param amount_with_fee amount the exchange will deposit for this coin - * @param deposit_fee fee the exchange will charge for this coin - * @param refund_fee fee the exchange will charge for refunding this coin - * @param wire_fee fee the exchange will charge for the wire transfer - */ -typedef void -(*TALER_MERCHANTDB_DepositsCallback)( - void *cls, - const char *exchange_url, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *deposit_fee, - const struct TALER_Amount *refund_fee, - const struct TALER_Amount *wire_fee); - -/** - * Lookup information about coins that were successfully deposited for a - * given contract. - * - * @param pg database context - * @param instance_id instance to lookup deposits for - * @param h_contract_terms proposal data's hashcode - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct - TALER_PrivateContractHashP *h_contract_terms, - TALER_MERCHANTDB_DepositsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_deposits_by_contract_and_coin.h b/src/include/merchant-database/lookup_deposits_by_contract_and_coin.h @@ -1,80 +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/lookup_deposits_by_contract_and_coin.h - * @brief implementation of the lookup_deposits_by_contract_and_coin function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_DEPOSITS_BY_CONTRACT_AND_COIN_H -#define MERCHANT_DATABASE_LOOKUP_DEPOSITS_BY_CONTRACT_AND_COIN_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a coin that was deposited. - * - * @param cls closure - * @param exchange_url URL of the exchange that issued the coin - * @param amount_with_fee amount the exchange will deposit for this coin - * @param deposit_fee fee the exchange will charge for this coin - * @param refund_fee fee the exchange will charge for refunding this coin - * @param wire_fee wire fee the exchange charges - * @param h_wire hash of merchant's wire details - * @param deposit_timestamp when did the exchange receive the deposit - * @param refund_deadline until when are refunds allowed - * @param exchange_sig signature by the exchange - * @param exchange_pub exchange signing key used for @a exchange_sig - */ -typedef void -(*TALER_MERCHANTDB_CoinDepositCallback)( - void *cls, - const char *exchange_url, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *deposit_fee, - const struct TALER_Amount *refund_fee, - const struct TALER_Amount *wire_fee, - const struct TALER_MerchantWireHashP *h_wire, - struct GNUNET_TIME_Timestamp deposit_timestamp, - struct GNUNET_TIME_Timestamp refund_deadline, - const struct TALER_ExchangeSignatureP *exchange_sig, - const struct TALER_ExchangePublicKeyP *exchange_pub); - - -/** - * Lookup information about coin payments by @a h_contract_terms and - * @a coin_pub. - * - * @param pg database context - * @param instance_id instance to lookup payments for - * @param h_contract_terms proposal data's hashcode - * @param coin_pub public key to use for the search - * @param cb function to call with payment data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits_by_contract_and_coin ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - TALER_MERCHANTDB_CoinDepositCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_deposits_by_order.h b/src/include/merchant-database/lookup_deposits_by_order.h @@ -1,68 +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/lookup_deposits_by_order.h - * @brief implementation of the lookup_deposits_by_order function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_DEPOSITS_BY_ORDER_H -#define MERCHANT_DATABASE_LOOKUP_DEPOSITS_BY_ORDER_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a coin that was deposited. - * - * @param cls closure - * @param deposit_serial which deposit operation is this about - * @param exchange_url URL of the exchange that issued the coin - * @param h_wire hash of merchant's wire details - * @param deposit_timestamp when was the deposit made - * @param amount_with_fee amount the exchange will deposit for this coin - * @param deposit_fee fee the exchange will charge for this coin - * @param coin_pub public key of the coin - */ -typedef void -(*TALER_MERCHANTDB_DepositedCoinsCallback)( - void *cls, - uint64_t deposit_serial, - const char *exchange_url, - const struct TALER_MerchantWireHashP *h_wire, - struct GNUNET_TIME_Timestamp deposit_timestamp, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *deposit_fee, - const struct TALER_CoinSpendPublicKeyP *coin_pub); - -/** - * Retrieve details about coins that were deposited for an order. - * - * @param pg database context - * @param order_serial identifies the order - * @param cb function to call for each deposited coin - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_deposits_by_order ( - struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_DepositedCoinsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_donau_keys.h b/src/include/merchant-database/lookup_donau_keys.h @@ -1,49 +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/lookup_donau_keys.h - * @brief implementation of the lookup_donau_keys function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#ifndef MERCHANT_DATABASE_LOOKUP_DONAU_KEYS_H -#define MERCHANT_DATABASE_LOOKUP_DONAU_KEYS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" -#include "donau/donau_service.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve donau's keys from the database. - * - * @param pg database context - * @param donau_url base URL of the exchange - * @param first_retry if the query fails, this is set to the - * time when the next retry should be attempted - * @param[out] keys set to the keys of the exchange - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_donau_keys (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *donau_url, - struct GNUNET_TIME_Absolute *first_retry, - struct DONAU_Keys **keys); - - -#endif diff --git a/src/include/merchant-database/lookup_expected_transfer.h b/src/include/merchant-database/lookup_expected_transfer.h @@ -1,60 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_expected_transfer.h - * @brief implementation of the lookup_expected_transfer function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_EXPECTED_TRANSFER_H -#define MERCHANT_DATABASE_LOOKUP_EXPECTED_TRANSFER_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Obtain information about an expected incoming wire transfer. - * - * @param pg database context - * @param instance_id instance to lookup payments for - * @param expected_incoming_serial serial number of the transfer - * @param[out] expected_time expected date of the transfer - * @param[out] expected_credit_amount expected amount to be credited - * @param[out] wtid expected wire transfer subject - * @param[out] payto_uri target bank account - * @param[out] exchange_url URL of the exchange - * @param[out] execution_time set to 0 if unknown - * @param[out] confirmed set if the transfer was confirmed - * @param[out] master_pub master public key of the exchange - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_expected_transfer (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t expected_incoming_serial, - struct GNUNET_TIME_Timestamp *expected_time, - struct TALER_Amount *expected_credit_amount, - struct TALER_WireTransferIdentifierRawP *wtid, - struct TALER_FullPayto *payto_uri, - char **exchange_url, - struct GNUNET_TIME_Timestamp *execution_time, - bool *confirmed, - struct TALER_MasterPublicKeyP *master_pub); - - -#endif diff --git a/src/include/merchant-database/lookup_expected_transfers.h b/src/include/merchant-database/lookup_expected_transfers.h @@ -1,93 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_expected_transfers.h - * @brief implementation of the lookup_expected_transfers function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_EXPECTED_TRANSFERS_H -#define MERCHANT_DATABASE_LOOKUP_EXPECTED_TRANSFERS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about expected incoming wire transfers. - * - * @param cls closure with a `json_t *` array to build up the response - * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown - * @param wtid wire transfer identifier - * @param payto_uri target account that received the wire transfer - * @param exchange_url base URL of the exchange that made the wire transfer - * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend - * @param execution_time when did the exchange claim to have made the transfer - * @param confirmed true if the merchant confirmed this wire transfer - * false if it is so far only claimed to have been made by the exchange - * @param validated true if the reconciliation succeeded - * @param last_http_status HTTP status of our last request to the exchange for this transfer - * @param last_ec last error code we got back (otherwise #TALER_EC_NONE) - * @param last_error_detail last detail we got back (or NULL for none) - */ -typedef void -(*TALER_MERCHANTDB_IncomingCallback)( - void *cls, - const struct TALER_Amount *expected_credit_amount, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct TALER_FullPayto payto_uri, - const char *exchange_url, - uint64_t expected_transfer_serial_id, - struct GNUNET_TIME_Timestamp execution_time, - bool confirmed, - bool validated, - unsigned int last_http_status, - enum TALER_ErrorCode last_ec, - const char *last_error_detail); - -/** - * Lookup expected incoming transfers. - * - * @param pg database context - * @param instance_id instance to lookup payments for - * @param payto_uri account that we are interested in transfers to - * @param before timestamp for the earliest transfer we care about - * @param after timestamp for the last transfer we care about - * @param limit number of entries to return, negative for descending in execution time, - * positive for ascending in execution time - * @param offset expected_transfer_serial number of the transfer we want to offset from - * @param confirmed filter by confirmation status - * @param verified filter by verification status - * @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_lookup_expected_transfers ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - struct GNUNET_TIME_Timestamp before, - struct GNUNET_TIME_Timestamp after, - int64_t limit, - uint64_t offset, - enum TALER_EXCHANGE_YesNoAll confirmed, - enum TALER_EXCHANGE_YesNoAll verified, - TALER_MERCHANTDB_IncomingCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_instance_auth.h b/src/include/merchant-database/lookup_instance_auth.h @@ -1,42 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_instance_auth.h - * @brief implementation of the lookup_instance_auth function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_INSTANCE_AUTH_H -#define MERCHANT_DATABASE_LOOKUP_INSTANCE_AUTH_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup authentication data of an instance. - * - * @param pg database context - * @param instance_id instance to query - * @param[out] ias where to store the auth data - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instance_auth (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_MERCHANTDB_InstanceAuthSettings *ias); - -#endif diff --git a/src/include/merchant-database/lookup_instances.h b/src/include/merchant-database/lookup_instances.h @@ -1,78 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_instances.h - * @brief implementation of the lookup_instances function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_INSTANCES_H -#define MERCHANT_DATABASE_LOOKUP_INSTANCES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - -/** - * Typically called by `lookup_instances`. - * - * @param cls closure - * @param merchant_pub public key of the instance - * @param merchant_priv private key of the instance, NULL if not available - * @param is general instance settings - * @param ias instance authentication settings - */ -typedef void -(*TALER_MERCHANTDB_InstanceCallback)( - void *cls, - const struct TALER_MerchantPublicKeyP *merchant_pub, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_InstanceSettings *is, - const struct TALER_MERCHANTDB_InstanceAuthSettings *ias); - -/** - * Lookup all of the instances this backend has configured. - * - * @param pg database context - * @param active_only only find 'active' instances - * @param cb function to call on all instances found - * @param cb_cls closure for @a cb - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instances ( - struct TALER_MERCHANTDB_PostgresContext *pg, - bool active_only, - TALER_MERCHANTDB_InstanceCallback cb, - void *cb_cls); - - -/** - * Lookup one of the instances this backend has configured. - * - * @param pg database context - * @param id instance ID to resolve - * @param active_only only find 'active' instances - * @param cb function to call on all instances found - * @param cb_cls closure for @a cb - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_instances_by_id ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - bool active_only, - TALER_MERCHANTDB_InstanceCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_inventory_products.h b/src/include/merchant-database/lookup_inventory_products.h @@ -1,62 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_inventory_products.h - * @brief Lookup inventory product details for templates - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_H -#define MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_H - -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Typically called by `lookup_inventory_products`. - * - * @param cls a `json_t *` JSON array to build - * @param product_id ID of the product - * @param pd inventory product details - * @param num_categories length of @a categories array - * @param categories array of categories the - * product is in - */ -typedef void -(*TALER_MERCHANTDB_InventoryProductCallback)( - void *cls, - const char *product_id, - const struct TALER_MERCHANTDB_InventoryProductDetails *pd, - size_t num_categories, - const uint64_t *categories); - -/** - * Lookup inventory details for all products of an instance. - * - * @param pg database context - * @param instance_id instance to lookup products for - * @param cb function to call on all products found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_inventory_products (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_InventoryProductCallback cb, - void *cb_cls); - -#endif /* MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_H */ diff --git a/src/include/merchant-database/lookup_inventory_products_filtered.h b/src/include/merchant-database/lookup_inventory_products_filtered.h @@ -1,70 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_inventory_products_filtered.h - * @brief Lookup inventory product details for templates (filtered) - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_FILTERED_H -#define MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_FILTERED_H - -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Typically called by `lookup_inventory_products`. - * - * @param cls a `json_t *` JSON array to build - * @param product_id ID of the product - * @param pd inventory product details - * @param num_categories length of @a categories array - * @param categories array of categories the - * product is in - */ -typedef void -(*TALER_MERCHANTDB_InventoryProductCallback)( - void *cls, - const char *product_id, - const struct TALER_MERCHANTDB_InventoryProductDetails *pd, - size_t num_categories, - const uint64_t *categories); - -/** - * Lookup inventory details for a subset of products. - * - * @param pg database context - * @param instance_id instance to lookup products for - * @param product_ids product IDs to include (can be NULL/empty) - * @param num_product_ids number of entries in @a product_ids - * @param categories category IDs to include (can be NULL/empty) - * @param num_categories number of entries in @a categories - * @param cb function to call on all products found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_inventory_products_filtered (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *const *product_ids, - size_t num_product_ids, - const uint64_t *categories, - size_t num_categories, - TALER_MERCHANTDB_InventoryProductCallback cb, - void *cb_cls); - -#endif /* MERCHANT_DATABASE_LOOKUP_INVENTORY_PRODUCTS_FILTERED_H */ diff --git a/src/include/merchant-database/lookup_login_tokens.h b/src/include/merchant-database/lookup_login_tokens.h @@ -1,69 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_login_tokens.h - * @brief implementation of the lookup_login_tokens function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_LOOKUP_LOGIN_TOKENS_H -#define MERCHANT_DATABASE_LOOKUP_LOGIN_TOKENS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_login_tokens`. - * - * @param cls a `json_t *` JSON array to build - * @param creation_time creation time of the token - * @param expiration_time expiration time of the token - * @param scope validity scope of the token - * @param description description of the token - * @param serial serial number of the token - */ -typedef void -(*TALER_MERCHANTDB_LoginTokensCallback)( - void *cls, - struct GNUNET_TIME_Timestamp creation_time, - struct GNUNET_TIME_Timestamp expiration_time, - uint32_t scope, - const char *description, - uint64_t serial); - -/** - * Lookup all of the tokens the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup tokens for - * @param offset transfer_serial number of the transfer we want to offset from - * @param limit number of entries to return, negative for descending, - * positive for ascending - * @param cb function to call on all products found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_login_tokens ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t offset, - int64_t limit, - TALER_MERCHANTDB_LoginTokensCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_mfa_challenge.h b/src/include/merchant-database/lookup_mfa_challenge.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/lookup_mfa_challenge.h - * @brief implementation of the lookup_mfa_challenge function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_MFA_CHALLENGE_H -#define MERCHANT_DATABASE_LOOKUP_MFA_CHALLENGE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Check if a new multi-factor authorization (MFA) challenge - * matching the body exists in the database. - * - * @param pg database context - * @param challenge_id set to the ID of the challenge - * @param h_body hash of the request body - * @param[out] salt salt used to compute @a h_body - * @param[out] required_address set to where the challenge is to be send - * @param[out] op operation that triggered the MFA request - * @param[out] confirmation_date when was the challenge solved, - * set to "GNUNET_TIME_ABSOLUTE_NEVER" if unsolved - * @param[out] retransmission_date set to when a fresh challenge - * may be transmitted - * @param[out] retry_counter set to the number of attempts that remain - * for solving the challenge (after this time) - * @param[out] tan_channel which channel was used - * @param[out] instance_name name of the instance for which the - * challenge is being issued - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_mfa_challenge (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t challenge_id, - const struct TALER_MERCHANT_MFA_BodyHash *h_body, - struct TALER_MERCHANT_MFA_BodySalt *salt, - char **required_address, - enum TALER_MERCHANT_MFA_CriticalOperation *op, - struct GNUNET_TIME_Absolute *confirmation_date, - struct GNUNET_TIME_Absolute *retransmission_date, - uint32_t *retry_counter, - enum TALER_MERCHANT_MFA_Channel *tan_channel, - char **instance_name); - - -#endif diff --git a/src/include/merchant-database/lookup_order.h b/src/include/merchant-database/lookup_order.h @@ -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/include/merchant-database/lookup_order.h - * @brief implementation of the lookup_order function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDER_H -#define MERCHANT_DATABASE_LOOKUP_ORDER_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve order given its @a order_id and the @a instance_id. - * - * @param pg database context - * @param instance_id instance to obtain order of - * @param order_id order id used to perform the lookup - * @param[out] claim_token the claim token generated for the order, - * NULL to only test if the order exists - * @param[out] h_post_data set to the hash of the POST data that created the order - * @param[out] contract_terms where to store the retrieved contract terms, - * NULL to only test if the order exists - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct TALER_ClaimTokenP *claim_token, - struct TALER_MerchantPostDataHashP *h_post_data, - json_t **contract_terms); - -#endif diff --git a/src/include/merchant-database/lookup_order_by_fulfillment.h b/src/include/merchant-database/lookup_order_by_fulfillment.h @@ -1,51 +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/lookup_order_by_fulfillment.h - * @brief implementation of the lookup_order_by_fulfillment function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDER_BY_FULFILLMENT_H -#define MERCHANT_DATABASE_LOOKUP_ORDER_BY_FULFILLMENT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve the order ID that was used to pay for a resource within a session. - * - * @param pg database context - * @param instance_id identifying the instance - * @param fulfillment_url URL that canonically identifies the resource - * being paid for - * @param session_id session id - * @param allow_refunded_for_repurchase true to include refunded orders in repurchase detection - * @param[out] order_id where to store the order ID that was used when - * paying for the resource URL - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_by_fulfillment (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *fulfillment_url, - const char *session_id, - bool allow_refunded_for_repurchase, - char **order_id); - -#endif diff --git a/src/include/merchant-database/lookup_order_charity.h b/src/include/merchant-database/lookup_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/lookup_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_LOOKUP_ORDER_CHARITY_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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_LOOKUP_ORDER_CHARITY_H */ diff --git a/src/include/merchant-database/lookup_order_status.h b/src/include/merchant-database/lookup_order_status.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/lookup_order_status.h - * @brief implementation of the lookup_order_status function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDER_STATUS_H -#define MERCHANT_DATABASE_LOOKUP_ORDER_STATUS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_id - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_id order to lookup contract for - * @param[out] h_contract_terms set to the hash of the contract. - * @param[out] paid set to the payment status of the contract - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_status (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct TALER_PrivateContractHashP *h_contract_terms, - bool *paid); - -#endif diff --git a/src/include/merchant-database/lookup_order_status_by_serial.h b/src/include/merchant-database/lookup_order_status_by_serial.h @@ -1,50 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_order_status_by_serial.h - * @brief implementation of the lookup_order_status_by_serial function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDER_STATUS_BY_SERIAL_H -#define MERCHANT_DATABASE_LOOKUP_ORDER_STATUS_BY_SERIAL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve contract terms given its @a order_serial - * - * @param pg database context - * @param instance_id instance's identifier - * @param order_serial serial ID of the order to look up - * @param[out] order_id set to ID of the order - * @param[out] h_contract_terms set to the hash of the contract. - * @param[out] paid set to the payment status of the contract - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_status_by_serial (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t order_serial, - char **order_id, - struct TALER_PrivateContractHashP * - h_contract_terms, - bool *paid); - -#endif diff --git a/src/include/merchant-database/lookup_order_summary.h b/src/include/merchant-database/lookup_order_summary.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/lookup_order_summary.h - * @brief implementation of the lookup_order_summary function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDER_SUMMARY_H -#define MERCHANT_DATABASE_LOOKUP_ORDER_SUMMARY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve order summary given its @a order_id and the @a instance_id. - * - * @param pg database context - * @param instance_id instance to obtain order of - * @param order_id order id used to perform the lookup - * @param[out] timestamp when was the order created - * @param[out] order_serial under which serial do we keep this order - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_order_summary (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *order_id, - struct GNUNET_TIME_Timestamp *timestamp, - uint64_t *order_serial); - -#endif diff --git a/src/include/merchant-database/lookup_orders.h b/src/include/merchant-database/lookup_orders.h @@ -1,121 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_orders.h - * @brief implementation of the lookup_orders function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_ORDERS_H -#define MERCHANT_DATABASE_LOOKUP_ORDERS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Filter preferences. - */ -struct TALER_MERCHANTDB_OrderFilter -{ - /** - * Filter orders by this fulfillment URL. - */ - const char *fulfillment_url; - - /** - * Filter orders by this session ID. - */ - const char *session_id; - - /** - * Filter by payment status. - */ - enum TALER_EXCHANGE_YesNoAll paid; - - /** - * Filter by refund status. - */ - enum TALER_EXCHANGE_YesNoAll refunded; - - /** - * Filter by wire transfer status. - */ - enum TALER_EXCHANGE_YesNoAll wired; - - /** - * Filter orders by date, exact meaning depends on @e delta. - */ - struct GNUNET_TIME_Timestamp date; - - /** - * Filter orders by order serial number, exact meaning depends on @e delta. - */ - uint64_t start_row; - - /** - * takes value of the form N (-N), so that at most N values strictly older - * (younger) than start and date are returned. - */ - int64_t delta; - - /** - * Timeout for long-polling. - */ - struct GNUNET_TIME_Relative timeout; - - /** - * Filter to apply on the summary of the order. - */ - const char *summary_filter; - -}; - - -/** - * Typically called by `lookup_orders`. - * - * @param cls a `json_t *` JSON array to build - * @param order_id ID of the order - * @param order_serial row of the order in the database - * @param timestamp creation time of the order in the database - */ -typedef void -(*TALER_MERCHANTDB_OrdersCallback)( - void *cls, - const char *order_id, - uint64_t order_serial, - struct GNUNET_TIME_Timestamp timestamp); - -/** - * Retrieve orders given the @a instance_id. - * - * @param pg database context - * @param instance_id instance to obtain order of - * @param of filter to apply when looking up orders - * @param cb callback to pass all the orders that are found - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_orders ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_MERCHANTDB_OrderFilter *of, - TALER_MERCHANTDB_OrdersCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_otp_devices.h b/src/include/merchant-database/lookup_otp_devices.h @@ -1,60 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_otp_devices.h - * @brief implementation of the lookup_otp_devices function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_OTP_DEVICES_H -#define MERCHANT_DATABASE_LOOKUP_OTP_DEVICES_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 `lookup_otp_devices`. - * - * @param cls closure - * @param otp_id ID of the OTP device - * @param otp_description description of the OTP device - */ -typedef void -(*TALER_MERCHANTDB_OtpDeviceCallback)( - void *cls, - const char *otp_id, - const char *otp_description); - -/** - * Lookup all of the OTP devices the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup OTP devices for - * @param cb function to call on all OTP devices found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_otp_devices (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_OtpDeviceCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_pending_deposits.h b/src/include/merchant-database/lookup_pending_deposits.h @@ -1,80 +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/lookup_pending_deposits.h - * @brief implementation of the lookup_pending_deposits function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PENDING_DEPOSITS_H -#define MERCHANT_DATABASE_LOOKUP_PENDING_DEPOSITS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Callback for results from `lookup_pending_deposits`. - * - * @param cls NULL - * @param deposit_serial identifies the deposit operation - * @param wire_deadline when is the wire due - * @param retry_time when to next try the exchange again - * @param h_contract_terms hash of the contract terms - * @param merchant_priv private key of the merchant - * @param instance_id name of the instance - * @param h_wire hash of the merchant's wire account into - * @param amount_with_fee amount the exchange will deposit for this coin - * @param deposit_fee fee the exchange will charge for this coin which the deposit was made - * @param coin_pub public key of the deposited coin - */ -typedef void -(*TALER_MERCHANTDB_PendingDepositsCallback) ( - void *cls, - uint64_t deposit_serial, - struct GNUNET_TIME_Absolute wire_deadline, - struct GNUNET_TIME_Absolute retry_time, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const char *instance_id, - const struct TALER_MerchantWireHashP *h_wire, - const struct TALER_Amount *amount_with_fee, - const struct TALER_Amount *deposit_fee, - const struct TALER_CoinSpendPublicKeyP *coin_pub); - -/** - * Lookup deposits that are finished and awaiting a wire transfer. - * - * @param pg database context - * @param exchange_url exchange to filter deposits by - * @param limit maximum number of deposits to return - * @param allow_future true to allow deposits with wire deadline in the future - * @param cb function to call with deposit data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_pending_deposits (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - uint64_t limit, - bool allow_future, - TALER_MERCHANTDB_PendingDepositsCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_pending_webhooks.h b/src/include/merchant-database/lookup_pending_webhooks.h @@ -1,88 +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/lookup_pending_webhooks.h - * @brief implementation of the lookup_pending_webhooks function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PENDING_WEBHOOKS_H -#define MERCHANT_DATABASE_LOOKUP_PENDING_WEBHOOKS_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 `lookup_pending_webhooks`. - * - * @param cls a `json_t *` JSON array to build - * @param webhook_pending_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_PendingWebhooksCallback)( - void *cls, - uint64_t webhook_pending_serial, - struct GNUNET_TIME_Absolute - next_attempt, - uint32_t retries, - const char *url, - const char *http_method, - const char *header, - const char *body); - -/** - * Lookup the webhook that need to be send in priority. - * send. - * - * @param pg database context - * @param limit maximum number of webhooks to return - * @param cb pending webhook callback - * @param cb_cls callback closure - */ -// WHERE next_attempt <= now ORDER BY next_attempt ASC LIMIT limit -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_pending_webhooks (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t limit, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls); - - -/** - * Lookup the next webhook in the pending webhooks that needs to be - * sent. With that we can know how long the system can 'sleep'. - * - * @param pg database context - * @param cb pending webhook callback - * @param cb_cls callback closure - */ -// ORDER BY next_attempt ASC LIMIT 1 -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_pending_webhooks_next ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_PendingWebhooksCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_product.h b/src/include/merchant-database/lookup_product.h @@ -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/include/merchant-database/lookup_product.h - * @brief implementation of the lookup_product function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PRODUCT_H -#define MERCHANT_DATABASE_LOOKUP_PRODUCT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Lookup details about a particular product. - * - * @param pg database context - * @param instance_id instance to lookup products for - * @param product_id product to lookup - * @param[out] pd set to the product details on success, can be NULL - * (in that case we only want to check if the product exists) - * @param[out] num_categories set to length of @a categories array - * @param[out] categories set to array of categories the - * product is in, caller must free() it. - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *product_id, - struct TALER_MERCHANTDB_ProductDetails *pd, - size_t *num_categories, - uint64_t **categories); - -#endif diff --git a/src/include/merchant-database/lookup_product_image_by_hash.h b/src/include/merchant-database/lookup_product_image_by_hash.h @@ -1,34 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file src/include/merchant-database/lookup_product_image_by_hash.h - * @brief declaration of lookup_product_image_by_hash for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_BY_HASH_H -#define MERCHANT_DATABASE_LOOKUP_PRODUCT_IMAGE_BY_HASH_H - -#include "merchantdb_lib.h" - - -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_product_image_by_hash ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *image_hash, - char **image); - -#endif diff --git a/src/include/merchant-database/lookup_products.h b/src/include/merchant-database/lookup_products.h @@ -1,91 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_products.h - * @brief implementation of the lookup_products function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_PRODUCTS_H -#define MERCHANT_DATABASE_LOOKUP_PRODUCTS_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 `lookup_products`. - * - * @param cls a `json_t *` JSON array to build - * @param product_serial row ID of the product - * @param product_id ID of the product - */ -typedef void -(*TALER_MERCHANTDB_ProductsCallback)( - void *cls, - uint64_t product_serial, - const char *product_id); - -/** - * Lookup all of the products the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup products for - * @param offset transfer_serial number of the transfer we want to offset from - * @param limit number of entries to return, negative for descending, - * positive for ascending - * @param category_filter filter products by category, NULL to not filter; - * uses the Postgresql "LIKE" pattern matcher, so - * "%" stands for any sequence of zero or more characters, - * "_" stands for any single character; - * use "\%" and "\_" to exactly match "%" or "_". - * We will always use case-insensitive searches, for case-sensitive - * matching the client should filter the result set. - * @param name_filter filter products by name, NULL to not filter - * uses the Postgresql "LIKE" pattern matcher, so - * "%" stands for any sequence of zero or more characters, - * "_" stands for any single character - * use "\%" and "\_" to exactly match "%" or "_". - * We will always use case-insensitive searches, for case-sensitive - * matching the client should filter the result set. - * @param description_filter filter products by description, NULL to not filter - * uses the Postgresql "LIKE" pattern matcher, so - * "%" stands for any sequence of zero or more characters, - * "_" stands for any single character - * use "\%" and "\_" to exactly match "%" or "_". - * We will always use case-insensitive searches, for case-sensitive - * matching the client should filter the result set. - * @param product_group_id_filter only return products in where the - * product group ID matches the given ID, 0 to not filter - * @param cb function to call on all products found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_products (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t offset, - int64_t limit, - const char *category_filter, - const char *name_filter, - const char *description_filter, - uint64_t product_group_id_filter, - TALER_MERCHANTDB_ProductsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_reconciliation_details.h b/src/include/merchant-database/lookup_reconciliation_details.h @@ -1,66 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_reconciliation_details.h - * @brief implementation of the lookup_reconciliation_details function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_RECONCILIATION_DETAILS_H -#define MERCHANT_DATABASE_LOOKUP_RECONCILIATION_DETAILS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function returning reconciliation details for an - * expected incoming wire transfer. - * Called by `lookup_reconciliation_details`. - * - * @param cls closure - * @param order_id order that was paid and then aggregated - * @param remaining_deposit deposited amount minus any refunds - * @param deposit_fee deposit fees paid to the exchange for the order - */ -typedef void -(*TALER_MERCHANTDB_ReconciliationDetailsCallback)( - void *cls, - const char *order_id, - const struct TALER_Amount *remaining_deposit, - const struct TALER_Amount *deposit_fee); - - -/** - * Obtain reconciliation details for an expected incoming wire transfer. - * - * @param pg database context - * @param instance_id instance to lookup payments for - * @param expected_incoming_serial serial number of the transfer - * @param cb callback to invoke - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_reconciliation_details ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t expected_incoming_serial, - TALER_MERCHANTDB_ReconciliationDetailsCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_refund_proof.h b/src/include/merchant-database/lookup_refund_proof.h @@ -1,45 +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/lookup_refund_proof.h - * @brief implementation of the lookup_refund_proof function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_REFUND_PROOF_H -#define MERCHANT_DATABASE_LOOKUP_REFUND_PROOF_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup refund proof data. - * - * @param pg database context - * @param refund_serial serial number of the refund - * @param[out] exchange_sig set to signature from exchange - * @param[out] exchange_pub signing key that was used for @a exchange_sig - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refund_proof (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t refund_serial, - struct TALER_ExchangeSignatureP *exchange_sig, - struct TALER_ExchangePublicKeyP *exchange_pub); - -#endif diff --git a/src/include/merchant-database/lookup_refunds.h b/src/include/merchant-database/lookup_refunds.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/lookup_refunds.h - * @brief implementation of the lookup_refunds function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_REFUNDS_H -#define MERCHANT_DATABASE_LOOKUP_REFUNDS_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 a refund. - * - * @param cls closure - * @param coin_pub public coin from which the refund comes from - * @param refund_amount refund amount which is being taken from @a coin_pub - */ -typedef void -(*TALER_MERCHANTDB_RefundCallback)( - void *cls, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_Amount *refund_amount); - -/** - * Obtain refunds associated with a contract. - * - * @param pg database context - * @param instance_id instance to lookup refunds for - * @param h_contract_terms hash code of the contract - * @param rc function to call for each coin on which there is a refund - * @param rc_cls closure for @a rc - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refunds (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - TALER_MERCHANTDB_RefundCallback rc, - void *rc_cls); - -#endif diff --git a/src/include/merchant-database/lookup_refunds_detailed.h b/src/include/merchant-database/lookup_refunds_detailed.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/lookup_refunds_detailed.h - * @brief implementation of the lookup_refunds_detailed function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_REFUNDS_DETAILED_H -#define MERCHANT_DATABASE_LOOKUP_REFUNDS_DETAILED_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 detailed information about a refund. - * - * @param cls closure - * @param refund_serial unique serial number of the refund - * @param timestamp time of the refund (for grouping of refunds in the wallet UI) - * @param coin_pub public coin from which the refund comes from - * @param exchange_url URL of the exchange that issued @a coin_pub - * @param rtransaction_id identificator of the refund - * @param reason human-readable explanation of the refund - * @param refund_amount refund amount which is being taken from @a coin_pub - * @param pending true if the this refund was not yet processed by the wallet/exchange - */ -typedef void -(*TALER_MERCHANTDB_RefundDetailCallback)( - void *cls, - uint64_t refund_serial, - struct GNUNET_TIME_Timestamp timestamp, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const char *exchange_url, - uint64_t rtransaction_id, - const char *reason, - const struct TALER_Amount *refund_amount, - bool pending); - -/** - * Obtain detailed refund data associated with a contract. - * - * @param pg database context - * @param instance_id instance to lookup refunds for - * @param h_contract_terms hash code of the contract - * @param rc function to call for each coin on which there is a refund - * @param rc_cls closure for @a rc - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_refunds_detailed (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const struct TALER_PrivateContractHashP *h_contract_terms, - TALER_MERCHANTDB_RefundDetailCallback rc, - void *rc_cls); - -#endif diff --git a/src/include/merchant-database/lookup_reports_pending.h b/src/include/merchant-database/lookup_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/lookup_reports_pending.h - * @brief implementation of the lookup_reports_pending function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_REPORTS_PENDING_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_reports_pending ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_ReportsPendingCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_spent_tokens_by_order.h b/src/include/merchant-database/lookup_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/lookup_spent_tokens_by_order.h - * @brief implementation of the lookup_spent_tokens_by_order function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_SPENT_TOKENS_BY_ORDER_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_statistics_amount_by_bucket.h b/src/include/merchant-database/lookup_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/lookup_statistics_amount_by_bucket.h - * @brief implementation of the lookup_statistics_amount_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_statistics_amount_by_bucket_range.h b/src/include/merchant-database/lookup_statistics_amount_by_bucket_range.h @@ -1,93 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_statistics_amount_by_bucket_range.h - * @brief implementation of the lookup_statistics_amount_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET_RANGE_H -#define MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_BUCKET_RANGE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Returns amount-valued statistics by bucket. - * Called by `lookup_statistics_amount_by_bucket`. - * - * @param cls closure - * @param description description of the statistic - * @param bucket_start start time of the bucket - * @param bucket_end end time of the bucket - * @param bucket_range range of the bucket - * @param cumulative_amounts_len the length of @a cumulative_amounts - * @param cumulative_amounts the cumulative amounts array - */ -typedef void -(*TALER_MERCHANTDB_AmountByBucketStatisticsCallback)( - void *cls, - const char *description, - struct GNUNET_TIME_Timestamp bucket_start, - struct GNUNET_TIME_Timestamp bucket_end, - const char *bucket_range, - unsigned int cumulative_amounts_len, - const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); - -/** - * Returns amount-valued statistics by bucket. - * Called by `lookup_statistics_amount_by_bucket2`. - * - * @param cls closure - * @param bucket_start start time of the bucket - * @param cumulative_amounts_len the length of @a cumulative_amounts - * @param cumulative_amounts the cumulative amounts array - */ -typedef void -(*TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback)( - void *cls, - struct GNUNET_TIME_Timestamp bucket_start, - unsigned int cumulative_amounts_len, - const struct TALER_Amount cumulative_amounts[static cumulative_amounts_len]); - -/** - * Lookup amount statistics for instance and slug by bucket, - * restricting to a fixed number of buckets at a given granularity. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param slug instance to lookup statistics for - * @param granularity limit to buckets of this size - * @param counter requested number of buckets - * @param cb function to call on all token families found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_amount_by_bucket_range (struct TALER_MERCHANTDB_PostgresContext * - pg, - const char *instance_id, - const char *slug, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_AmountByBucketRangeStatisticsCallback - cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_statistics_amount_by_interval.h b/src/include/merchant-database/lookup_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/lookup_statistics_amount_by_interval.h - * @brief implementation of the lookup_statistics_amount_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_AMOUNT_BY_INTERVAL_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_statistics_counter_by_bucket.h b/src/include/merchant-database/lookup_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/lookup_statistics_counter_by_bucket.h - * @brief implementation of the lookup_statistics_counter_by_bucket function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_statistics_counter_by_bucket_range.h b/src/include/merchant-database/lookup_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/lookup_statistics_counter_by_bucket_range.h - * @brief implementation of the lookup_statistics_counter_by_bucket_range function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET_RANGE_H -#define MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_BUCKET_RANGE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function returning integer-valued statistics for a bucket. - * Called by `lookup_statistics_counter_by_bucket2`. - * - * @param cls closure - * @param bucket_start start time of the bucket - * @param counters_len the length of @a cumulative_amounts - * @param descriptions description for the counter in the bucket - * @param counters the counters in the bucket - */ -typedef void -(*TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback)( - void *cls, - struct GNUNET_TIME_Timestamp bucket_start, - unsigned int counters_len, - const char *descriptions[static counters_len], - uint64_t counters[static counters_len]); - - -/** - * Lookup counter statistics for instance and slug-prefix by bucket. - * - * @param pg database context - * @param instance_id instance to lookup statistics for - * @param prefix slug prefix to lookup statistics under - * @param granularity limit to buckets of this size - * @param counter requested number of buckets - * @param cb function to call on all token families found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_statistics_counter_by_bucket_range ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *prefix, - const char *granularity, - uint64_t counter, - TALER_MERCHANTDB_CounterByBucketRangeStatisticsCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_statistics_counter_by_interval.h b/src/include/merchant-database/lookup_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/lookup_statistics_counter_by_interval.h - * @brief implementation of the lookup_statistics_by_interval function for Postgres - * @author Martin Schanzenbach - */ -#ifndef MERCHANT_DATABASE_LOOKUP_STATISTICS_COUNTER_BY_INTERVAL_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_template.h b/src/include/merchant-database/lookup_template.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/lookup_template.h - * @brief implementation of the lookup_template function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TEMPLATE_H -#define MERCHANT_DATABASE_LOOKUP_TEMPLATE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Lookup details about a particular template. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param template_id template to lookup - * @param[out] td set to the template details on success - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_template ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *template_id, - struct TALER_MERCHANTDB_TemplateDetails *td); - - -#endif diff --git a/src/include/merchant-database/lookup_templates.h b/src/include/merchant-database/lookup_templates.h @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_templates.h - * @brief implementation of the lookup_templates function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TEMPLATES_H -#define MERCHANT_DATABASE_LOOKUP_TEMPLATES_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 `lookup_templates`. - * - * @param cls closure - * @param template_id ID of the template - * @param template_description description of the template - */ -typedef void -(*TALER_MERCHANTDB_TemplatesCallback)( - void *cls, - const char *template_id, - const char *template_description); - -/** - * Lookup all of the templates the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param cb function to call on all template found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_templates (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_TemplatesCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_token_families.h b/src/include/merchant-database/lookup_token_families.h @@ -1,67 +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/lookup_token_families.h - * @brief implementation of the lookup_token_families function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILIES_H -#define MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILIES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - -/** - * Typically called by `lookup_token_families`. - * - * @param cls closure - * @param slug slug of the token family - * @param name name of the token family - * @param description description of the token family - * @param description_i18n Internationalized token family description. - * @param start_time start time of the token family's validity period - * @param expiration end time of the token family's validity period - * @param kind kind of the token family - */ -typedef void -(*TALER_MERCHANTDB_TokenFamiliesCallback)( - void *cls, - const char *slug, - const char *name, - const char *description, - const json_t *description_i18n, - struct GNUNET_TIME_Timestamp start_time, - struct GNUNET_TIME_Timestamp expiration, - const char *kind); - -/** - * Lookup all of the token families the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup token families for - * @param cb function to call on all token families found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_families ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_TokenFamiliesCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_token_family.h b/src/include/merchant-database/lookup_token_family.h @@ -1,47 +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/lookup_token_family.h - * @brief implementation of the lookup_token_family function for Postgres - * @author Christian Blättler - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_H -#define MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about a particular token family. - * - * @param pg database context - * @param instance_id instance to lookup token family for - * @param token_family_slug token family to lookup - * @param[out] details set to the token family details on success, can be NULL - * (in that case we only want to check if the token family exists) - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct TALER_MERCHANTDB_TokenFamilyDetails *details) -; - -#endif diff --git a/src/include/merchant-database/lookup_token_family_key.h b/src/include/merchant-database/lookup_token_family_key.h @@ -1,92 +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/lookup_token_family_key.h - * @brief implementation of the lookup_token_family_key function for Postgres - * @author Christian Blättler - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_KEY_H -#define MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_KEY_H - -#include <gnunet/gnunet_common.h> -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Details about a token key. - */ -struct TALER_MERCHANTDB_TokenFamilyKeyDetails -{ - /** - * Tokens signed with this key are valid from this date on. - * This is the time the key was created. - */ - struct GNUNET_TIME_Timestamp signature_validity_start; - - /** - * Tokens signed with this key are valid until this date. - */ - struct GNUNET_TIME_Timestamp signature_validity_end; - - /** - * Private key expires for use at this time. Signatures can - * only be created until this point. - */ - struct GNUNET_TIME_Timestamp private_key_deleted_at; - - /** - * Token family public key. - */ - struct TALER_TokenIssuePublicKey pub; - - /** - * Token family private key. - */ - struct TALER_TokenIssuePrivateKey priv; - - /** - * Details about the token family this key belongs to. - */ - struct TALER_MERCHANTDB_TokenFamilyDetails token_family; -}; - - -/** - * Lookup details about a particular token family key. The valid_after field - * of the key has to be >= @e min_valid_after and < @e max_valid_after. - * - * @param pg database context - * @param instance_id instance to lookup token family key for - * @param token_family_slug slug of token family to lookup - * @param valid_at find a key with a validity period that includes this time - * @param sign_until find a private key that can sign until this time - * @param[out] details set to the token family key details on success, can be NULL - * (in that case we only want to check if the token family key exists) - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family_key ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct GNUNET_TIME_Timestamp valid_at, - struct GNUNET_TIME_Timestamp sign_until, - struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); - - -#endif diff --git a/src/include/merchant-database/lookup_token_family_keys.h b/src/include/merchant-database/lookup_token_family_keys.h @@ -1,65 +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/lookup_token_family_keys.h - * @brief implementation of the lookup_token_family_keys function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_KEYS_H -#define MERCHANT_DATABASE_LOOKUP_TOKEN_FAMILY_KEYS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" -#include "merchant-database/lookup_token_family_key.h" - - -/** - * Function called with applicable token keys. - * - * @param cls closure - * @param details details about an applicable key - */ -typedef void -(*TALER_MERCHANTDB_TokenKeyCallback) ( - void *cls, - const struct TALER_MERCHANTDB_TokenFamilyKeyDetails *details); - - -/** - * Lookup token family keys that may be used for a payment. - * - * @param pg database context - * @param instance_id instance to lookup token family key for - * @param token_family_slug slug of token family to lookup - * @param start_time signature validity start the keys must fall into - * @param end_time signature validity end the keys must fall into - * @param cb function to call with each matching key - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_token_family_keys ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *token_family_slug, - struct GNUNET_TIME_Timestamp start_time, - struct GNUNET_TIME_Timestamp end_time, - TALER_MERCHANTDB_TokenKeyCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/lookup_tos_accepted_early.h b/src/include/merchant-database/lookup_tos_accepted_early.h @@ -1,54 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_tos_accepted_early.h - * @brief implementation of the lookup_tos_accepted_early function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TOS_ACCEPTED_EARLY_H -#define MERCHANT_DATABASE_LOOKUP_TOS_ACCEPTED_EARLY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; - -/** - * Look up the ``Taler-Terms-Version`` of the terms of - * service that the user has accepted early for a given - * exchange (via the ``POST /private/accept-tos-early`` - * endpoint). - * - * @param pg database context - * @param merchant_id merchant backend instance ID - * @param exchange_url base URL of the exchange to look up - * @param[out] tos_version set to a newly allocated string with the - * accepted ``Taler-Terms-Version``; caller must @a GNUNET_free - * it. Set to NULL if no acceptance is on record for this - * @a exchange_url, in which case the query status will be - * ``GNUNET_DB_STATUS_SUCCESS_NO_RESULTS``. - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_tos_accepted_early ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *merchant_id, - const char *exchange_url, - char **tos_version); - -#endif diff --git a/src/include/merchant-database/lookup_transfer_details.h b/src/include/merchant-database/lookup_transfer_details.h @@ -1,63 +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/lookup_transfer_details.h - * @brief implementation of the lookup_transfer_details function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TRANSFER_DETAILS_H -#define MERCHANT_DATABASE_LOOKUP_TRANSFER_DETAILS_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 detailed information about a wire transfer and - * the underlying deposits that are being aggregated. - * - * @param cls closure - * @param current_offset offset in the exchange reply we are at - * @param ttd details about the transfer at @a current_offset - */ -typedef void -(*TALER_MERCHANTDB_TransferDetailsCallback)( - void *cls, - unsigned int current_offset, - const struct TALER_TrackTransferDetails *ttd); - -/** - * Lookup transfer details. - * - * @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_lookup_transfer_details (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - const struct TALER_WireTransferIdentifierRawP * - wtid, - TALER_MERCHANTDB_TransferDetailsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_transfer_details_by_order.h b/src/include/merchant-database/lookup_transfer_details_by_order.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/lookup_transfer_details_by_order.h - * @brief implementation of the lookup_transfer_details_by_order function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TRANSFER_DETAILS_BY_ORDER_H -#define MERCHANT_DATABASE_LOOKUP_TRANSFER_DETAILS_BY_ORDER_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 `lookup_transfer_details_by_order`. - * - * @param cls closure - * @param wtid wire transfer subject of the wire transfer for the coin - * @param exchange_url base URL of the exchange that made the payment - * @param execution_time when was the payment made - * @param deposit_value contribution of the coin to the total wire transfer value - * @param deposit_fee deposit fee charged by the exchange for the coin - * @param transfer_confirmed did the merchant confirm that a wire transfer with - * @a wtid over the total amount happened? - * @param expected_credit_serial row of the expected wire transfer, usable - * as ``offset`` for the ``/private/incoming`` endpoint - */ -typedef void -(*TALER_MERCHANTDB_OrderTransferDetailsCallback)( - void *cls, - const struct TALER_WireTransferIdentifierRawP *wtid, - const char *exchange_url, - struct GNUNET_TIME_Timestamp execution_time, - const struct TALER_Amount *deposit_value, - const struct TALER_Amount *deposit_fee, - bool transfer_confirmed, - uint64_t expected_credit_serial); - -/** - * Retrieve wire transfer details for all deposits associated with - * a given @a order_serial. - * - * @param pg database context - * @param order_serial identifies the order - * @param cb function called with the wire transfer details - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_transfer_details_by_order (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t order_serial, - TALER_MERCHANTDB_OrderTransferDetailsCallback - cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_transfer_summary.h b/src/include/merchant-database/lookup_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/lookup_transfer_summary.h - * @brief implementation of the lookup_transfer_summary function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TRANSFER_SUMMARY_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/lookup_transfers.h b/src/include/merchant-database/lookup_transfers.h @@ -1,88 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_transfers.h - * @brief implementation of the lookup_transfers function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_LOOKUP_TRANSFERS_H -#define MERCHANT_DATABASE_LOOKUP_TRANSFERS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a wire transfer. - * - * @param cls closure with a `json_t *` array to build up the response - * @param expected_credit_amount how we expect to see wired to the merchant (minus fees), NULL if unknown - * @param wtid wire transfer identifier - * @param payto_uri target account that received the wire transfer - * @param exchange_url base URL of the exchange that made the wire transfer - * @param transfer_serial_id serial number identifying the transfer in the backend - * @param expected_transfer_serial_id serial number identifying the expected transfer in the backend, 0 if not @a expected - * @param execution_time when did the exchange make the transfer, #GNUNET_TIME_UNIT_FOREVER_ABS - * if it did not yet happen - * @param expected true if the merchant acknowledged the wire transfer reception - */ -typedef void -(*TALER_MERCHANTDB_TransferCallback)( - void *cls, - const struct TALER_Amount *expected_credit_amount, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct TALER_FullPayto payto_uri, - const char *exchange_url, - uint64_t transfer_serial_id, - uint64_t expected_transfer_serial_id, - struct GNUNET_TIME_Absolute execution_time, - bool expected); - -/** - * Lookup transfers. Note that filtering by @a verified status is done - * outside of SQL, as we already have 8 prepared statements and adding - * a filter on verified would further double the number of statements for - * a likely rather ineffective filter. So we apply that filter in - * #lookup_transfers_cb(). - * - * @param pg database context - * @param instance_id instance to lookup payments for - * @param payto_uri account that we are interested in transfers to - * @param before timestamp for the earliest transfer we care about - * @param after timestamp for the last transfer we care about - * @param limit number of entries to return, negative for descending in execution time, - * positive for ascending in execution time - * @param offset transfer_serial number of the transfer we want to offset from - * @param expected filter for transfers that were expected - * @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_lookup_transfers ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - struct TALER_FullPayto payto_uri, - struct GNUNET_TIME_Timestamp before, - struct GNUNET_TIME_Timestamp after, - int64_t limit, - uint64_t offset, - enum TALER_EXCHANGE_YesNoAll expected, - TALER_MERCHANTDB_TransferCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_units.h b/src/include/merchant-database/lookup_units.h @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2025 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/lookup_units.h - * @brief implementation of the lookup_units function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_LOOKUP_UNITS_H -#define MERCHANT_DATABASE_LOOKUP_UNITS_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 `lookup_units`. - * - * @param cls closure - * @param unit_serial database identifier - * @param ud measurement unit details (borrowed) - */ -typedef void -(*TALER_MERCHANTDB_UnitsCallback)( - void *cls, - uint64_t unit_serial, - const struct TALER_MERCHANTDB_UnitDetails *ud); - -/** - * Lookup all measurement units for an instance. - * - * @param pg database context - * @param instance_id instance to fetch units for - * @param cb function to call with each unit - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_units (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_UnitsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_webhook.h b/src/include/merchant-database/lookup_webhook.h @@ -1,46 +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/lookup_webhook.h - * @brief implementation of the lookup_webhook function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_WEBHOOK_H -#define MERCHANT_DATABASE_LOOKUP_WEBHOOK_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about a particular webhook. - * - * @param pg database context - * @param instance_id instance to lookup webhook for - * @param webhook_id webhook to lookup - * @param[out] wb set to the webhook details on success, can be NULL - * (in that case we only want to check if the webhook exists) - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhook (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *webhook_id, - struct TALER_MERCHANTDB_WebhookDetails *wb); - -#endif diff --git a/src/include/merchant-database/lookup_webhook_by_event.h b/src/include/merchant-database/lookup_webhook_by_event.h @@ -1,68 +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/lookup_webhook_by_event.h - * @brief implementation of the lookup_webhook_by_event function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_WEBHOOK_BY_EVENT_H -#define MERCHANT_DATABASE_LOOKUP_WEBHOOK_BY_EVENT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_webhook_by_event`. - * - * @param cls a `json_t *` JSON array to build - * @param webhook_serial reference to the configured webhook template. - * @param event_type which type of event triggers this type of webhook - * @param url the HTTP URL to make the webhook request to - * @param http_method HTTP method use for the webhook - * @param header_template template for the header of the webhook - * @param body_template template for the body of the webhook - */ -typedef void -(*TALER_MERCHANTDB_WebhookDetailCallback)( - void *cls, - uint64_t webhook_serial, - const char *event_type, - const char *url, - const char *http_method, - const char *header_template, - const char *body_template); - -/** - * Lookup webhook by event - * - * @param pg database context - * @param instance_id instance to lookup webhook for - * @param event_type event that we need to put in the pending webhook - * @param[out] cb set to the webhook details on success - * @param cb_cls callback closure - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhook_by_event ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *event_type, - TALER_MERCHANTDB_WebhookDetailCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_webhooks.h b/src/include/merchant-database/lookup_webhooks.h @@ -1,58 +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/lookup_webhooks.h - * @brief implementation of the lookup_webhooks function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_WEBHOOKS_H -#define MERCHANT_DATABASE_LOOKUP_WEBHOOKS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `lookup_webhooks`. - * - * @param cls a `json_t *` JSON array to build - * @param webhook_id ID of the webhook - * @param event_type event of the webhook - */ -typedef void -(*TALER_MERCHANTDB_WebhooksCallback)( - void *cls, - const char *webhook_id, - const char *event_type); - -/** - * Lookup all of the webhooks the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup webhook for - * @param cb function to call on all webhook found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_lookup_webhooks ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - TALER_MERCHANTDB_WebhooksCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/lookup_wire_fee.h b/src/include/merchant-database/lookup_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/lookup_wire_fee.h - * @brief implementation of the lookup_wire_fee function for Postgres - * @author Iván Ávalos - */ -#ifndef MERCHANT_DATABASE_LOOKUP_WIRE_FEE_H -#define MERCHANT_DATABASE_LOOKUP_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_lookup_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/select_account.h b/src/include/merchant-database/select_account.h @@ -1,45 +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/select_account.h - * @brief implementation of the select_account function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_ACCOUNT_H -#define MERCHANT_DATABASE_SELECT_ACCOUNT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Obtain information about an instance's accounts. - * - * @param pg database context - * @param id identifier of the instance - * @param h_wire wire hash of the account - * @param[out] ad account details returned - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_account (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - const struct TALER_MerchantWireHashP *h_wire, - struct TALER_MERCHANTDB_AccountDetails *ad); - -#endif diff --git a/src/include/merchant-database/select_account_by_uri.h b/src/include/merchant-database/select_account_by_uri.h @@ -1,45 +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/select_account_by_uri.h - * @brief implementation of the select_account_by_uri function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_ACCOUNT_BY_URI_H -#define MERCHANT_DATABASE_SELECT_ACCOUNT_BY_URI_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Obtain information about an instance's accounts. - * - * @param pg database context - * @param id identifier of the instance - * @param payto_uri URI of the account - * @param[out] ad account details returned - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_account_by_uri (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - struct TALER_FullPayto payto_uri, - struct TALER_MERCHANTDB_AccountDetails *ad); - -#endif diff --git a/src/include/merchant-database/select_accounts.h b/src/include/merchant-database/select_accounts.h @@ -1,57 +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/select_accounts.h - * @brief implementation of the select_accounts function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_ACCOUNTS_H -#define MERCHANT_DATABASE_SELECT_ACCOUNTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Callback invoked with information about a bank account. - * - * @param cls closure - * @param merchant_priv private key of the merchant instance - * @param ad details about the account - */ -typedef void -(*TALER_MERCHANTDB_AccountCallback)( - void *cls, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_AccountDetails *ad); - - -/** - * Obtain information about an instance's accounts. - * - * @param pg database context - * @param cb function to call on each account - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_accounts ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_AccountCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_accounts_by_exchange.h b/src/include/merchant-database/select_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/select_accounts_by_exchange.h - * @brief implementation of the select_accounts_by_exchange function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_ACCOUNTS_BY_EXCHANGE_H -#define MERCHANT_DATABASE_SELECT_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_select_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/select_accounts_by_instance.h b/src/include/merchant-database/select_accounts_by_instance.h @@ -1,58 +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/select_accounts_by_instance.h - * @brief implementation of the select_accounts_by_instance function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_ACCOUNTS_BY_INSTANCE_H -#define MERCHANT_DATABASE_SELECT_ACCOUNTS_BY_INSTANCE_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Callback invoked with information about a bank account. - * - * @param cls closure - * @param merchant_priv private key of the merchant instance - * @param ad details about the account - */ -typedef void -(*TALER_MERCHANTDB_AccountCallback)( - void *cls, - const struct TALER_MerchantPrivateKeyP *merchant_priv, - const struct TALER_MERCHANTDB_AccountDetails *ad); - -/** - * Obtain information about an instance's accounts. - * - * @param pg database context - * @param id identifier of the instance - * @param cb function to call on each account - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_accounts_by_instance ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - TALER_MERCHANTDB_AccountCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_all_donau_instances.h b/src/include/merchant-database/select_all_donau_instances.h @@ -1,75 +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/select_all_donau_instances.h - * @brief implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#ifndef MERCHANT_DATABASE_SELECT_ALL_DONAU_INSTANCES_H -#define MERCHANT_DATABASE_SELECT_ALL_DONAU_INSTANCES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donau/donau_util.h" -#include "merchantdb_lib.h" - - -/** - * Callback function typically used by `select_donau_instances` to handle - * the details of each Donau instance retrieved from the database. - * - * @param cls Closure to pass additional context or data to the callback function. - * @param donau_instance_serial Serial number of the Donau instance in the merchant database. - * @param donau_url The URL of the Donau instance. - * @param charity_name The name of the charity associated with the Donau instance. - * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. - * @param charity_id The unique identifier for the charity within the Donau instance. - * @param charity_max_per_year Maximum allowed donations to the charity for the current year. - * @param charity_receipts_to_date Total donations received by the charity so far in the current year. - * @param current_year The year for which the donation data is being tracked. - * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available. - */ -typedef void -(*TALER_MERCHANTDB_DonauInstanceCallback)( - void *cls, - uint64_t donau_instance_serial, - const char *donau_url, - const char *charity_name, - const struct DONAU_CharityPublicKeyP *charity_pub_key, - uint64_t charity_id, - const struct TALER_Amount *charity_max_per_year, - const struct TALER_Amount *charity_receipts_to_date, - int64_t current_year, - const json_t *donau_keys_json - ); - -/** - * Select all Donau instances from the database, regardless - * of instance or key status. - * - * @param pg database context - * @param cb callback function to call with each result - * @param cb_cls closure for the callback - * @return status of the PG - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_all_donau_instances ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_DonauInstanceCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_category.h b/src/include/merchant-database/select_category.h @@ -1,50 +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/select_category.h - * @brief implementation of the select_category function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_CATEGORY_H -#define MERCHANT_DATABASE_SELECT_CATEGORY_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about product category. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param category_id category to update - * @param[out] cd set to the category details on success, can be NULL - * (in that case we only want to check if the category exists) - * @param[out] num_products set to length of @a products array - * @param[out] products set to buffer with @a num_products 0-terminated strings with the product IDs, caller must free() it. - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_category (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t category_id, - struct TALER_MERCHANTDB_CategoryDetails *cd, - size_t *num_products, - char **products); - -#endif diff --git a/src/include/merchant-database/select_category_by_name.h b/src/include/merchant-database/select_category_by_name.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/select_category_by_name.h - * @brief implementation of the select_category_by_name function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_CATEGORY_BY_NAME_H -#define MERCHANT_DATABASE_SELECT_CATEGORY_BY_NAME_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about product category by name. - * - * @param pg database context - * @param instance_id instance to lookup template for - * @param category_name category name to look for - * @param[out] name_i18n category name translation - * @param[out] category_id category ID - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_category_by_name (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *category_name, - json_t **name_i18n, - uint64_t *category_id); - -#endif diff --git a/src/include/merchant-database/select_donau_instance_by_serial.h b/src/include/merchant-database/select_donau_instance_by_serial.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/select_donau_instance_by_serial.h - * @brief implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#ifndef MERCHANT_DATABASE_SELECT_DONAU_INSTANCE_BY_SERIAL_H -#define MERCHANT_DATABASE_SELECT_DONAU_INSTANCE_BY_SERIAL_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" -#include "donau/donau_util.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Select Donau instance from the database by serial. - * - * @param pg database context - * @param serial the serial of the Donau instance to select - * @param[out] donau_url Donau URL - * @param[out] charity_id charity ID - * @return status of the PG - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instance_by_serial (struct TALER_MERCHANTDB_PostgresContext *pg, - uint64_t serial, - char **donau_url, - uint64_t *charity_id); - -#endif diff --git a/src/include/merchant-database/select_donau_instances.h b/src/include/merchant-database/select_donau_instances.h @@ -1,76 +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/select_donau_instances.h - * @brief implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#ifndef MERCHANT_DATABASE_SELECT_DONAU_INSTANCES_H -#define MERCHANT_DATABASE_SELECT_DONAU_INSTANCES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Callback function typically used by `select_donau_instances` to handle - * the details of each Donau instance retrieved from the database. - * - * @param cls Closure to pass additional context or data to the callback function. - * @param donau_instance_serial Serial number of the Donau instance in the merchant database. - * @param donau_url The URL of the Donau instance. - * @param charity_name The name of the charity associated with the Donau instance. - * @param charity_pub_key Pointer to the charity's public key used for cryptographic operations. - * @param charity_id The unique identifier for the charity within the Donau instance. - * @param charity_max_per_year Maximum allowed donations to the charity for the current year. - * @param charity_receipts_to_date Total donations received by the charity so far in the current year. - * @param current_year The year for which the donation data is being tracked. - * @param donau_keys_json JSON object containing additional key-related information for the Donau instance, NULL if not (yet) available. - */ -typedef void -(*TALER_MERCHANTDB_DonauInstanceCallback)( - void *cls, - uint64_t donau_instance_serial, - const char *donau_url, - const char *charity_name, - const struct DONAU_CharityPublicKeyP *charity_pub_key, - uint64_t charity_id, - const struct TALER_Amount *charity_max_per_year, - const struct TALER_Amount *charity_receipts_to_date, - int64_t current_year, - const json_t *donau_keys_json - ); - -/** - * Select Donau instances from the database. - * - * @param pg database context - * @param id the ID of the merchant instance, NULL for all instances - * @param cb callback function to call with each result - * @param cb_cls closure for the callback - * @return status of the PG - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instances (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - TALER_MERCHANTDB_DonauInstanceCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_donau_instances_filtered.h b/src/include/merchant-database/select_donau_instances_filtered.h @@ -1,61 +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/select_donau_instances_filtered.h - * @brief implementation of the select_donau_instance function for Postgres - * @author Bohdan Potuzhnyi - * @author Vlada Svirsh - */ -#ifndef MERCHANT_DATABASE_SELECT_DONAU_INSTANCES_FILTERED_H -#define MERCHANT_DATABASE_SELECT_DONAU_INSTANCES_FILTERED_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" -#include "donau/donau_util.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/* Callback typedefs */ -/** - * Callback function typically used by `select_donau_instances` to handle - * the details of each Donau instance retrieved from the database. - * - * @param cls Closure to pass additional context or data to the callback function. - * @param donau_url The URL of the Donau instance. - */ -typedef void -(*TALER_MERCHANTDB_DonauInstanceFilteredCallback)( - void *cls, - const char *donau_url - ); - -/** - * Select multiple Donau instances from the database. - * - * @param pg database context - * @param currency currency to filter donau instances by - * @param cb callback function to call with each result - * @param cb_cls closure for the callback - * @return status of the PG - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_donau_instances_filtered (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *currency, - TALER_MERCHANTDB_DonauInstanceFilteredCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_exchange_keys.h b/src/include/merchant-database/select_exchange_keys.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/select_exchange_keys.h - * @brief implementation of the select_exchange_keys function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_EXCHANGE_KEYS_H -#define MERCHANT_DATABASE_SELECT_EXCHANGE_KEYS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Retrieve exchange's keys from the database. - * - * @param pg database context - * @param exchange_url base URL of the exchange - * @param[out] first_retry set to earliest we may retry fetching the keys - * @param[out] keys set to the keys of the exchange - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_exchange_keys (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *exchange_url, - struct GNUNET_TIME_Absolute *first_retry, - struct TALER_EXCHANGE_Keys **keys); - - -#endif diff --git a/src/include/merchant-database/select_exchanges.h b/src/include/merchant-database/select_exchanges.h @@ -1,67 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file src/include/merchant-database/select_exchanges.h - * @brief implementation of the select_exchanges function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_EXCHANGES_H -#define MERCHANT_DATABASE_SELECT_EXCHANGES_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called about the ``/keys`` status of every exchange - * we are working with. - * - * @param cls closure - * @param exchange_url base URL of the exchange - * @param keys keys of the exchange, NULL if we do not have any yet - * @param next_download when will be the next download - * @param keys_expiration when does the current ``/keys`` response expire - * @param http_status last HTTP status from ``/keys`` - * @param ec last error code from fetching ``/keys`` - */ -typedef void -(*TALER_MERCHANTDB_ExchangesCallback)( - void *cls, - const char *exchange_url, - const json_t *keys, - struct GNUNET_TIME_Absolute next_download, - struct GNUNET_TIME_Absolute keys_expiration, - unsigned int http_status, - enum TALER_ErrorCode ec); - - -/** - * Call @a cb on each exchange we have in the database. - * - * @param pg database context - * @param cb callback to invoke - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_exchanges ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_ExchangesCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/select_login_token.h b/src/include/merchant-database/select_login_token.h @@ -1,48 +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/select_login_token.h - * @brief implementation of the select_login_token function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_LOGIN_TOKEN_H -#define MERCHANT_DATABASE_SELECT_LOGIN_TOKEN_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup information about a login token from database. - * - * @param pg database context - * @param id identifier of the instance - * @param token value of the token - * @param[out] expiration_time set to expiration time - * @param[out] validity_scope set to scope of the token - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_login_token (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *id, - const struct TALER_MERCHANTDB_LoginTokenP *token, - struct GNUNET_TIME_Timestamp *expiration_time, - uint32_t *validity_scope); - - -#endif diff --git a/src/include/merchant-database/select_money_pot.h b/src/include/merchant-database/select_money_pot.h @@ -1,51 +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/select_money_pot.h - * @brief implementation of the select_money_pot function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_MONEY_POT_H -#define MERCHANT_DATABASE_SELECT_MONEY_POT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about a particular money pot. - * - * @param pg database context - * @param instance_id instance to lookup token family for - * @param money_pot_id serial number of the pot to lookup - * @param [out] name set to name of the pot - * @param[out] description set to description of the pot - * @param[out] pot_total_len set to length of @a pot_totals - * @param[out] pot_totals set to amount currently in the pot - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_money_pot (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t money_pot_id, - char **name, - char **description, - size_t *pot_total_len, - struct TALER_Amount **pot_totals); - -#endif diff --git a/src/include/merchant-database/select_money_pots.h b/src/include/merchant-database/select_money_pots.h @@ -1,66 +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/select_money_pots.h - * @brief implementation of the select_money_pots function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_MONEY_POTS_H -#define MERCHANT_DATABASE_SELECT_MONEY_POTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `select_money_pots`. - * - * @param cls closure - * @param name set to name of the pot - * @param pot_total_len length of @a pot_totals array - * @param pot_totals amounts currently in the pot - */ -typedef void -(*TALER_MERCHANTDB_MoneyPotsCallback)( - void *cls, - uint64_t money_pot_id, - const char *name, - size_t pot_total_len, - const struct TALER_Amount *pot_totals); - -/** - * Lookup all of the money pots the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup token families for - * @param limit number of entries to return, negative for descending in execution time, - * positive for ascending in execution time - * @param offset expected_transfer_serial number of the transfer we want to offset from - * @param cb function to call on all money pots found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_money_pots ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_MoneyPotsCallback cb, - void *cb_cls); - -#endif diff --git a/src/include/merchant-database/select_open_transfers.h b/src/include/merchant-database/select_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/select_open_transfers.h - * @brief implementation of the select_open_transfers function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_OPEN_TRANSFERS_H -#define MERCHANT_DATABASE_SELECT_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_select_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/select_order_blinded_sigs.h b/src/include/merchant-database/select_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/select_order_blinded_sigs.h - * @brief Implementation of the select blinded sigs by order_id function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_SELECT_ORDER_BLINDED_SIGS_H -#define MERCHANT_DATABASE_SELECT_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_select_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/select_otp.h b/src/include/merchant-database/select_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/select_otp.h - * @brief implementation of the select_otp function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_OTP_H -#define MERCHANT_DATABASE_SELECT_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_select_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/select_otp_serial.h b/src/include/merchant-database/select_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/select_otp_serial.h - * @brief implementation of the select_otp_serial function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_OTP_SERIAL_H -#define MERCHANT_DATABASE_SELECT_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_select_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/select_product_groups.h b/src/include/merchant-database/select_product_groups.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/select_product_groups.h - * @brief implementation of the select_product_groups function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_PRODUCT_GROUPS_H -#define MERCHANT_DATABASE_SELECT_PRODUCT_GROUPS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `select_product_groups`. - * - * @param cls closure - * @param product_group_id ID of the product group - * @param group_name set to name of the group - * @param group_description set to description of the group - */ -typedef void -(*TALER_MERCHANTDB_ProductGroupsCallback)( - void *cls, - uint64_t product_group_id, - const char *group_name, - const char *group_description); - - -/** - * Lookup all of the product groups the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup product groups for - * @param limit number of entries to return, negative for descending in execution time, - * positive for ascending in execution time - * @param offset expected_transfer_serial number of the transfer we want to offset from - * @param cb function to call on all groups found - * @param cb_cls closure for @a cb - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_product_groups ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_ProductGroupsCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/select_report.h b/src/include/merchant-database/select_report.h @@ -1,66 +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/select_report.h - * @brief implementation of the select_report function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_REPORT_H -#define MERCHANT_DATABASE_SELECT_REPORT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup details about a particular report. - * - * @param pg database context - * @param instance_id instance to lookup reports for - * @param report_id serial number of the report to lookup - * @param[out] report_program_section configuration section of program - * for report generation - * @param[out] report_description text describing the report - * @param[out] mime_type mime type to request from the @a data_source - * @param[out] data_source relative URL (to instance base URL) - * to request report data from - * @param[out] target_address where to send report data - * @param[out] frequency report frequency - * @param[out] frequency_shift how much to shift the report time from a - * multiple of the report @a frequency - * @param[out] next_transmission when will the report be generated next - * @param[out] last_error_code status of the last report - * @param[out] last_error_detail details about failures of last generation - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_report (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - uint64_t report_id, - char **report_program_section, - char **report_description, - char **mime_type, - char **data_source, - char **target_address, - struct GNUNET_TIME_Relative *frequency, - struct GNUNET_TIME_Relative *frequency_shift, - struct GNUNET_TIME_Absolute *next_transmission, - enum TALER_ErrorCode *last_error_code, - char **last_error_detail); - -#endif diff --git a/src/include/merchant-database/select_reports.h b/src/include/merchant-database/select_reports.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/select_reports.h - * @brief implementation of the select_reports function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_REPORTS_H -#define MERCHANT_DATABASE_SELECT_REPORTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Typically called by `select_reports`. - * - * @param cls closure - * @param report_id ID of the report - * @param report_description description of the report - * @param frequency the report frequency - */ -typedef void -(*TALER_MERCHANTDB_ReportsCallback)( - void *cls, - uint64_t report_id, - const char *report_description, - struct GNUNET_TIME_Relative frequency); - - -/** - * Lookup all of the reports the given instance has configured. - * - * @param pg database context - * @param instance_id instance to lookup reports for - * @param limit number of entries to return, negative for descending in execution time, - * positive for ascending in execution time - * @param offset expected_transfer_serial number of the transfer we want to offset from - * @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_select_reports ( - struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_ReportsCallback cb, - void *cb_cls); - - -#endif diff --git a/src/include/merchant-database/select_unit.h b/src/include/merchant-database/select_unit.h @@ -1,45 +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/select_unit.h - * @brief implementation of the select_unit function for Postgres - * @author Bohdan Potuzhnyi - */ -#ifndef MERCHANT_DATABASE_SELECT_UNIT_H -#define MERCHANT_DATABASE_SELECT_UNIT_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -struct TALER_MERCHANTDB_PostgresContext; -/** - * Lookup a measurement unit by identifier. - * - * @param pg database context - * @param instance_id instance owning the unit - * @param unit_id symbolic identifier - * @param[out] ud unit details on success; may be NULL to test for existence - * @return database result code - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_unit (struct TALER_MERCHANTDB_PostgresContext *pg, - const char *instance_id, - const char *unit_id, - struct TALER_MERCHANTDB_UnitDetails *ud); - -#endif diff --git a/src/include/merchant-database/select_wirewatch_accounts.h b/src/include/merchant-database/select_wirewatch_accounts.h @@ -1,64 +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/select_wirewatch_accounts.h - * @brief implementation of the select_wirewatch_accounts function for Postgres - * @author Christian Grothoff - */ -#ifndef MERCHANT_DATABASE_SELECT_WIREWATCH_ACCOUNTS_H -#define MERCHANT_DATABASE_SELECT_WIREWATCH_ACCOUNTS_H - -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "merchantdb_lib.h" - - -/** - * Function called with information about a accounts - * the wirewatcher should monitor. - * - * @param cls closure - * @param instance instance that owns the account - * @param payto_uri account URI - * @param credit_facade_url URL for the credit facade - * @param credit_facade_credentials account access credentials - * @param last_serial last transaction serial (inclusive) we have seen from this account - */ -typedef void -(*TALER_MERCHANTDB_WirewatchWorkCallback)( - void *cls, - const char *instance, - struct TALER_FullPayto payto_uri, - const char *credit_facade_url, - const json_t *credit_facade_credentials, - uint64_t last_serial); - -/** - * Select information about progress made by taler-merchant-wirewatch. - * - * @param pg database context - * @param cb function to call with results - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TALER_MERCHANTDB_select_wirewatch_accounts ( - struct TALER_MERCHANTDB_PostgresContext *pg, - TALER_MERCHANTDB_WirewatchWorkCallback cb, - void *cb_cls); - - -#endif