From 49bbea1c6bbc64f48ccffa6595acbde204c2e867 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 9 Feb 2024 20:05:25 +0100 Subject: remove reserve/rewards --- src/backenddb/Makefile.am | 14 - src/backenddb/merchant-0004.sql | 10 +- src/backenddb/pg_activate_reserve.c | 56 - src/backenddb/pg_activate_reserve.h | 48 - src/backenddb/pg_authorize_reward.c | 449 -------- src/backenddb/pg_authorize_reward.h | 64 -- src/backenddb/pg_delete_reserve.c | 57 - src/backenddb/pg_delete_reserve.h | 42 - src/backenddb/pg_insert_pickup.c | 169 --- src/backenddb/pg_insert_pickup.h | 57 - src/backenddb/pg_insert_pickup_blind_signature.c | 58 - src/backenddb/pg_insert_pickup_blind_signature.h | 46 - src/backenddb/pg_insert_reserve.c | 151 --- src/backenddb/pg_insert_reserve.h | 56 - src/backenddb/pg_lookup_pending_reserves.c | 146 --- src/backenddb/pg_lookup_pending_reserves.h | 41 - src/backenddb/pg_lookup_pickup.c | 174 --- src/backenddb/pg_lookup_pickup.h | 52 - src/backenddb/pg_lookup_reserve.c | 241 ---- src/backenddb/pg_lookup_reserve.h | 47 - src/backenddb/pg_lookup_reserves.c | 216 ---- src/backenddb/pg_lookup_reserves.h | 51 - src/backenddb/pg_lookup_reward.c | 84 -- src/backenddb/pg_lookup_reward.h | 53 - src/backenddb/pg_lookup_reward_details.c | 208 ---- src/backenddb/pg_lookup_reward_details.h | 57 - src/backenddb/pg_lookup_rewards.c | 221 ---- src/backenddb/pg_lookup_rewards.h | 50 - src/backenddb/pg_purge_reserve.c | 54 - src/backenddb/pg_purge_reserve.h | 42 - src/backenddb/plugin_merchantdb_postgres.c | 44 +- src/backenddb/test_merchantdb.c | 1312 +--------------------- 32 files changed, 11 insertions(+), 4359 deletions(-) delete mode 100644 src/backenddb/pg_activate_reserve.c delete mode 100644 src/backenddb/pg_activate_reserve.h delete mode 100644 src/backenddb/pg_authorize_reward.c delete mode 100644 src/backenddb/pg_authorize_reward.h delete mode 100644 src/backenddb/pg_delete_reserve.c delete mode 100644 src/backenddb/pg_delete_reserve.h delete mode 100644 src/backenddb/pg_insert_pickup.c delete mode 100644 src/backenddb/pg_insert_pickup.h delete mode 100644 src/backenddb/pg_insert_pickup_blind_signature.c delete mode 100644 src/backenddb/pg_insert_pickup_blind_signature.h delete mode 100644 src/backenddb/pg_insert_reserve.c delete mode 100644 src/backenddb/pg_insert_reserve.h delete mode 100644 src/backenddb/pg_lookup_pending_reserves.c delete mode 100644 src/backenddb/pg_lookup_pending_reserves.h delete mode 100644 src/backenddb/pg_lookup_pickup.c delete mode 100644 src/backenddb/pg_lookup_pickup.h delete mode 100644 src/backenddb/pg_lookup_reserve.c delete mode 100644 src/backenddb/pg_lookup_reserve.h delete mode 100644 src/backenddb/pg_lookup_reserves.c delete mode 100644 src/backenddb/pg_lookup_reserves.h delete mode 100644 src/backenddb/pg_lookup_reward.c delete mode 100644 src/backenddb/pg_lookup_reward.h delete mode 100644 src/backenddb/pg_lookup_reward_details.c delete mode 100644 src/backenddb/pg_lookup_reward_details.h delete mode 100644 src/backenddb/pg_lookup_rewards.c delete mode 100644 src/backenddb/pg_lookup_rewards.h delete mode 100644 src/backenddb/pg_purge_reserve.c delete mode 100644 src/backenddb/pg_purge_reserve.h (limited to 'src/backenddb') diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 149a43ed..e7fb15cf 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -75,10 +75,6 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_insert_transfer.h pg_insert_transfer.c \ pg_insert_transfer_details.h pg_insert_transfer_details.c \ pg_store_wire_fee_by_exchange.h pg_store_wire_fee_by_exchange.c \ - pg_insert_reserve.h pg_insert_reserve.c \ - pg_activate_reserve.h pg_activate_reserve.c \ - pg_authorize_reward.h pg_authorize_reward.c \ - pg_insert_pickup.h pg_insert_pickup.c \ pg_select_open_transfers.h pg_select_open_transfers.c \ pg_lookup_instances.h pg_lookup_instances.c \ pg_lookup_transfers.h pg_lookup_transfers.c \ @@ -91,7 +87,6 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_delete_login_token.h pg_delete_login_token.c \ pg_select_login_token.h pg_select_login_token.c \ pg_select_account_by_uri.h pg_select_account_by_uri.c \ - pg_lookup_reserves.h pg_lookup_reserves.c \ pg_lookup_instance_auth.h pg_lookup_instance_auth.c \ pg_lookup_pending_deposits.h pg_lookup_pending_deposits.c \ pg_insert_instance.h pg_insert_instance.c \ @@ -163,15 +158,6 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_lookup_transfer.h pg_lookup_transfer.c \ pg_lookup_transfer_summary.h pg_lookup_transfer_summary.c \ pg_lookup_transfer_details.h pg_lookup_transfer_details.c \ - pg_lookup_pending_reserves.h pg_lookup_pending_reserves.c \ - pg_lookup_reserve.h pg_lookup_reserve.c \ - pg_delete_reserve.h pg_delete_reserve.c \ - pg_purge_reserve.h pg_purge_reserve.c \ - pg_lookup_pickup.h pg_lookup_pickup.c \ - pg_lookup_reward.h pg_lookup_reward.c \ - pg_lookup_rewards.h pg_lookup_rewards.c \ - pg_lookup_reward_details.h pg_lookup_reward_details.c \ - pg_insert_pickup_blind_signature.h pg_insert_pickup_blind_signature.c \ pg_lookup_webhooks.h pg_lookup_webhooks.c \ pg_lookup_webhook.h pg_lookup_webhook.c \ pg_delete_webhook.h pg_delete_webhook.c \ diff --git a/src/backenddb/merchant-0004.sql b/src/backenddb/merchant-0004.sql index 47fa71af..711026a2 100644 --- a/src/backenddb/merchant-0004.sql +++ b/src/backenddb/merchant-0004.sql @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2022-2023 Taler Systems SA +-- 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 @@ -16,9 +16,15 @@ BEGIN; -- Check patch versioning is in place. --- SELECT _v.register_patch('merchant-0004', NULL, NULL); +SELECT _v.register_patch('merchant-0004', NULL, NULL); SET search_path TO merchant; +DROP TABLE merchant_reward_pickup_signatures; +DROP TABLE merchant_reward_pickups; +DROP TABLE merchant_rewards; +DROP TABLE merchant_reward_reserve_keys; +DROP TABLE merchant_reward_reserves; + COMMIT; diff --git a/src/backenddb/pg_activate_reserve.c b/src/backenddb/pg_activate_reserve.c deleted file mode 100644 index d7a4ff48..00000000 --- a/src/backenddb/pg_activate_reserve.c +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_activate_reserve.c - * @brief Implementation of the activate_reserve function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include -#include "pg_activate_reserve.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TMH_PG_activate_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *initial_exchange_balance) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - TALER_PQ_query_param_amount_with_currency (pg->conn, - initial_exchange_balance), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "activate_reserve", - "UPDATE merchant_reward_reserves SET" - " exchange_initial_balance=$3" - " WHERE reserve_pub=$2" - " AND merchant_serial=" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "activate_reserve", - params); -} diff --git a/src/backenddb/pg_activate_reserve.h b/src/backenddb/pg_activate_reserve.h deleted file mode 100644 index 3b7c8a3d..00000000 --- a/src/backenddb/pg_activate_reserve.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see - */ -/** - * @file backenddb/pg_activate_reserve.h - * @brief implementation of the activate_reserve function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ACTIVATE_RESERVE_H -#define PG_ACTIVATE_RESERVE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - - -/** - * Confirms @a credit as the amount the exchange claims to have received and - * thus really 'activates' the reserve. This has to happen before rewards can - * be authorized. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance is the reserve tied to - * @param reserve_pub which reserve is topped up or created - * @param initial_exchange_balance how much money was be added to the reserve - * according to the exchange - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - */ -enum GNUNET_DB_QueryStatus -TMH_PG_activate_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *initial_exchange_balance); - -#endif diff --git a/src/backenddb/pg_authorize_reward.c b/src/backenddb/pg_authorize_reward.c deleted file mode 100644 index 5038f4fa..00000000 --- a/src/backenddb/pg_authorize_reward.c +++ /dev/null @@ -1,449 +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 - */ -/** - * @file backenddb/pg_authorize_reward.c - * @brief Implementation of the authorize_reward function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include -#include "pg_authorize_reward.h" -#include "pg_helper.h" - - -/** - * How often do we re-try if we run into a DB serialization error? - */ -#define MAX_RETRIES 3 - - -/** - * Closure for #lookup_reserve_for_reward_cb(). - */ -struct LookupReserveForRewardContext -{ - /** - * Postgres context. - */ - struct PostgresClosure *pg; - - /** - * Public key of the reserve we found. - */ - struct TALER_ReservePublicKeyP reserve_pub; - - /** - * How much money must be left in the reserve. - */ - struct TALER_Amount required_amount; - - /** - * Set to the expiration time of the reserve we found. - * #GNUNET_TIME_UNIT_FOREVER_ABS if we found none. - */ - struct GNUNET_TIME_Timestamp expiration; - - /** - * Error status. - */ - enum TALER_ErrorCode ec; - - /** - * Did we find a good reserve? - */ - bool ok; -}; - - -/** - * How long must a reserve be at least still valid before we use - * it for a reward? - */ -#define MIN_EXPIRATION GNUNET_TIME_UNIT_HOURS - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about accounts. - * - * @param[in,out] cls of type `struct LookupReserveForRewardContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_reserve_for_reward_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupReserveForRewardContext *lac = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_ReservePublicKeyP reserve_pub; - struct TALER_Amount committed_amount; - struct TALER_Amount remaining; - struct TALER_Amount initial_balance; - struct GNUNET_TIME_Timestamp expiration; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance", - &initial_balance), - TALER_PQ_result_spec_amount_with_currency ("rewards_committed", - &committed_amount), - GNUNET_PQ_result_spec_timestamp ("expiration", - &expiration), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - lac->ec = TALER_EC_GENERIC_DB_FETCH_FAILED; - return; - } - if ( (GNUNET_YES != - TALER_amount_cmp_currency (&initial_balance, - &committed_amount)) || - (GNUNET_YES != - TALER_amount_cmp_currency (&initial_balance, - &lac->required_amount)) ) - { - /* insufficient balance */ - if (lac->ok) - continue; /* got another reserve */ - lac->ec = TALER_EC_MERCHANT_GENERIC_CURRENCY_MISMATCH; - continue; - } - if (0 > - TALER_amount_subtract (&remaining, - &initial_balance, - &committed_amount)) - { - GNUNET_break (0); - continue; - } - if (0 > - TALER_amount_cmp (&remaining, - &lac->required_amount)) - { - /* insufficient balance */ - if (lac->ok) - continue; /* got another reserve */ - lac->ec = - TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_INSUFFICIENT_FUNDS; - continue; - } - if ( (! GNUNET_TIME_absolute_is_never (lac->expiration.abs_time)) && - GNUNET_TIME_timestamp_cmp (expiration, - >, - lac->expiration) && - GNUNET_TIME_relative_cmp ( - GNUNET_TIME_absolute_get_remaining (lac->expiration.abs_time), - >, - MIN_EXPIRATION) ) - { - /* reserve expired */ - if (lac->ok) - continue; /* got another reserve */ - lac->ec = TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_EXPIRED; - continue; - } - lac->ok = true; - lac->ec = TALER_EC_NONE; - lac->expiration = expiration; - lac->reserve_pub = reserve_pub; - } -} - - -enum TALER_ErrorCode -TMH_PG_authorize_reward (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *amount, - const char *justification, - const char *next_url, - struct TALER_RewardIdentifierP *reward_id, - struct GNUNET_TIME_Timestamp *expiration) -{ - struct PostgresClosure *pg = cls; - unsigned int retries = 0; - enum GNUNET_DB_QueryStatus qs; - struct TALER_Amount rewards_committed; - struct TALER_Amount exchange_initial_balance; - const struct TALER_ReservePublicKeyP *reserve_pubp; - struct LookupReserveForRewardContext lac = { - .pg = pg, - .required_amount = *amount, - .expiration = GNUNET_TIME_UNIT_FOREVER_TS - }; - - check_connection (pg); - PREPARE (pg, - "lookup_reserve_for_reward", - "SELECT" - " reserve_pub" - ",expiration" - ",exchange_initial_balance" - ",rewards_committed" - " FROM merchant_reward_reserves" - " WHERE" - " merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - PREPARE (pg, - "lookup_reserve_status", - "SELECT" - " expiration" - ",exchange_initial_balance" - ",rewards_committed" - " FROM merchant_reward_reserves" - " WHERE reserve_pub = $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - PREPARE (pg, - "update_reserve_rewards_committed", - "UPDATE merchant_reward_reserves SET" - " rewards_committed=$3" - " WHERE reserve_pub=$2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - PREPARE (pg, - "insert_reward", - "INSERT INTO merchant_rewards" - "(reserve_serial" - ",reward_id" - ",justification" - ",next_url" - ",expiration" - ",amount" - ",picked_up" - ") " - "SELECT" - " reserve_serial, $3, $4, $5, $6, $7, $8" - " FROM merchant_reward_reserves" - " WHERE reserve_pub=$2" - " AND merchant_serial = " - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); -RETRY: - reserve_pubp = reserve_pub; - if (MAX_RETRIES < ++retries) - { - GNUNET_break (0); - return - TALER_EC_GENERIC_DB_SOFT_FAILURE; - } - if (GNUNET_OK != - TMH_PG_start (pg, - "authorize reward")) - { - GNUNET_break (0); - return TALER_EC_GENERIC_DB_START_FAILED; - } - if (NULL == reserve_pubp) - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_reserve_for_reward", - params, - &lookup_reserve_for_reward_cb, - &lac); - switch (qs) - { - case GNUNET_DB_STATUS_SOFT_ERROR: - TMH_PG_rollback (pg); - goto RETRY; - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_FETCH_FAILED; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - TMH_PG_rollback (pg); - return TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_NOT_FOUND; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - default: - break; - } - if (TALER_EC_NONE != lac.ec) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Enabling reward reserved failed with status %d\n", - lac.ec); - TMH_PG_rollback (pg); - return lac.ec; - } - GNUNET_assert (lac.ok); - reserve_pubp = &lac.reserve_pub; - } - - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pubp), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("expiration", - expiration), - TALER_PQ_result_spec_amount_with_currency ("rewards_committed", - &rewards_committed), - TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance", - &exchange_initial_balance), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_reserve_status", - params, - rs); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - { - TMH_PG_rollback (pg); - goto RETRY; - } - if (qs < 0) - { - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_FETCH_FAILED; - } - if (0 == qs) - { - TMH_PG_rollback (pg); - return TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_NOT_FOUND; - } - } - { - struct TALER_Amount remaining; - - if (0 > - TALER_amount_subtract (&remaining, - &exchange_initial_balance, - &rewards_committed)) - { - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_INVARIANT_FAILURE; - } - if (GNUNET_YES != - TALER_amount_cmp_currency (&remaining, - amount)) - { - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_CURRENCY_MISMATCH; - } - - if (0 > - TALER_amount_cmp (&remaining, - amount)) - { - TMH_PG_rollback (pg); - return TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_INSUFFICIENT_FUNDS; - } - } - GNUNET_assert (0 <= - TALER_amount_add (&rewards_committed, - &rewards_committed, - amount)); - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pubp), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &rewards_committed), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_reserve_rewards_committed", - params); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - { - TMH_PG_rollback (pg); - goto RETRY; - } - if (qs < 0) - { - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_STORE_FAILED; - } - } - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - reward_id, - sizeof (*reward_id)); - { - struct TALER_Amount zero; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pubp), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_string (justification), - GNUNET_PQ_query_param_string (next_url), - GNUNET_PQ_query_param_timestamp (expiration), - TALER_PQ_query_param_amount_with_currency (pg->conn, - amount), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &zero), - GNUNET_PQ_query_param_end - }; - - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (amount->currency, - &zero)); - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_reward", - params); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - { - TMH_PG_rollback (pg); - goto RETRY; - } - if (qs < 0) - { - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_STORE_FAILED; - } - } - qs = TMH_PG_commit (pg); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto RETRY; - if (qs < 0) - { - GNUNET_break (0); - TMH_PG_rollback (pg); - return TALER_EC_GENERIC_DB_COMMIT_FAILED; - } - return TALER_EC_NONE; -} diff --git a/src/backenddb/pg_authorize_reward.h b/src/backenddb/pg_authorize_reward.h deleted file mode 100644 index 4ef56bf3..00000000 --- a/src/backenddb/pg_authorize_reward.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_authorize_reward.h - * @brief implementation of the authorize_reward function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_AUTHORIZE_REWARD_H -#define PG_AUTHORIZE_REWARD_H - -#include -#include -#include "taler_merchantdb_plugin.h" - - -/** - * Authorize a reward over @a amount from reserve @a reserve_pub. Remember - * the authorization under @a reward_id for later, together with the - * @a justification. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance should generate the reward - * @param reserve_pub which reserve is debited, NULL to pick one in the DB - * @param amount how high is the reward (with fees) - * @param justification why was the reward approved - * @param next_url where to send the URL post reward pickup - * @param[out] reward_id set to the unique ID for the reward - * @param[out] expiration set to when the reward expires - * @return transaction status, - * #TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_EXPIRED if the reserve is known but has expired - * #TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_NOT_FOUND if the reserve is not known - * #TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_INSUFFICIENT_FUNDS if the reserve has insufficient funds left - * #TALER_EC_GENERIC_DB_START_FAILED on hard DB errors - * #TALER_EC_GENERIC_DB_FETCH_FAILED on hard DB errors - * #TALER_EC_GENERIC_DB_STORE_FAILED on hard DB errors - * #TALER_EC_GENERIC_DB_INVARIANT_FAILURE on hard DB errors - * #TALER_EC_GENERIC_DB_SOFT_FAILURE soft DB errors (client should retry) - * #TALER_EC_NONE upon success - */ -enum TALER_ErrorCode -TMH_PG_authorize_reward (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *amount, - const char *justification, - const char *next_url, - struct TALER_RewardIdentifierP *reward_id, - struct GNUNET_TIME_Timestamp *expiration); - - -#endif diff --git a/src/backenddb/pg_delete_reserve.c b/src/backenddb/pg_delete_reserve.c deleted file mode 100644 index f31e7c7a..00000000 --- a/src/backenddb/pg_delete_reserve.c +++ /dev/null @@ -1,57 +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 - */ -/** - * @file backenddb/pg_delete_reserve.c - * @brief Implementation of the delete_reserve function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_delete_reserve.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TMH_PG_delete_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - PREPARE (pg, - "delete_reserve", - "DELETE" - " FROM merchant_reward_reserve_keys" - " WHERE reserve_serial=" - " (SELECT reserve_serial" - " FROM merchant_reward_reserves" - " WHERE reserve_pub=$2" - " AND merchant_serial=" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1))"); - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "delete_reserve", - params); -} diff --git a/src/backenddb/pg_delete_reserve.h b/src/backenddb/pg_delete_reserve.h deleted file mode 100644 index f3aa2403..00000000 --- a/src/backenddb/pg_delete_reserve.h +++ /dev/null @@ -1,42 +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 - */ -/** - * @file backenddb/pg_delete_reserve.h - * @brief implementation of the delete_reserve function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_DELETE_RESERVE_H -#define PG_DELETE_RESERVE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Delete a reserve's private key. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance is the reserve tied to - * @param reserve_pub which reserve is to be deleted - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - */ -enum GNUNET_DB_QueryStatus -TMH_PG_delete_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub); - -#endif diff --git a/src/backenddb/pg_insert_pickup.c b/src/backenddb/pg_insert_pickup.c deleted file mode 100644 index 4094d748..00000000 --- a/src/backenddb/pg_insert_pickup.c +++ /dev/null @@ -1,169 +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 - */ -/** - * @file backenddb/pg_insert_pickup.c - * @brief Implementation of the insert_pickup function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include -#include "pg_insert_pickup.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TMH_PG_insert_pickup ( - void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - const struct TALER_Amount *total_picked_up, - const struct TALER_PickupIdentifierP *pickup_id, - const struct TALER_Amount *total_requested) -{ - struct PostgresClosure *pg = cls; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "insert_pickup", - "INSERT INTO merchant_reward_pickups" - "(reward_serial" - ",pickup_id" - ",amount" - ") " - "SELECT" - " reward_serial, $3, $4" - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE reward_id=$2" - " AND merchant_serial = " - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - PREPARE (pg, - "update_picked_up_reward", - "UPDATE merchant_rewards SET" - " picked_up=$2" - ",was_picked_up = (CAST($2 AS taler_amount_currency) = amount)" - " WHERE reward_id = $1"); - PREPARE (pg, - "lookup_picked_up_reserve", - "SELECT" - " reserve_serial" - ",rewards_picked_up" - " FROM merchant_reward_reserves" - " JOIN merchant_rewards USING (reserve_serial)" - " WHERE reward_id=$2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - PREPARE (pg, - "update_picked_up_reserve", - "UPDATE merchant_reward_reserves SET" - " rewards_picked_up=$2" - " WHERE reserve_serial = $1"); - - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_auto_from_type (pickup_id), - TALER_PQ_query_param_amount_with_currency (pg->conn, - total_requested), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_pickup", - params); - if (0 > qs) - return qs; - } - - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (reward_id), - TALER_PQ_query_param_amount_with_currency (pg->conn, - total_picked_up), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_picked_up_reward", - params); - if (0 > qs) - return qs; - } - { - uint64_t reserve_serial; - struct TALER_Amount reserve_picked_up; - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("reserve_serial", - &reserve_serial), - TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up", - &reserve_picked_up), - GNUNET_PQ_result_spec_end - - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_picked_up_reserve", - params, - rs); - if (0 > qs) - return qs; - } - if (GNUNET_OK != - TALER_amount_cmp_currency (&reserve_picked_up, - total_requested)) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - if (0 >= - TALER_amount_add (&reserve_picked_up, - &reserve_picked_up, - total_requested)) - { - GNUNET_break (0); - return GNUNET_DB_STATUS_HARD_ERROR; - } - - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&reserve_serial), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &reserve_picked_up), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_picked_up_reserve", - params); - if (0 > qs) - return qs; - } - } - return qs; -} diff --git a/src/backenddb/pg_insert_pickup.h b/src/backenddb/pg_insert_pickup.h deleted file mode 100644 index d9e960c5..00000000 --- a/src/backenddb/pg_insert_pickup.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_insert_pickup.h - * @brief implementation of the insert_pickup function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_INSERT_PICKUP_H -#define PG_INSERT_PICKUP_H - -#include -#include -#include "taler_merchantdb_plugin.h" - - -/** - * Insert details about a reward pickup operation. The @a total_picked_up - * UPDATES the total amount under the @a reward_id, while the @a - * total_requested is the amount to be associated with this @a pickup_id. - * While there is usually only one pickup event that picks up the entire - * amount, our schema allows for wallets to pick up the amount incrementally - * over mulrewardle pick up operations. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance gave the reward - * @param reward_id the unique ID for the reward - * @param total_picked_up how much was picked up overall at this - * point (includes @a total_requested) - * @param pickup_id unique ID for the operation - * @param total_requested how much is being picked up in this operation - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known - */ -enum GNUNET_DB_QueryStatus -TMH_PG_insert_pickup ( - void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - const struct TALER_Amount *total_picked_up, - const struct TALER_PickupIdentifierP *pickup_id, - const struct TALER_Amount *total_requested); - -#endif diff --git a/src/backenddb/pg_insert_pickup_blind_signature.c b/src/backenddb/pg_insert_pickup_blind_signature.c deleted file mode 100644 index 89d51346..00000000 --- a/src/backenddb/pg_insert_pickup_blind_signature.c +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_insert_pickup_blind_signature.c - * @brief Implementation of the insert_pickup_blind_signature function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_insert_pickup_blind_signature.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TMH_PG_insert_pickup_blind_signature (void *cls, - const struct TALER_PickupIdentifierP *pickup_id, - uint32_t offset, - const struct TALER_BlindedDenominationSignature *blind_sig) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (pickup_id), - GNUNET_PQ_query_param_uint32 (&offset), - TALER_PQ_query_param_blinded_denom_sig (blind_sig), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - PREPARE (pg, - "insert_pickup_blind_signature", - "INSERT INTO merchant_reward_pickup_signatures" - "(pickup_serial" - ",coin_offset" - ",blind_sig" - ") " - "SELECT" - " pickup_serial, $2, $3" - " FROM merchant_reward_pickups" - " WHERE pickup_id=$1"); - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_pickup_blind_signature", - params); -} diff --git a/src/backenddb/pg_insert_pickup_blind_signature.h b/src/backenddb/pg_insert_pickup_blind_signature.h deleted file mode 100644 index a4f98275..00000000 --- a/src/backenddb/pg_insert_pickup_blind_signature.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_insert_pickup_blind_signature.h - * @brief implementation of the insert_pickup_blind_signature function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_INSERT_PICKUP_BLIND_SIGNATURE_H -#define PG_INSERT_PICKUP_BLIND_SIGNATURE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Insert blind signature obtained from the exchange during a - * reward pickup operation. - * - * @param cls closure, typically a connection to the db - * @param pickup_id unique ID for the operation - * @param offset offset of the blind signature for the pickup - * @param blind_sig the blind signature - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if @a credit_uuid already known - */ -enum GNUNET_DB_QueryStatus -TMH_PG_insert_pickup_blind_signature (void *cls, - const struct TALER_PickupIdentifierP *pickup_id, - uint32_t offset, - const struct TALER_BlindedDenominationSignature *blind_sig); - -#endif diff --git a/src/backenddb/pg_insert_reserve.c b/src/backenddb/pg_insert_reserve.c deleted file mode 100644 index 173d9304..00000000 --- a/src/backenddb/pg_insert_reserve.c +++ /dev/null @@ -1,151 +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 - */ -/** - * @file backenddb/pg_insert_reserve.c - * @brief Implementation of the insert_reserve function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include -#include "pg_insert_reserve.h" -#include "pg_helper.h" - -/** - * How often do we re-try if we run into a DB serialization error? - */ -#define MAX_RETRIES 3 - - -enum TALER_ErrorCode -TMH_PG_insert_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_MasterPublicKeyP *master_pub, - const char *exchange_url, - const struct TALER_Amount *initial_balance, - struct GNUNET_TIME_Timestamp expiration) -{ - struct PostgresClosure *pg = cls; - unsigned int retries; - enum GNUNET_DB_QueryStatus qs; - - retries = 0; - check_connection (pg); - PREPARE (pg, - "insert_reserve", - "INSERT INTO merchant_reward_reserves" - "(reserve_pub" - ",merchant_serial" - ",creation_time" - ",expiration" - ",merchant_initial_balance" - ",exchange_initial_balance" - ",rewards_committed" - ",rewards_picked_up" - ")" - "SELECT $2, merchant_serial, $3, $4, $5, $6, $6, $6" - " FROM merchant_instances" - " WHERE merchant_id=$1"); -RETRY: - if (MAX_RETRIES < ++retries) - return TALER_EC_GENERIC_DB_SOFT_FAILURE; - if (GNUNET_OK != - TMH_PG_start (pg, - "insert reserve")) - { - GNUNET_break (0); - return TALER_EC_GENERIC_DB_START_FAILED; - } - - /* Setup reserve */ - { - struct TALER_Amount zero; - struct GNUNET_TIME_Timestamp now; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_timestamp (&expiration), - TALER_PQ_query_param_amount_with_currency (pg->conn, - initial_balance), - TALER_PQ_query_param_amount_with_currency (pg->conn, - &zero), - GNUNET_PQ_query_param_end - }; - - now = GNUNET_TIME_timestamp_get (); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (initial_balance->currency, - &zero)); - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_reserve", - params); - if (0 > qs) - { - TMH_PG_rollback (pg); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto RETRY; - return qs; - } - } - /* Store private key */ - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_auto_from_type (reserve_priv), - GNUNET_PQ_query_param_string (exchange_url), - GNUNET_PQ_query_param_auto_from_type (master_pub), - GNUNET_PQ_query_param_end - }; - - PREPARE(pg, - "insert_reserve_key", - "INSERT INTO merchant_reward_reserve_keys" - "(reserve_serial" - ",reserve_priv" - ",exchange_url" - ",master_pub" - ")" - "SELECT reserve_serial, $3, $4, $5" - " FROM merchant_reward_reserves" - " WHERE reserve_pub=$2" - " AND merchant_serial=" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_reserve_key", - params); - if (0 > qs) - { - TMH_PG_rollback (pg); - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto RETRY; - return qs; - } - } - qs = TMH_PG_commit (pg); - if (0 <= qs) - return TALER_EC_NONE; /* success */ - if (GNUNET_DB_STATUS_SOFT_ERROR == qs) - goto RETRY; - return qs; -} diff --git a/src/backenddb/pg_insert_reserve.h b/src/backenddb/pg_insert_reserve.h deleted file mode 100644 index 41bae2ce..00000000 --- a/src/backenddb/pg_insert_reserve.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_insert_reserve.h - * @brief implementation of the insert_reserve function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_INSERT_RESERVE_H -#define PG_INSERT_RESERVE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Add @a credit to a reserve to be used for rewardping. Note that - * this function does not actually perform any wire transfers to - * credit the reserve, it merely tells the merchant backend that - * a reserve now exists. This has to happen before rewards can be - * authorized. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance is the reserve tied to - * @param reserve_priv which reserve is topped up or created - * @param reserve_pub which reserve is topped up or created - * @param master_pub master public key of the exchange - * @param exchange_url what URL is the exchange reachable at where the reserve is located - * @param initial_balance how much money will be added to the reserve - * @param expiration when does the reserve expire? - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - */ -enum TALER_ErrorCode -TMH_PG_insert_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePrivateKeyP *reserve_priv, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_MasterPublicKeyP *master_pub, - const char *exchange_url, - const struct TALER_Amount *initial_balance, - struct GNUNET_TIME_Timestamp expiration); - -#endif diff --git a/src/backenddb/pg_lookup_pending_reserves.c b/src/backenddb/pg_lookup_pending_reserves.c deleted file mode 100644 index f35021c6..00000000 --- a/src/backenddb/pg_lookup_pending_reserves.c +++ /dev/null @@ -1,146 +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 - */ -/** - * @file backenddb/pg_lookup_pending_reserves.c - * @brief Implementation of the lookup_pending_reserves function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_pending_reserves.h" -#include "pg_helper.h" - -/** - * Closure for #lookup_pending_reserves_cb. - */ -struct LookupPendingReservesContext -{ - /** - * Postgres context. - */ - struct PostgresClosure *pg; - - /** - * Function to call with the results - */ - TALER_MERCHANTDB_PendingReservesCallback cb; - - /** - * Closure for @e cb - */ - void *cb_cls; - - /** - * Set in case of 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[in,out] cls of type `struct LookupReservesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_pending_reserves_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupPendingReservesContext *lrc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_ReservePublicKeyP reserve_pub; - struct TALER_Amount merchant_initial_balance; - char *exchange_url; - char *instance_id; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - GNUNET_PQ_result_spec_string ("merchant_id", - &instance_id), - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance", - &merchant_initial_balance), - 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->cb (lrc->cb_cls, - instance_id, - exchange_url, - &reserve_pub, - &merchant_initial_balance); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_pending_reserves (void *cls, - TALER_MERCHANTDB_PendingReservesCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct LookupPendingReservesContext lrc = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - PREPARE (pg, - "lookup_pending_reserves", - "SELECT" - " reserve_pub" - ",merchant_id" - ",exchange_url" - ",merchant_initial_balance" - " FROM merchant_reward_reserves mrr" - " JOIN merchant_instances USING (merchant_serial)" - " JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE (mrr.exchange_initial_balance).val=0" - " AND (mrr.exchange_initial_balance).frac=0"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pending_reserves", - params, - &lookup_pending_reserves_cb, - &lrc); - if (lrc.qs < 0) - return lrc.qs; - return qs; -} diff --git a/src/backenddb/pg_lookup_pending_reserves.h b/src/backenddb/pg_lookup_pending_reserves.h deleted file mode 100644 index 4ffff78f..00000000 --- a/src/backenddb/pg_lookup_pending_reserves.h +++ /dev/null @@ -1,41 +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 - */ -/** - * @file backenddb/pg_lookup_pending_reserves.h - * @brief implementation of the lookup_pending_reserves function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_PENDING_RESERVES_H -#define PG_LOOKUP_PENDING_RESERVES_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup reserves pending activation across all instances. - * - * @param cls closure - * @param cb function to call with reserve summary data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_pending_reserves (void *cls, - TALER_MERCHANTDB_PendingReservesCallback cb, - void *cb_cls); - -#endif diff --git a/src/backenddb/pg_lookup_pickup.c b/src/backenddb/pg_lookup_pickup.c deleted file mode 100644 index f10b948b..00000000 --- a/src/backenddb/pg_lookup_pickup.c +++ /dev/null @@ -1,174 +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 - */ -/** - * @file backenddb/pg_lookup_pickup.c - * @brief Implementation of the lookup_pickup function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_pickup.h" -#include "pg_helper.h" - -/** - * Closure for #lookup_signatures_cb(). - */ -struct LookupSignaturesContext -{ - /** - * Length of the @e sigs array - */ - unsigned int sigs_length; - - /** - * Where to store the signatures. - */ - struct TALER_BlindedDenominationSignature *sigs; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about accounts. - * - * @param[in,out] cls of type `struct LookupSignaturesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_signatures_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupSignaturesContext *lsc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint32_t offset; - struct TALER_BlindedDenominationSignature bsig; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint32 ("coin_offset", - &offset), - TALER_PQ_result_spec_blinded_denom_sig ("blind_sig", - &bsig), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - return; - } - if (offset >= lsc->sigs_length) - { - GNUNET_break_op (0); - GNUNET_PQ_cleanup_result (rs); - continue; - } - /* Must be NULL due to UNIQUE constraint on offset and - requirement that client launched us with 'sigs' - pre-initialized to NULL. */ - lsc->sigs[offset] = bsig; - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_pickup (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - const struct TALER_PickupIdentifierP *pickup_id, - char **exchange_url, - struct TALER_ReservePrivateKeyP *reserve_priv, - unsigned int sigs_length, - struct TALER_BlindedDenominationSignature sigs[]) -{ - struct PostgresClosure *pg = cls; - uint64_t pickup_serial; - - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_auto_from_type (pickup_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("exchange_url", - exchange_url), - GNUNET_PQ_result_spec_auto_from_type ("reserve_priv", - reserve_priv), - GNUNET_PQ_result_spec_uint64 ("pickup_serial", - &pickup_serial), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - PREPARE (pg, - "lookup_pickup", - "SELECT" - " exchange_url" - ",reserve_priv" - ",pickup_serial" - " FROM merchant_reward_pickups" - " JOIN merchant_rewards USING (reward_serial)" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE pickup_id = $3" - " AND reward_id = $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_pickup", - params, - rs); - if (qs <= 0) - return qs; - } - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&pickup_serial), - GNUNET_PQ_query_param_end - }; - struct LookupSignaturesContext lsc = { - .sigs_length = sigs_length, - .sigs = sigs - }; - - PREPARE (pg, - "lookup_pickup_signatures", - "SELECT" - " coin_offset" - ",blind_sig" - " FROM merchant_reward_pickup_signatures" - " WHERE pickup_serial = $1"); - - return GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pickup_signatures", - params, - &lookup_signatures_cb, - &lsc); - } -} diff --git a/src/backenddb/pg_lookup_pickup.h b/src/backenddb/pg_lookup_pickup.h deleted file mode 100644 index b3814731..00000000 --- a/src/backenddb/pg_lookup_pickup.h +++ /dev/null @@ -1,52 +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 - */ -/** - * @file backenddb/pg_lookup_pickup.h - * @brief implementation of the lookup_pickup function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_PICKUP_H -#define PG_LOOKUP_PICKUP_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup pickup details for pickup @a pickup_id. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance should we lookup reward details for - * @param reward_id which reward should we lookup details on - * @param pickup_id which pickup should we lookup details on - * @param[out] exchange_url which exchange is the reward withdrawn from - * @param[out] reserve_priv private key the reward is withdrawn from (set if still available!) - * @param sigs_length length of the @a sigs array - * @param[out] sigs set to the (blind) signatures we have for this @a pickup_id, - * those that are unavailable are left at NULL - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_pickup (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - const struct TALER_PickupIdentifierP *pickup_id, - char **exchange_url, - struct TALER_ReservePrivateKeyP *reserve_priv, - unsigned int sigs_length, - struct TALER_BlindedDenominationSignature sigs[]); - -#endif diff --git a/src/backenddb/pg_lookup_reserve.c b/src/backenddb/pg_lookup_reserve.c deleted file mode 100644 index 392db057..00000000 --- a/src/backenddb/pg_lookup_reserve.c +++ /dev/null @@ -1,241 +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 - */ -/** - * @file backenddb/pg_lookup_reserve.c - * @brief Implementation of the lookup_reserve function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_reserve.h" -#include "pg_helper.h" - -/** - * Closure for #lookup_reserve_rewards_cb(). - */ -struct LookupRewardsContext -{ - /** - * Postgres context. - */ - struct PostgresClosure *pg; - - /** - * Array with information about rewards generated from this reserve. - */ - struct TALER_MERCHANTDB_RewardDetails *rewards; - - /** - * Length of the @e rewards array. - */ - unsigned int rewards_length; - - /** - * Set in case of 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[in,out] cls of type `struct LookupRewardsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_reserve_rewards_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRewardsContext *ltc = cls; - - GNUNET_array_grow (ltc->rewards, - ltc->rewards_length, - num_results); - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_MERCHANTDB_RewardDetails *td = <c->rewards[i]; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("justification", - &td->reason), - GNUNET_PQ_result_spec_auto_from_type ("reward_id", - &td->reward_id), - TALER_PQ_result_spec_amount_with_currency ("amount", - &td->total_amount), - 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; - } - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - bool fetch_rewards, - TALER_MERCHANTDB_ReserveDetailsCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct LookupRewardsContext ltc = { - .pg = pg, - .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_TIME_Timestamp creation_time; - struct GNUNET_TIME_Timestamp expiration_time; - struct TALER_Amount merchant_initial_balance; - struct TALER_Amount exchange_initial_balance; - struct TALER_Amount pickup_amount; - struct TALER_Amount committed_amount; - struct TALER_MasterPublicKeyP master_pub; - bool active; - char *exchange_url = NULL; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("creation_time", - &creation_time), - GNUNET_PQ_result_spec_timestamp ("expiration", - &expiration_time), - TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance", - &merchant_initial_balance), - TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance", - &exchange_initial_balance), - TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up", - &pickup_amount), - TALER_PQ_result_spec_amount_with_currency ("rewards_committed", - &committed_amount), - GNUNET_PQ_result_spec_auto_from_type ("master_pub", - &master_pub), - GNUNET_PQ_result_spec_bool ("active", - &active), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("exchange_url", - &exchange_url), - NULL), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - PREPARE (pg, - "lookup_reserve", - "SELECT" - " creation_time" - ",expiration" - ",merchant_initial_balance" - ",exchange_initial_balance" - ",rewards_committed" - ",rewards_picked_up" - ",reserve_priv IS NOT NULL AS active" - ",exchange_url" - ",master_pub" - " FROM merchant_reward_reserves" - " FULL OUTER JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE reserve_pub = $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_reserve", - params, - rs); - if (qs < 0) - return qs; - if (! fetch_rewards) - { - cb (cb_cls, - creation_time, - expiration_time, - &merchant_initial_balance, - &exchange_initial_balance, - &pickup_amount, - &committed_amount, - active, - &master_pub, - exchange_url, - 0, - NULL); - GNUNET_PQ_cleanup_result (rs); - return qs; - } - - PREPARE (pg, - "lookup_reserve_rewards", - "SELECT" - " justification" - ",reward_id" - ",amount" - " FROM merchant_rewards" - " WHERE reserve_serial =" - " (SELECT reserve_serial" - " FROM merchant_reward_reserves" - " WHERE reserve_pub=$2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1))"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_reserve_rewards", - params, - &lookup_reserve_rewards_cb, - <c); - if (qs < 0) - return qs; - if (ltc.qs >= 0) - { - cb (cb_cls, - creation_time, - expiration_time, - &merchant_initial_balance, - &exchange_initial_balance, - &pickup_amount, - &committed_amount, - active, - &master_pub, - exchange_url, - ltc.rewards_length, - ltc.rewards); - } - for (unsigned int i = 0; i - */ -/** - * @file backenddb/pg_lookup_reserve.h - * @brief implementation of the lookup_reserve function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_RESERVE_H -#define PG_LOOKUP_RESERVE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup reserve details. - * - * @param cls closure - * @param instance_id instance to lookup payments for - * @param reserve_pub public key of the reserve to inspect - * @param fetch_rewards if true, also return information about rewards - * @param cb function to call with reserve summary data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub, - bool fetch_rewards, - TALER_MERCHANTDB_ReserveDetailsCallback cb, - void *cb_cls); - -#endif diff --git a/src/backenddb/pg_lookup_reserves.c b/src/backenddb/pg_lookup_reserves.c deleted file mode 100644 index 48601e5b..00000000 --- a/src/backenddb/pg_lookup_reserves.c +++ /dev/null @@ -1,216 +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 - */ -/** - * @file backenddb/pg_lookup_reserves.c - * @brief Implementation of the lookup_reserves function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_reserves.h" -#include "pg_helper.h" - - -/** - * Closure for #lookup_reserves_cb. - */ -struct LookupReservesContext -{ - /** - * Postgres context. - */ - struct PostgresClosure *pg; - - /** - * Function to call with the results - */ - TALER_MERCHANTDB_ReservesCallback cb; - - /** - * Closure for @e cb - */ - void *cb_cls; - - /** - * Filter by active reserves. - */ - enum TALER_EXCHANGE_YesNoAll active; - - /** - * Filter by failures (mismatch in exchange claimed and - * merchant claimed initial amounts). - */ - enum TALER_EXCHANGE_YesNoAll failures; - - /** - * Set in case of 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[in,out] cls of type `struct LookupReservesContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_reserves_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupReservesContext *lrc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_ReservePublicKeyP reserve_pub; - struct GNUNET_TIME_Timestamp creation_time; - struct GNUNET_TIME_Timestamp expiration_time; - struct TALER_Amount merchant_initial_balance; - struct TALER_Amount exchange_initial_balance; - struct TALER_Amount pickup_amount; - struct TALER_Amount committed_amount; - uint8_t active; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - GNUNET_PQ_result_spec_timestamp ("creation_time", - &creation_time), - GNUNET_PQ_result_spec_timestamp ("expiration", - &expiration_time), - TALER_PQ_result_spec_amount_with_currency ("merchant_initial_balance", - &merchant_initial_balance), - TALER_PQ_result_spec_amount_with_currency ("exchange_initial_balance", - &exchange_initial_balance), - TALER_PQ_result_spec_amount_with_currency ("rewards_committed", - &committed_amount), - TALER_PQ_result_spec_amount_with_currency ("rewards_picked_up", - &pickup_amount), - GNUNET_PQ_result_spec_auto_from_type ("active", - &active), - 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; - } - switch (lrc->active) - { - case TALER_EXCHANGE_YNA_YES: - if (0 == active) - continue; - break; - case TALER_EXCHANGE_YNA_NO: - if (0 != active) - continue; - break; - case TALER_EXCHANGE_YNA_ALL: - break; - } - switch (lrc->failures) - { - case TALER_EXCHANGE_YNA_YES: - if (0 == - TALER_amount_cmp (&merchant_initial_balance, - &exchange_initial_balance)) - continue; - break; - case TALER_EXCHANGE_YNA_NO: - if (0 != - TALER_amount_cmp (&merchant_initial_balance, - &exchange_initial_balance)) - continue; - break; - case TALER_EXCHANGE_YNA_ALL: - break; - } - lrc->cb (lrc->cb_cls, - &reserve_pub, - creation_time, - expiration_time, - &merchant_initial_balance, - &exchange_initial_balance, - &pickup_amount, - &committed_amount, - (0 != active)); - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reserves (void *cls, - const char *instance_id, - struct GNUNET_TIME_Timestamp created_after, - enum TALER_EXCHANGE_YesNoAll active, - enum TALER_EXCHANGE_YesNoAll failures, - TALER_MERCHANTDB_ReservesCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct LookupReservesContext lrc = { - .pg = pg, - .active = active, - .failures = failures, - .cb = cb, - .cb_cls = cb_cls - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_timestamp (&created_after), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - - check_connection (pg); - PREPARE (pg, - "lookup_reserves", - "SELECT" - " reserve_pub" - ",creation_time" - ",expiration" - ",merchant_initial_balance" - ",exchange_initial_balance" - ",rewards_committed" - ",rewards_picked_up" - ",reserve_priv IS NOT NULL AS active" - " FROM merchant_reward_reserves" - " FULL OUTER JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE creation_time > $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_reserves", - params, - &lookup_reserves_cb, - &lrc); - if (lrc.qs < 0) - return lrc.qs; - return qs; -} diff --git a/src/backenddb/pg_lookup_reserves.h b/src/backenddb/pg_lookup_reserves.h deleted file mode 100644 index bf16edc1..00000000 --- a/src/backenddb/pg_lookup_reserves.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_lookup_reserves.h - * @brief implementation of the lookup_reserves function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_LOOKUP_RESERVES_H -#define PG_LOOKUP_RESERVES_H - -#include -#include -#include "taler_merchantdb_plugin.h" - - -/** - * Lookup reserves. - * - * @param cls closure - * @param instance_id instance to lookup payments for - * @param created_after filter by reserves created after this date - * @param active filter by active reserves - * @param failures filter by reserves with a disagreement on the initial balance - * @param cb function to call with reserve summary data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reserves (void *cls, - const char *instance_id, - struct GNUNET_TIME_Timestamp created_after, - enum TALER_EXCHANGE_YesNoAll active, - enum TALER_EXCHANGE_YesNoAll failures, - TALER_MERCHANTDB_ReservesCallback cb, - void *cb_cls); - - -#endif diff --git a/src/backenddb/pg_lookup_reward.c b/src/backenddb/pg_lookup_reward.c deleted file mode 100644 index cb887586..00000000 --- a/src/backenddb/pg_lookup_reward.c +++ /dev/null @@ -1,84 +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 - */ -/** - * @file backenddb/pg_lookup_reward.c - * @brief Implementation of the lookup_reward function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_reward.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reward (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - struct TALER_Amount *total_authorized, - struct TALER_Amount *total_picked_up, - struct GNUNET_TIME_Timestamp *expiration, - char **exchange_url, - char **next_url, - struct TALER_ReservePrivateKeyP *reserve_priv) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount_with_currency ("amount", - total_authorized), - TALER_PQ_result_spec_amount_with_currency ("picked_up", - total_picked_up), - GNUNET_PQ_result_spec_timestamp ("expiration", - expiration), - GNUNET_PQ_result_spec_string ("exchange_url", - exchange_url), - GNUNET_PQ_result_spec_string ("next_url", - next_url), - GNUNET_PQ_result_spec_auto_from_type ("reserve_priv", - reserve_priv), - GNUNET_PQ_result_spec_end - }; - - check_connection (pg); - PREPARE (pg, - "lookup_reward", - "SELECT" - " amount" - ",picked_up" - ",merchant_rewards.expiration" - ",exchange_url" - ",next_url" - ",reserve_priv" - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " JOIN merchant_reward_reserve_keys USING (reserve_serial)" - " WHERE reward_id = $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_reward", - params, - rs); -} diff --git a/src/backenddb/pg_lookup_reward.h b/src/backenddb/pg_lookup_reward.h deleted file mode 100644 index fc23c9ea..00000000 --- a/src/backenddb/pg_lookup_reward.h +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_lookup_reward.h - * @brief implementation of the lookup_reward function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_REWARD_H -#define PG_LOOKUP_REWARD_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup reward details for reward @a reward_id. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance should we lookup reward details for - * @param reward_id which reward should we lookup details on - * @param[out] total_authorized amount how high is the reward (with fees) - * @param[out] total_picked_up how much of the reward was so far picked up (with fees) - * @param[out] expiration set to when the reward expires - * @param[out] exchange_url set to the exchange URL where the reserve is - * @param[out] next_url set to the URL where the wallet should navigate after getting the reward - * @param[out] reserve_priv set to private key of reserve to be debited - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reward (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - struct TALER_Amount *total_authorized, - struct TALER_Amount *total_picked_up, - struct GNUNET_TIME_Timestamp *expiration, - char **exchange_url, - char **next_url, - struct TALER_ReservePrivateKeyP *reserve_priv); - -#endif diff --git a/src/backenddb/pg_lookup_reward_details.c b/src/backenddb/pg_lookup_reward_details.c deleted file mode 100644 index 062fbdd4..00000000 --- a/src/backenddb/pg_lookup_reward_details.c +++ /dev/null @@ -1,208 +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 - */ -/** - * @file backenddb/pg_lookup_reward_details.c - * @brief Implementation of the lookup_reward_details function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_reward_details.h" -#include "pg_helper.h" - -/** - * Closure for #lookup_pickup_details_cb(). - */ -struct LookupRewardDetailsContext -{ - /** - * Length of the @e sigs array - */ - unsigned int *pickups_length; - - /** - * Where to store the signatures. - */ - struct TALER_MERCHANTDB_PickupDetails **pickups; - - /** - * Database handle. - */ - struct PostgresClosure *pg; - - /** - * Transaction status. - */ - enum GNUNET_DB_QueryStatus qs; - -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results about pickups. - * - * @param[in,out] cls of type `struct LookupRewardDetailsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_pickup_details_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRewardDetailsContext *ltdc = cls; - - *ltdc->pickups_length = num_results; - *ltdc->pickups = GNUNET_new_array (num_results, - struct TALER_MERCHANTDB_PickupDetails); - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_MERCHANTDB_PickupDetails *pd = &((*ltdc->pickups)[i]); - uint64_t num_planchets = 0; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("pickup_id", - &pd->pickup_id), - TALER_PQ_result_spec_amount_with_currency ("amount", - &pd->requested_amount), - GNUNET_PQ_result_spec_uint64 ("num_planchets", - &num_planchets), - 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; - GNUNET_array_grow (*ltdc->pickups, - *ltdc->pickups_length, - 0); - return; - } - - pd->num_planchets = num_planchets; - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reward_details (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - bool fpu, - struct TALER_Amount *total_authorized, - struct TALER_Amount *total_picked_up, - char **justification, - struct GNUNET_TIME_Timestamp *expiration, - struct TALER_ReservePublicKeyP *reserve_pub, - unsigned int *pickups_length, - struct TALER_MERCHANTDB_PickupDetails **pickups) -{ - struct PostgresClosure *pg = cls; - uint64_t reward_serial; - enum GNUNET_DB_QueryStatus qs; - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reward_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("reward_serial", - &reward_serial), - TALER_PQ_result_spec_amount_with_currency ("amount", - total_authorized), - TALER_PQ_result_spec_amount_with_currency ("picked_up", - total_picked_up), - GNUNET_PQ_result_spec_string ("justification", - justification), - GNUNET_PQ_result_spec_timestamp ("expiration", - expiration), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - reserve_pub), - GNUNET_PQ_result_spec_end - }; - - check_connection (pg); - PREPARE (pg, - "lookup_reward_details", - "SELECT" - " reward_serial" - ",amount" - ",picked_up" - ",justification" - ",merchant_rewards.expiration" - ",reserve_pub" - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE reward_id = $2" - " AND merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_reward_details", - params, - rs); - if (qs <= 0) - return qs; - if (! fpu) - { - *pickups_length = 0; - *pickups = NULL; - return qs; - } - } - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&reward_serial), - GNUNET_PQ_query_param_end - }; - - struct LookupRewardDetailsContext ltdc = { - .pickups_length = pickups_length, - .pickups = pickups, - .pg = pg, - .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT - }; - - PREPARE (pg, - "lookup_pickup_details", - "SELECT" - " pickup_id" - ",amount" - ",COUNT(blind_sig) AS num_planchets" - " FROM merchant_reward_pickups" - " JOIN merchant_reward_pickup_signatures USING (pickup_serial)" - " WHERE reward_serial = $1" - " GROUP BY pickup_serial"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "lookup_pickup_details", - params, - &lookup_pickup_details_cb, - <dc); - if (qs < 0) - return qs; - return ltdc.qs; - } -} diff --git a/src/backenddb/pg_lookup_reward_details.h b/src/backenddb/pg_lookup_reward_details.h deleted file mode 100644 index 61ff301f..00000000 --- a/src/backenddb/pg_lookup_reward_details.h +++ /dev/null @@ -1,57 +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 - */ -/** - * @file backenddb/pg_lookup_reward_details.h - * @brief implementation of the lookup_reward_details function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_REWARD_DETAILS_H -#define PG_LOOKUP_REWARD_DETAILS_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup reward details for reward @a reward_id. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance should we lookup reward details for - * @param reward_id which reward should we lookup details on - * @param fpu should we fetch details about individual pickups - * @param[out] total_authorized amount how high is the reward (with fees) - * @param[out] total_picked_up how much of the reward was so far picked up (with fees) - * @param[out] justification why was the reward approved - * @param[out] expiration set to when the reward expires - * @param[out] reserve_pub set to which reserve is debited - * @param[out] pickups_length set to the length of @e pickups - * @param[out] pickups if @a fpu is true, set to details about the pickup operations - * @return transaction status, - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_reward_details (void *cls, - const char *instance_id, - const struct TALER_RewardIdentifierP *reward_id, - bool fpu, - struct TALER_Amount *total_authorized, - struct TALER_Amount *total_picked_up, - char **justification, - struct GNUNET_TIME_Timestamp *expiration, - struct TALER_ReservePublicKeyP *reserve_pub, - unsigned int *pickups_length, - struct TALER_MERCHANTDB_PickupDetails **pickups); - -#endif diff --git a/src/backenddb/pg_lookup_rewards.c b/src/backenddb/pg_lookup_rewards.c deleted file mode 100644 index 4914ad58..00000000 --- a/src/backenddb/pg_lookup_rewards.c +++ /dev/null @@ -1,221 +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 - */ -/** - * @file backenddb/pg_lookup_rewards.c - * @brief Implementation of the lookup_rewards function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_lookup_rewards.h" -#include "pg_helper.h" - -/** - * Context used for postgres_lookup_rewards(). - */ -struct LookupMerchantRewardsContext -{ - /** - * Postgres context. - */ - struct PostgresClosure *pg; - - /** - * Function to call with the results. - */ - TALER_MERCHANTDB_RewardsCallback 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 LookupRewardsContext *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lookup_rewards_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupMerchantRewardsContext *plc = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - uint64_t row_id; - struct TALER_RewardIdentifierP reward_id; - struct TALER_Amount reward_amount; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("reward_serial", - &row_id), - GNUNET_PQ_result_spec_auto_from_type ("reward_id", - &reward_id), - TALER_PQ_result_spec_amount_with_currency ("amount", - &reward_amount), - 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, - row_id, - reward_id, - reward_amount); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_rewards (void *cls, - const char *instance_id, - enum TALER_EXCHANGE_YesNoAll expired, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_RewardsCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct LookupMerchantRewardsContext plc = { - .pg = pg, - .cb = cb, - .cb_cls = cb_cls - }; - uint64_t ulimit = (limit > 0) ? limit : -limit; - uint8_t bexpired; - struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_uint64 (&ulimit), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_auto_from_type (&bexpired), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - char stmt[128]; - - bexpired = (TALER_EXCHANGE_YNA_YES == expired); - GNUNET_snprintf (stmt, - sizeof (stmt), - "lookup_rewards_%s%s", - (limit > 0) ? "inc" : "dec", - (TALER_EXCHANGE_YNA_ALL == expired) ? "" : "_expired"); - - check_connection (pg); - PREPARE (pg, - "lookup_rewards_inc", - "SELECT" - " reward_serial" - ",reward_id" - ",amount" - ",CAST($4 as BIGINT)" /* otherwise $4 is unused and Postgres unhappy */ - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " reward_serial > $3" - " ORDER BY reward_serial ASC" - " LIMIT $2"); - PREPARE (pg, - "lookup_rewards_dec", - "SELECT" - " reward_serial" - ",reward_id" - ",amount" - ",CAST($4 as BIGINT)" /* otherwise $4 is unused and Postgres unhappy */ - ",CAST($5 as BOOL)" /* otherwise $5 is unused and Postgres unhappy */ - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " reward_serial < $3" - " ORDER BY reward_serial DESC" - " LIMIT $2"); - PREPARE (pg, - "lookup_rewards_inc_expired", - "SELECT" - " reward_serial" - ",reward_id" - ",amount" - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " reward_serial > $3" - " AND" - " CAST($5 as BOOL) = (merchant_rewards.expiration < $4)" - " ORDER BY reward_serial ASC" - " LIMIT $2"); - PREPARE (pg, - "lookup_rewards_dec_expired", - "SELECT" - " reward_serial" - ",reward_id" - ",amount" - " FROM merchant_rewards" - " JOIN merchant_reward_reserves USING (reserve_serial)" - " WHERE merchant_serial =" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)" - " AND" - " reward_serial < $3" - " AND" - " CAST($5 as BOOL) = (merchant_rewards.expiration < $4)" - " ORDER BY reward_serial DESC" - " LIMIT $2"); - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - stmt, - params, - &lookup_rewards_cb, - &plc); - if (0 != plc.qs) - return plc.qs; - return qs; -} diff --git a/src/backenddb/pg_lookup_rewards.h b/src/backenddb/pg_lookup_rewards.h deleted file mode 100644 index a4fc61ec..00000000 --- a/src/backenddb/pg_lookup_rewards.h +++ /dev/null @@ -1,50 +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 - */ -/** - * @file backenddb/pg_lookup_rewards.h - * @brief implementation of the lookup_rewards function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_LOOKUP_REWARDS_H -#define PG_LOOKUP_REWARDS_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Lookup rewards - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance should we lookup rewards for - * @param expired should we include expired rewards? - * @param limit maximum number of results to return, positive for - * ascending row id, negative for descending - * @param offset row id to start returning results from - * @param cb function to call with reward data - * @param cb_cls closure for @a cb - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TMH_PG_lookup_rewards (void *cls, - const char *instance_id, - enum TALER_EXCHANGE_YesNoAll expired, - int64_t limit, - uint64_t offset, - TALER_MERCHANTDB_RewardsCallback cb, - void *cb_cls); - -#endif diff --git a/src/backenddb/pg_purge_reserve.c b/src/backenddb/pg_purge_reserve.c deleted file mode 100644 index cb01069a..00000000 --- a/src/backenddb/pg_purge_reserve.c +++ /dev/null @@ -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 - */ -/** - * @file backenddb/pg_purge_reserve.c - * @brief Implementation of the purge_reserve function for Postgres - * @author Iván Ávalos - */ -#include "platform.h" -#include -#include -#include -#include "pg_purge_reserve.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TMH_PG_purge_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - PREPARE (pg, - "purge_reserve", - "DELETE" - " FROM merchant_reward_reserves" - " WHERE reserve_pub=$2" - " AND merchant_serial=" - " (SELECT merchant_serial" - " FROM merchant_instances" - " WHERE merchant_id=$1)"); - - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "purge_reserve", - params); -} diff --git a/src/backenddb/pg_purge_reserve.h b/src/backenddb/pg_purge_reserve.h deleted file mode 100644 index 83c1b44f..00000000 --- a/src/backenddb/pg_purge_reserve.h +++ /dev/null @@ -1,42 +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 - */ -/** - * @file backenddb/pg_purge_reserve.h - * @brief implementation of the purge_reserve function for Postgres - * @author Iván Ávalos - */ -#ifndef PG_PURGE_RESERVE_H -#define PG_PURGE_RESERVE_H - -#include -#include -#include "taler_merchantdb_plugin.h" - -/** - * Purge all of the information about a reserve, including rewards. - * - * @param cls closure, typically a connection to the db - * @param instance_id which instance is the reserve tied to - * @param reserve_pub which reserve is to be purged - * @return transaction status, usually - * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT for success - */ -enum GNUNET_DB_QueryStatus -TMH_PG_purge_reserve (void *cls, - const char *instance_id, - const struct TALER_ReservePublicKeyP *reserve_pub); - -#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 40fb1d19..e09b4827 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -50,7 +50,6 @@ #include "pg_delete_exchange_accounts.h" #include "pg_select_accounts_by_exchange.h" #include "pg_insert_exchange_account.h" -#include "pg_lookup_reserves.h" #include "pg_lookup_instance_auth.h" #include "pg_lookup_otp_devices.h" #include "pg_update_transfer_status.h" @@ -113,15 +112,6 @@ #include "pg_lookup_transfer.h" #include "pg_lookup_transfer_summary.h" #include "pg_lookup_transfer_details.h" -#include "pg_lookup_pending_reserves.h" -#include "pg_lookup_reserve.h" -#include "pg_delete_reserve.h" -#include "pg_purge_reserve.h" -#include "pg_lookup_pickup.h" -#include "pg_lookup_reward.h" -#include "pg_lookup_rewards.h" -#include "pg_lookup_reward_details.h" -#include "pg_insert_pickup_blind_signature.h" #include "pg_lookup_webhooks.h" #include "pg_lookup_webhook.h" #include "pg_delete_webhook.h" @@ -143,10 +133,6 @@ #include "pg_insert_transfer.h" #include "pg_insert_transfer_details.h" #include "pg_store_wire_fee_by_exchange.h" -#include "pg_insert_reserve.h" -#include "pg_activate_reserve.h" -#include "pg_authorize_reward.h" -#include "pg_insert_pickup.h" #include "pg_insert_token_family.h" #include "pg_lookup_token_family.h" #include "pg_lookup_token_families.h" @@ -225,7 +211,7 @@ postgres_create_tables (void *cls) * @param es specification of the event to listen for * @param timeout how long to wait for the event * @param cb function to call when the event happens, possibly - * mulrewardle times (until cancel is invoked) + * multiple times (until cancel is invoked) * @param cb_cls closure for @a cb * @return handle useful to cancel the listener */ @@ -533,26 +519,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_select_account; plugin->select_accounts = &TMH_PG_select_accounts; - plugin->lookup_reserves - = &TMH_PG_lookup_reserves; - plugin->lookup_pending_reserves - = &TMH_PG_lookup_pending_reserves; - plugin->lookup_reserve - = &TMH_PG_lookup_reserve; - plugin->delete_reserve - = &TMH_PG_delete_reserve; - plugin->purge_reserve - = &TMH_PG_purge_reserve; - plugin->lookup_pickup - = &TMH_PG_lookup_pickup; - plugin->lookup_reward - = &TMH_PG_lookup_reward; - plugin->lookup_rewards - = &TMH_PG_lookup_rewards; - plugin->lookup_reward_details - = &TMH_PG_lookup_reward_details; - plugin->insert_pickup_blind_signature - = &TMH_PG_insert_pickup_blind_signature; plugin->select_open_transfers = &TMH_PG_select_open_transfers; plugin->insert_exchange_keys @@ -567,14 +533,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_insert_transfer_details; plugin->store_wire_fee_by_exchange = &TMH_PG_store_wire_fee_by_exchange; - plugin->insert_reserve - = &TMH_PG_insert_reserve; - plugin->activate_reserve - = &TMH_PG_activate_reserve; - plugin->authorize_reward - = &TMH_PG_authorize_reward; - plugin->insert_pickup - = &TMH_PG_insert_pickup; plugin->lookup_webhooks = &TMH_PG_lookup_webhooks; plugin->lookup_webhook diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index dbec520b..2b9368f1 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -2029,7 +2029,7 @@ run_test_orders (struct TestOrders_Closure *cls) return 1; } } - /* Test lookups on mulrewardle orders */ + /* Test lookups on multiple orders */ TEST_RET_ON_FAIL (test_insert_order (&cls->instance, &cls->orders[1], GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); @@ -3131,7 +3131,7 @@ run_test_deposits (struct TestDeposits_Closure *cls) &cls->deposits[0].coin_pub, 1, cls->deposits)); - /* Test mulrewardle deposits */ + /* Test multiple deposits */ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance, &cls->signkey, &cls->deposits[1], @@ -4349,1313 +4349,6 @@ test_transfers (void) } -/* Reserves and rewards */ - - -struct ReserveData -{ - /** - * The reserve public key - */ - struct TALER_ReservePublicKeyP reserve_pub; - - /** - * The reserve private key - */ - struct TALER_ReservePrivateKeyP reserve_priv; - - /** - * The reserve initial amount - */ - struct TALER_Amount initial_amount; - - /** - * The exchange url - */ - const char *exchange_url; - - /** - * The exchange master public key. - */ - struct TALER_MasterPublicKeyP master_pub; - - /** - * The expiration date - */ - struct GNUNET_TIME_Timestamp expiration; -}; - - -/** - * Tests inserting a reserve into the database. - * @paper instance the instance the reserve is for. - * @param reserve the reserve to insert. - * @param expected_result the result we expect to receive from the db. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_insert_reserve (const struct InstanceData *instance, - const struct ReserveData *reserve, - enum TALER_ErrorCode expected_result) -{ - TEST_COND_RET_ON_FAIL (expected_result == - plugin->insert_reserve (plugin->cls, - instance->instance.id, - &reserve->reserve_priv, - &reserve->reserve_pub, - &reserve->master_pub, - reserve->exchange_url, - &reserve->initial_amount, - reserve->expiration), - "Insert reserve failed\n"); - return 0; -} - - -/** - * Container for looking up reserves. - */ -struct TestLookupReserve_Closure -{ - /** - * The reserve we expect to find. - */ - const struct ReserveData *reserve_to_cmp; - - /** - * The length of @e rewards. - */ - unsigned int rewards_length; - - /** - * The rewards that have been authorized from the reserve. - */ - const struct TALER_MERCHANTDB_RewardDetails *rewards; - - /** - * 1 if the result matches, 0 otherwise. - */ - int result_matches; -}; - - -/** - * Called after test_lookup_reserve. - * @param cls a pointer to TestLookupReserve_Closure. - * @param creation_time time when the reserve was setup - * @param expiration_time time when the reserve will be closed by the exchange - * @param merchant_initial_amount initial amount that the merchant claims to have filled the - * reserve with - * @param exchange_initial_amount initial amount that the exchange claims to have received - * @param picked_up_amount total of rewards that were picked up from this reserve - * @param committed_amount total of rewards that the merchant committed to, but that were not - * picked up yet - * @param active true if the reserve is still active (we have the private key) - * @param exchange_url base URL of the exchange hosting the reserve, NULL if not @a active - * @param payto_uri URI to use to fund the reserve, NULL if not @a active - * @param rewards_length length of the @a rewards array - * @param rewards information about the rewards created by this reserve - * - * @return 0 on success, 1 otherwise. - */ -static void -lookup_reserve_cb (void *cls, - struct GNUNET_TIME_Timestamp creation_time, - struct GNUNET_TIME_Timestamp expiration_time, - const struct TALER_Amount *merchant_initial_amount, - const struct TALER_Amount *exchange_initial_amount, - const struct TALER_Amount *picked_up_amount, - const struct TALER_Amount *committed_amount, - bool active, - const struct TALER_MasterPublicKeyP *master_pub, - const char *exchange_url, - unsigned int rewards_length, - const struct TALER_MERCHANTDB_RewardDetails *rewards) -{ - struct TestLookupReserve_Closure *cmp = cls; - unsigned int reward_cmp_results[GNUNET_NZL (rewards_length)]; - - if (NULL == cmp) - return; - if (GNUNET_TIME_timestamp_cmp (cmp->reserve_to_cmp->expiration, - !=, - expiration_time) || - (GNUNET_OK != - TALER_amount_cmp_currency ( - &cmp->reserve_to_cmp->initial_amount, - merchant_initial_amount)) || - (0 != TALER_amount_cmp (&cmp->reserve_to_cmp->initial_amount, - merchant_initial_amount)) || - (cmp->rewards_length != rewards_length)) - { - cmp->result_matches = 1; - return; - } - if (0 != strcmp (exchange_url, - "https://exch-url/")) - { - GNUNET_break (0); - cmp->result_matches = 0; - return; - } - if (0 != GNUNET_memcmp (&cmp->reserve_to_cmp->master_pub, - master_pub)) - { - GNUNET_break (0); - cmp->result_matches = 0; - return; - } - memset (reward_cmp_results, - 0, - sizeof (reward_cmp_results)); - for (unsigned int i = 0; rewards_length > i; ++i) - { - for (unsigned int j = 0; rewards_length > j; ++j) - { - if ((GNUNET_OK == TALER_amount_cmp_currency ( - &cmp->rewards[i].total_amount, - &rewards[j].total_amount)) && - (0 == TALER_amount_cmp (&cmp->rewards[i].total_amount, - &rewards[j].total_amount)) && - (0 == strcmp (cmp->rewards[i].reason, - rewards[j].reason))) - { - reward_cmp_results[i] += 1; - } - } - } - for (unsigned int i = 0; rewards_length > i; ++i) - { - if (1 != reward_cmp_results[i]) - { - cmp->result_matches = 1; - return; - } - } - cmp->result_matches = 0; -} - - -/** - * Tests looking up details of a reserve from the database. - * @param instance the instance to lookup the reserve from. - * @param reserve_pub the public key of the reserve we are looking for. - * @param reserve the data we expect to find. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_reserve (const struct InstanceData *instance, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct ReserveData *reserve) -{ - struct TestLookupReserve_Closure cmp = { - .reserve_to_cmp = reserve, - .rewards_length = 0, - .rewards = NULL, - .result_matches = 0 - }; - if (1 != plugin->lookup_reserve (plugin->cls, - instance->instance.id, - reserve_pub, - false, - &lookup_reserve_cb, - &cmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reserve failed\n"); - return 1; - } - if (0 != cmp.result_matches) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reserve failed: result does not match\n"); - return 1; - } - return 0; -} - - -/** - * Container for looking up mulrewardle reserves. - */ -struct TestLookupReserves_Closure -{ - /** - * The length of @e reserves_to_cmp. - */ - unsigned int reserves_to_cmp_length; - - /** - * The reserves we expect to find from the lookup. - */ - const struct ReserveData *reserves_to_cmp; - - /** - * The number of results matching each reserve we were looking for. - */ - unsigned int *results_matching; - - /** - * The total number of results found from the lookup. - */ - unsigned int results_length; -}; - - -/** - * Called after test_lookup_reserves. - * @param cls pointer to a TestLookupReserves_Closure. - * @param reserve_pub public key of the reserve - * @param creation_time time when the reserve was setup - * @param expiration_time time when the reserve will be closed by the exchange - * @param merchant_initial_amount initial amount that the merchant claims to have filled the - * reserve with - * @param exchange_initial_amount initial amount that the exchange claims to have received - * @param pickup_amount total of rewards that were picked up from this reserve - * @param committed_amount total of rewards that the merchant committed to, but that were not - * picked up yet - * @param active true if the reserve is still active (we have the private key) - */ -static void -lookup_reserves_cb (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct GNUNET_TIME_Timestamp creation_time, - struct GNUNET_TIME_Timestamp expiration_time, - const struct TALER_Amount *merchant_initial_amount, - const struct TALER_Amount *exchange_initial_amount, - const struct TALER_Amount *pickup_amount, - const struct TALER_Amount *committed_amount, - bool active) -{ - struct TestLookupReserves_Closure *cmp = cls; - if (NULL == cmp) - return; - for (unsigned int i = 0; cmp->reserves_to_cmp_length > i; ++i) - { - if ((0 == - GNUNET_memcmp (&cmp->reserves_to_cmp[i].reserve_pub, - reserve_pub)) && - (GNUNET_TIME_timestamp_cmp (cmp->reserves_to_cmp[i].expiration, - ==, - expiration_time)) && - (GNUNET_OK == - TALER_amount_cmp_currency ( - &cmp->reserves_to_cmp[i].initial_amount, - merchant_initial_amount)) && - (0 == TALER_amount_cmp (&cmp->reserves_to_cmp[i].initial_amount, - merchant_initial_amount))) - { - cmp->results_matching[i] += 1; - } - } - cmp->results_length += 1; -} - - -/** - * Test looking up reserves for an instance. - * @param instance the instance to get the reserves from. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_reserves (const struct InstanceData *instance, - unsigned int reserves_length, - const struct ReserveData *reserves) -{ - unsigned int results_matching[reserves_length]; - struct TestLookupReserves_Closure cmp = { - .reserves_to_cmp_length = reserves_length, - .reserves_to_cmp = reserves, - .results_matching = results_matching, - .results_length = 0 - }; - memset (results_matching, 0, sizeof (unsigned int) * reserves_length); - if (1 != plugin->lookup_reserves (plugin->cls, - instance->instance.id, - GNUNET_TIME_UNIT_ZERO_TS, - TALER_EXCHANGE_YNA_ALL, - TALER_EXCHANGE_YNA_ALL, - &lookup_reserves_cb, - &cmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reserves failed\n"); - return 1; - } - if (reserves_length != cmp.results_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reserves failed: incorrect number of results (%d)\n", - cmp.results_length); - return 1; - } - for (unsigned int i = 0; reserves_length > i; ++i) - { - if (1 != cmp.results_matching[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reserves failed: mismatched data\n"); - return 1; - } - } - return 0; -} - - -/** - * Called after test_lookup_pending_reserves. - * @param cls pointer to a TestLookupReserves_Closure. - * @param instance_id the id of the instance the reserve belongs to. - * @param exchange_url url of the exchange for this reserve. - * @param reserve_pub public key of this reserve. - * @param expected_amount what the amount in the reserve is, according to the db. - */ -static void -lookup_pending_reserves_cb (void *cls, - const char *instance_id, - const char *exchange_url, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *expected_amount) -{ - struct TestLookupReserves_Closure *cmp = cls; - if (NULL == cmp) - return; - for (unsigned int i = 0; cmp->reserves_to_cmp_length > i; ++i) - { - if ((0 == GNUNET_memcmp (&cmp->reserves_to_cmp[i].reserve_pub, - reserve_pub)) && - (0 == strcmp (cmp->reserves_to_cmp[i].exchange_url, - exchange_url)) && - (GNUNET_OK == TALER_amount_cmp_currency ( - &cmp->reserves_to_cmp[i].initial_amount, - expected_amount)) && - (0 == TALER_amount_cmp (&cmp->reserves_to_cmp[i].initial_amount, - expected_amount))) - { - cmp->results_matching[i] += 1; - } - } - cmp->results_length += 1; -} - - -/** - * Tests looking up reserves that are not activated from the database. - * @param reserves_length length of @e reserves. - * @param reserves the reserves that the db is expected to return. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_pending_reserves (unsigned int reserves_length, - const struct ReserveData *reserves) -{ - unsigned int results_matching[GNUNET_NZL (reserves_length)]; - struct TestLookupReserves_Closure cmp = { - .reserves_to_cmp_length = reserves_length, - .reserves_to_cmp = reserves, - .results_matching = results_matching, - .results_length = 0 - }; - memset (results_matching, 0, sizeof (unsigned int) * reserves_length); - if (0 > plugin->lookup_pending_reserves (plugin->cls, - &lookup_pending_reserves_cb, - &cmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pending reserves failed\n"); - return 1; - } - if (reserves_length != cmp.results_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pending reserves failed: incorrect number of results (%d)\n", - cmp.results_length); - return 1; - } - for (unsigned int i = 0; reserves_length > i; ++i) - { - if (1 != cmp.results_matching[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pending reserves failed: mismatched data\n"); - return 1; - } - } - return 0; -} - - -/** - * Container for all reward data relevant to the database. - */ -struct RewardData -{ - /** - * The details of the reward. - */ - struct TALER_MERCHANTDB_RewardDetails details; - - /** - * Where the user should be redirected. - */ - const char *next_url; - - /** - * When the reward expires. - */ - struct GNUNET_TIME_Timestamp expiration; -}; - - -/** - * Creates a reward for testing. - * @param reward the reward to fill with data. - */ -static void -make_reward (struct RewardData *reward) -{ - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount ("EUR:0.99", - &reward->details.total_amount)); - reward->details.reason = "because"; - reward->next_url = "https://taler.net"; -} - - -/** - * Tests authorizing a reward. - * @param instance the instance authorizing the reward. - * @param reserve where the reward is coming from. - * @param reward the reward to authorize. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_authorize_reward (const struct InstanceData *instance, - const struct ReserveData *reserve, - struct RewardData *reward) -{ - TEST_COND_RET_ON_FAIL (TALER_EC_NONE == - plugin->authorize_reward (plugin->cls, - instance->instance.id, - &reserve->reserve_pub, - &reward->details.total_amount, - reward->details.reason, - reward->next_url, - &reward->details.reward_id, - &reward->expiration), - "Authorize reward failed\n"); - return 0; -} - - -/** - * Tests looking up a reward from the database. - * @param instance the instance to look up rewards from. - * @param reserve the reserve to look up rewards from. - * @param reward the reward we expect to find (uses @e reward_id to perform lookup). - * @param expected_total_picked_up how much of the reward should have been - * picked up. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_reward (const struct InstanceData *instance, - const struct ReserveData *reserve, - const struct RewardData *reward, - const struct TALER_Amount *expected_total_picked_up) -{ - struct TALER_Amount total_authorized; - struct TALER_Amount total_picked_up; - struct GNUNET_TIME_Timestamp expiration; - char *exchange_url = NULL; - char *next_url = NULL; - struct TALER_ReservePrivateKeyP reserve_priv; - - if (1 != plugin->lookup_reward (plugin->cls, - instance->instance.id, - &reward->details.reward_id, - &total_authorized, - &total_picked_up, - &expiration, - &exchange_url, - &next_url, - &reserve_priv)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reward failed\n"); - GNUNET_free (exchange_url); - return 1; - } - if ((GNUNET_OK != - TALER_amount_cmp_currency (&reward->details.total_amount, - &total_authorized)) || - (0 != TALER_amount_cmp (&reward->details.total_amount, - &total_authorized)) || - (GNUNET_OK != - TALER_amount_cmp_currency (expected_total_picked_up, - &total_picked_up)) || - (0 != TALER_amount_cmp (expected_total_picked_up, - &total_picked_up)) || - (GNUNET_TIME_timestamp_cmp (reward->expiration, - !=, - expiration)) || - (0 != strcmp (reserve->exchange_url, - exchange_url)) || - (0 != GNUNET_memcmp (&reserve->reserve_priv, - &reserve_priv))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reward failed: mismatched data\n"); - GNUNET_free (exchange_url); - GNUNET_free (next_url); - return 1; - } - GNUNET_free (exchange_url); - GNUNET_free (next_url); - return 0; -} - - -/** - * Tests looking up the details of a reward from the database. - * - * @param instance the instance the reward is in. - * @param reserve the reserve the reward was authorized from. - * @param reward the reward we expect to find (uses @e reward_id to perform lookup). - * @param expected_total_picked_up how much of the reward should have been - * picked up. - * @param expected_pickups_length the length of @e expected_pickups. - * @param expected_pickups the pickups that we expect to be associated with - * the reward. - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_reward_details ( - const struct InstanceData *instance, - const struct ReserveData *reserve, - const struct RewardData *reward, - const struct TALER_Amount *expected_total_picked_up, - unsigned int expected_pickups_length, - const struct TALER_MERCHANTDB_PickupDetails *expected_pickups) -{ - struct TALER_Amount total_authorized; - struct TALER_Amount total_picked_up; - char *justification = NULL; - struct GNUNET_TIME_Timestamp expiration; - struct TALER_ReservePublicKeyP reserve_pub; - unsigned int pickups_length; - struct TALER_MERCHANTDB_PickupDetails *pickups = NULL; - unsigned int results_matching[GNUNET_NZL (expected_pickups_length)]; - - if (0 > - plugin->lookup_reward_details (plugin->cls, - instance->instance.id, - &reward->details.reward_id, - true, - &total_authorized, - &total_picked_up, - &justification, - &expiration, - &reserve_pub, - &pickups_length, - &pickups)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reward details failed\n"); - GNUNET_free (justification); - GNUNET_free (pickups); - return 1; - } - if ( (GNUNET_OK != - TALER_amount_cmp_currency (&reward->details.total_amount, - &total_authorized)) || - (0 != TALER_amount_cmp (&reward->details.total_amount, - &total_authorized)) || - (GNUNET_OK != - TALER_amount_cmp_currency (expected_total_picked_up, - &total_picked_up)) || - (0 != TALER_amount_cmp (expected_total_picked_up, - &total_picked_up)) || - (0 != strcmp (reward->details.reason, - justification)) || - (GNUNET_TIME_timestamp_cmp (reward->expiration, - !=, - expiration)) || - (0 != GNUNET_memcmp (&reserve->reserve_pub, - &reserve_pub)) || - (expected_pickups_length != pickups_length) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reward details failed: mismatched data\n"); - GNUNET_free (justification); - GNUNET_free (pickups); - return 1; - } - memset (results_matching, - 0, - sizeof (unsigned int) * expected_pickups_length); - for (unsigned int i = 0; expected_pickups_length > i; ++i) - { - for (unsigned int j = 0; pickups_length > j; ++j) - { - /* Compare expected_pickups[i] with pickups[j] */ - if ((0 == GNUNET_memcmp (&expected_pickups[i].pickup_id, - &pickups[j].pickup_id)) && - (GNUNET_OK == TALER_amount_cmp_currency ( - &expected_pickups[i].requested_amount, - &pickups[j].requested_amount)) && - (0 == TALER_amount_cmp (&expected_pickups[i].requested_amount, - &pickups[j].requested_amount)) && - (expected_pickups[i].num_planchets == pickups[j].num_planchets)) - { - results_matching[i] += 1; - } - } - } - for (unsigned int i = 0; expected_pickups_length > i; ++i) - { - if (1 != results_matching[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup reward details failed: mismatched data\n"); - GNUNET_free (justification); - GNUNET_free (pickups); - return 1; - } - } - GNUNET_free (justification); - GNUNET_free (pickups); - return 0; -} - - -/** - * Utility function for freeing an array of RSA signatures. - * @param sigs_length length of @e sigs. - * @param sigs the signatures to free. - */ -static void -free_signature_array (unsigned int sigs_length, - struct TALER_BlindedDenominationSignature *sigs) -{ - for (unsigned int i = 0; sigs_length > i; ++i) - TALER_blinded_denom_sig_free (&sigs[i]); -} - - -/** - * Tests looking up a reward pickup. - * @param instance the instance to look up from. - * @param reward the reward the pickup was made for. - * @param pickup_id id of the pickup to look up. - * @param expected_exchange_url exchange url for the pickup. - * @param expected_reserve_priv reserve private key for the pickup. - * @param expected_sigs_length length of @e expected_sigs. - * @param expected_sigs the signatures we expect to be made for the pickup. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_pickup ( - const struct InstanceData *instance, - const struct RewardData *reward, - const struct TALER_PickupIdentifierP *pickup_id, - const char *expected_exchange_url, - const struct TALER_ReservePrivateKeyP *expected_reserve_priv, - unsigned int expected_sigs_length, - const struct TALER_BlindedDenominationSignature *expected_sigs) -{ - char *exchange_url = NULL; - struct TALER_ReservePrivateKeyP reserve_priv; - struct TALER_BlindedDenominationSignature sigs[GNUNET_NZL ( - expected_sigs_length)]; - unsigned int results_matching[GNUNET_NZL (expected_sigs_length)]; - - memset (sigs, - 0, - sizeof (sigs)); - if (0 > plugin->lookup_pickup (plugin->cls, - instance->instance.id, - &reward->details.reward_id, - pickup_id, - &exchange_url, - &reserve_priv, - expected_sigs_length, - sigs)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pickup failed\n"); - GNUNET_free (exchange_url); - free_signature_array (expected_sigs_length, - sigs); - return 1; - } - if ((0 != strcmp (expected_exchange_url, - exchange_url)) || - (0 != GNUNET_memcmp (expected_reserve_priv, - &reserve_priv))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pickup failed: mismatched data\n"); - GNUNET_free (exchange_url); - free_signature_array (expected_sigs_length, - sigs); - return 1; - } - memset (results_matching, - 0, - sizeof (unsigned int) * expected_sigs_length); - for (unsigned int i = 0; expected_sigs_length > i; ++i) - { - for (unsigned int j = 0; expected_sigs_length > j; ++j) - { - /* compare expected_sigs[i] to sigs[j] */ - if (0 == - TALER_blinded_denom_sig_cmp (&expected_sigs[i], - &sigs[j])) - { - results_matching[i] += 1; - } - } - } - for (unsigned int i = 0; expected_sigs_length > i; ++i) - { - if (1 != results_matching[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pickup failed: mismatched data\n"); - GNUNET_free (exchange_url); - free_signature_array (expected_sigs_length, - sigs); - return 1; - } - } - GNUNET_free (exchange_url); - free_signature_array (expected_sigs_length, - sigs); - return 0; -} - - -/** - * Closure for testing lookup_rewards. - */ -struct TestLookupRewards_Closure -{ - /** - * The length of @e rewards_to_cmp. - */ - unsigned int rewards_to_cmp_length; - - /** - * The rewards that we are expecting to find. - */ - const struct RewardData *rewards_to_cmp; - - /** - * The number of results found from the lookup. - */ - unsigned int results_length; - - /** - * Whether each result matches with the corresponding reward in @rewards_to_cmp. - */ - bool *results_match; -}; - - -/** - * Called after test_lookup_rewards. - * @param cls pointer to a TestLookupRewards_Closure. - * @param row_id the row id of the reward. - * @param reward_id the id of the reward. - * @param amount the amount of the reward. - */ -static void -lookup_rewards_cb (void *cls, - uint64_t row_id, - struct TALER_RewardIdentifierP reward_id, - struct TALER_Amount amount) -{ - struct TestLookupRewards_Closure *cmp = cls; - if (NULL == cmp) - return; - unsigned int i = cmp->results_length; - cmp->results_length += 1; - if (cmp->rewards_to_cmp_length > i) - { - if ((0 == GNUNET_memcmp (&cmp->rewards_to_cmp[i].details.reward_id, - &reward_id)) && - (GNUNET_OK == TALER_amount_cmp_currency ( - &cmp->rewards_to_cmp[i].details.total_amount, - &amount)) && - (0 == TALER_amount_cmp (&cmp->rewards_to_cmp[i].details.total_amount, - &amount))) - cmp->results_match[i] = true; - else - cmp->results_match[i] = false; - } -} - - -/** - * Tests looking up the rewards from the database. - * @param instance the instance to look up rewards from. - * @param expired how to filter expired rewards. - * @param offset where to start retrieving rewards. - * @param rewards_length length of @e rewards. - * @param rewards the rewards that we expect to find. - * - * @return 0 on success, 1 otherwise. - */ -static int -test_lookup_rewards (const struct InstanceData *instance, - enum TALER_EXCHANGE_YesNoAll expired, - int64_t limit, - uint64_t offset, - unsigned int rewards_length, - const struct RewardData *rewards) -{ - bool results_match[rewards_length]; - struct TestLookupRewards_Closure cmp = { - .rewards_to_cmp_length = rewards_length, - .rewards_to_cmp = rewards, - .results_length = 0, - .results_match = results_match - }; - - memset (results_match, - 0, - sizeof (bool) * rewards_length); - if (0 > plugin->lookup_rewards (plugin->cls, - instance->instance.id, - expired, - limit, - offset, - &lookup_rewards_cb, - &cmp)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup rewards failed\n"); - return 1; - } - if (rewards_length != cmp.results_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup rewards failed: incorrect number of results (%d)\n", - cmp.results_length); - return 1; - } - for (unsigned int i = 0; i < rewards_length; ++i) - { - if (true != cmp.results_match[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup rewards failed: mismatched data\n"); - return 1; - } - } - return 0; -} - - -/** - * Convenience function for testing lookup rewards with filters - * @param rewards_length length of @e rewards. - * @param rewards the array of rewards to reverse. - */ -static void -reverse_reward_data_array (unsigned int rewards_length, - struct RewardData *rewards) -{ - struct RewardData tmp[rewards_length]; - for (unsigned int i = 0; i < rewards_length; ++i) - tmp[i] = rewards[rewards_length - 1 - i]; - for (unsigned int i = 0; i < rewards_length; ++i) - rewards[i] = tmp[i]; -} - - -/** - * Container for data for testing rewards. - */ -struct TestRewards_Closure -{ - /** - * The instance. - */ - struct InstanceData instance; - - /** - * The reward reserve data. - */ - struct ReserveData reserve; - - /** - * Reserve data that is expired. - */ - struct ReserveData expired_reserve; - - /** - * A normal reward. - */ - struct RewardData reward; - - /** - * A reward that is too large to authorize. - */ - struct RewardData bigreward; - - /** - * Array of rewards for testing lookups. - */ - struct RewardData rewards[5]; - - /** - * Id of a pickup. - */ - struct TALER_PickupIdentifierP pickup_id; - - /** - * Private key of the pickup. - */ - struct GNUNET_CRYPTO_RsaPrivateKey *pickup_priv; - - /** - * Signature for the pickup. - */ - struct TALER_BlindedDenominationSignature pickup_sig; -}; - - -/** - * Prepares for testing rewards functionality. - * @param cls the data to prepare. - */ -static void -pre_test_rewards (struct TestRewards_Closure *cls) -{ - struct GNUNET_CRYPTO_BlindedSignature *us; - - /* Instance */ - make_instance ("test_inst_rewards", - &cls->instance); - - /* Reserve */ - GNUNET_CRYPTO_eddsa_key_create (&cls->reserve.reserve_priv.eddsa_priv); - GNUNET_CRYPTO_eddsa_key_get_public (&cls->reserve.reserve_priv.eddsa_priv, - &cls->reserve.reserve_pub.eddsa_pub); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount ("EUR:99.99", - &cls->reserve.initial_amount)); - cls->reserve.exchange_url = "https://exch-url/"; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &cls->reserve.master_pub, - sizeof (cls->reserve.master_pub)); - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &cls->pickup_id, - sizeof (cls->pickup_id)); - cls->reserve.expiration = GNUNET_TIME_relative_to_timestamp ( - GNUNET_TIME_UNIT_WEEKS); - - GNUNET_CRYPTO_eddsa_key_create ( - &cls->expired_reserve.reserve_priv.eddsa_priv); - GNUNET_CRYPTO_eddsa_key_get_public ( - &cls->expired_reserve.reserve_priv.eddsa_priv, - &cls->expired_reserve.reserve_pub. - eddsa_pub); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount ("EUR:99.99", - &cls->expired_reserve.initial_amount)); - cls->expired_reserve.exchange_url = "exch-url"; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &cls->expired_reserve.master_pub, - sizeof (cls->expired_reserve.master_pub)); - cls->expired_reserve.expiration = GNUNET_TIME_UNIT_ZERO_TS; - - /* Reward/pickup */ - make_reward (&cls->reward); - make_reward (&cls->bigreward); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount ("EUR:99.90", - &cls->bigreward.details.total_amount)); - for (unsigned int i = 0; i < 5; ++i) - { - char amount[16]; - make_reward (&cls->rewards[i]); - GNUNET_snprintf (amount, - 16, - "EUR:0.%u0", - i + 1); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (amount, - &cls->rewards[i].details.total_amount)); - } - - cls->pickup_priv = GNUNET_CRYPTO_rsa_private_key_create (2048); - us = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature); - cls->pickup_sig.blinded_sig = us; - us->cipher = GNUNET_CRYPTO_BSA_RSA; - us->rc = 1; - us->details.blinded_rsa_signature - = GNUNET_CRYPTO_rsa_sign_fdh (cls->pickup_priv, - &cls->pickup_id.hash, - sizeof (cls->pickup_id.hash)); -} - - -/** - * Cleans up after testing rewards. - * @param cls the data to clean up. - */ -static void -post_test_rewards (struct TestRewards_Closure *cls) -{ - free_instance_data (&cls->instance); - GNUNET_CRYPTO_rsa_private_key_free (cls->pickup_priv); - TALER_blinded_denom_sig_free (&cls->pickup_sig); -} - - -/** - * Runs tests for rewards. - * @param cls container of test data. - * - * @return 0 on success, 1 on failure. - */ -static int -run_test_rewards (struct TestRewards_Closure *cls) -{ - struct TALER_Amount zero; - - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero ("EUR", - &zero)); - TEST_RET_ON_FAIL (test_insert_instance (&cls->instance, - GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); - /* Test insert reserve */ - TEST_RET_ON_FAIL (test_insert_reserve (&cls->instance, - &cls->reserve, - TALER_EC_NONE)); - /* Test lookup reserve */ - TEST_RET_ON_FAIL (test_lookup_reserve (&cls->instance, - &cls->reserve.reserve_pub, - &cls->reserve)); - /* Test lookup pending reserves */ - TEST_RET_ON_FAIL (test_lookup_pending_reserves (1, - &cls->reserve)); - /* Test reserve activation */ - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->activate_reserve (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub, - &cls->reserve.initial_amount), - "Activate reserve failed\n"); - TEST_RET_ON_FAIL (test_lookup_pending_reserves (0, - NULL)); - /* Test inserting a reward */ - TEST_RET_ON_FAIL (test_authorize_reward (&cls->instance, - &cls->reserve, - &cls->reward)); - /* Test lookup reward */ - TEST_RET_ON_FAIL (test_lookup_reward (&cls->instance, - &cls->reserve, - &cls->reward, - &zero)); - /* Test lookup reward details */ - TEST_RET_ON_FAIL (test_lookup_reward_details (&cls->instance, - &cls->reserve, - &cls->reward, - &zero, - 0, - NULL)); - /* Test insert pickup */ - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->insert_pickup (plugin->cls, - cls->instance.instance.id, - &cls->reward.details.reward_id, - &cls->reward.details. - total_amount, - &cls->pickup_id, - &cls->reward.details. - total_amount), - "Insert pickup failed\n"); - /* Test lookup pickup */ - TEST_RET_ON_FAIL (test_lookup_pickup (&cls->instance, - &cls->reward, - &cls->pickup_id, - cls->reserve.exchange_url, - &cls->reserve.reserve_priv, - 0, - NULL)); - /* Test insert pickup blind signature */ - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->insert_pickup_blind_signature (plugin->cls, - &cls->pickup_id, - 0, - &cls->pickup_sig), - "Insert pickup blind signature failed\n"); - /* Test that overdrawing the reserve fails */ - TEST_COND_RET_ON_FAIL (TALER_EC_NONE != - plugin->authorize_reward (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub, - &cls->bigreward.details. - total_amount, - cls->bigreward.details.reason, - cls->bigreward.next_url, - &cls->bigreward.details. - reward_id, - &cls->reserve.expiration), - "Authorize reward failed\n"); - /* Test lookup rewards */ - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_ALL, - 1, - 0, - 1, - &cls->reward)); - /* Test lookup reserves */ - TEST_RET_ON_FAIL (test_lookup_reserves (&cls->instance, - 1, - &cls->reserve)); - { - /* Test lookup rewards & friends */ - struct RewardData expected_rewards[6]; - expected_rewards[0] = cls->reward; - TEST_RET_ON_FAIL (test_insert_reserve (&cls->instance, - &cls->expired_reserve, - TALER_EC_NONE)); - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->activate_reserve (plugin->cls, - cls->instance.instance.id, - &cls->expired_reserve. - reserve_pub, - &cls->expired_reserve. - initial_amount), - "Activate reserve failed\n"); - for (unsigned int i = 0; i < 5; ++i) - { - if (i % 2 == 0) - { - TEST_RET_ON_FAIL (test_authorize_reward (&cls->instance, - &cls->expired_reserve, - &cls->rewards[i])); - } - else - { - TEST_RET_ON_FAIL (test_authorize_reward (&cls->instance, - &cls->reserve, - &cls->rewards[i])); - } - } - GNUNET_memcpy (&expected_rewards[1], - cls->rewards, - sizeof (struct RewardData) * 5); - /* Test lookup rewards inc */ - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_ALL, - 6, - 0, - 6, - expected_rewards)); - reverse_reward_data_array (6, - expected_rewards); - /* Test lookup rewards dec */ - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_ALL, - -6, - 10, - 6, - expected_rewards)); - /* Test lookup rewards expired inc */ - expected_rewards[0] = cls->rewards[0]; - expected_rewards[1] = cls->rewards[2]; - expected_rewards[2] = cls->rewards[4]; - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_YES, - 6, - 0, - 3, - expected_rewards)); - /* Test lookup rewards expired dec */ - reverse_reward_data_array (3, - expected_rewards); - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_YES, - -6, - 10, - 3, - expected_rewards)); - /* Test lookup rewards unexpired inc */ - expected_rewards[0] = cls->reward; - expected_rewards[1] = cls->rewards[1]; - expected_rewards[2] = cls->rewards[3]; - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_NO, - 6, - 0, - 3, - expected_rewards)); - /* Test lookup rewards unexpired dec */ - reverse_reward_data_array (3, - expected_rewards); - TEST_RET_ON_FAIL (test_lookup_rewards (&cls->instance, - TALER_EXCHANGE_YNA_NO, - -6, - 10, - 3, - expected_rewards)); - } - /* Test delete reserve private key */ - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->delete_reserve (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub), - "Delete reserve private key failed\n"); - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == - plugin->delete_reserve (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub), - "Delete reserve private key failed\n"); - /* Test purging a reserve */ - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - plugin->purge_reserve (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub), - "Purge reserve failed\n"); - TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == - plugin->purge_reserve (plugin->cls, - cls->instance.instance.id, - &cls->reserve.reserve_pub), - "Purge reserve failed\n"); - - return 0; -} - - -/** - * Handles all logic for testing rewards in the database. - * - * @return 0 on success, 1 on failure. - */ -static int -test_rewards (void) -{ - struct TestRewards_Closure test_cls; - - pre_test_rewards (&test_cls); - int test_result = run_test_rewards (&test_cls); - post_test_rewards (&test_cls); - return test_result; -} - - /** * Closure for testing lookup_refunds. */ @@ -8366,7 +7059,6 @@ run_tests (void) TEST_RET_ON_FAIL (test_orders ()); TEST_RET_ON_FAIL (test_deposits ()); TEST_RET_ON_FAIL (test_transfers ()); - TEST_RET_ON_FAIL (test_rewards ()); TEST_RET_ON_FAIL (test_refunds ()); TEST_RET_ON_FAIL (test_lookup_orders_all_filters ()); TEST_RET_ON_FAIL (test_kyc ()); -- cgit v1.2.3