diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-09-18 18:59:53 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-09-18 18:59:53 +0200 |
commit | 12cff1b4439ab5dcc26fcf79e19518ae1bdce069 (patch) | |
tree | b2ba500293a986475a66cde99a8bdb28e84368aa /src/exchangedb | |
parent | 612828b7ef2299769a5b525a0fbf031858edc4f4 (diff) | |
download | exchange-12cff1b4439ab5dcc26fcf79e19518ae1bdce069.tar.xz |
remove coin and reserve histories from exchange replies
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/Makefile.am | 2 | ||||
-rw-r--r-- | src/exchangedb/exchange_do_history_request.sql | 101 | ||||
-rw-r--r-- | src/exchangedb/pg_get_reserve_history.c | 360 | ||||
-rw-r--r-- | src/exchangedb/pg_get_reserve_history.h | 32 | ||||
-rw-r--r-- | src/exchangedb/pg_insert_history_request.c | 67 | ||||
-rw-r--r-- | src/exchangedb/pg_insert_history_request.h | 53 | ||||
-rw-r--r-- | src/exchangedb/pg_select_history_requests_above_serial_id.c | 156 | ||||
-rw-r--r-- | src/exchangedb/pg_select_history_requests_above_serial_id.h | 44 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 8 | ||||
-rw-r--r-- | src/exchangedb/procedures.sql.in | 1 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 1 |
11 files changed, 10 insertions, 815 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index 50f9e768a..3a4120afc 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -164,7 +164,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_store_wire_transfer_out.h pg_store_wire_transfer_out.c \ pg_gc.h pg_gc.c \ pg_select_coin_deposits_above_serial_id.h pg_select_coin_deposits_above_serial_id.c \ - pg_select_history_requests_above_serial_id.h pg_select_history_requests_above_serial_id.c \ pg_select_purse_decisions_above_serial_id.h pg_select_purse_decisions_above_serial_id.c \ pg_select_purse_deposits_by_purse.h pg_select_purse_deposits_by_purse.c \ pg_select_refreshes_above_serial_id.h pg_select_refreshes_above_serial_id.c \ @@ -215,7 +214,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_update_auditor.h pg_update_auditor.c \ pg_begin_revolving_shard.h pg_begin_revolving_shard.c \ pg_get_extension_manifest.h pg_get_extension_manifest.c \ - pg_insert_history_request.h pg_insert_history_request.c \ pg_do_purse_merge.h pg_do_purse_merge.c \ pg_start_read_committed.h pg_start_read_committed.c \ pg_start_read_only.h pg_start_read_only.c \ diff --git a/src/exchangedb/exchange_do_history_request.sql b/src/exchangedb/exchange_do_history_request.sql deleted file mode 100644 index 726c853fb..000000000 --- a/src/exchangedb/exchange_do_history_request.sql +++ /dev/null @@ -1,101 +0,0 @@ --- --- This file is part of TALER --- Copyright (C) 2014--2022 Taler Systems SA --- --- TALER is free software; you can redistribute it and/or modify it under the --- terms of the GNU General Public License as published by the Free Software --- Foundation; either version 3, or (at your option) any later version. --- --- TALER is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR --- A PARTICULAR PURPOSE. See the GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License along with --- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> --- - - -CREATE OR REPLACE FUNCTION exchange_do_history_request( - IN in_reserve_pub BYTEA, - IN in_reserve_sig BYTEA, - IN in_request_timestamp INT8, - IN in_history_fee taler_amount, - OUT out_balance_ok BOOLEAN, - OUT out_idempotent BOOLEAN) -LANGUAGE plpgsql -AS $$ -DECLARE - reserve RECORD; - balance taler_amount; - new_balance taler_amount; -BEGIN - - -- Insert and check for idempotency. - INSERT INTO exchange.history_requests - (reserve_pub - ,request_timestamp - ,reserve_sig - ,history_fee) - VALUES - (in_reserve_pub - ,in_request_timestamp - ,in_reserve_sig - ,in_history_fee) - ON CONFLICT DO NOTHING; - - IF NOT FOUND - THEN - out_balance_ok=TRUE; - out_idempotent=TRUE; - RETURN; - END IF; - - out_idempotent=FALSE; - - SELECT * - INTO reserve - FROM exchange.reserves - WHERE reserve_pub=in_reserve_pub; - - IF NOT FOUND - THEN - -- Reserve does not exist, we treat it the same here - -- as balance insufficient. - out_balance_ok=FALSE; - RETURN; - END IF; - - balance = reserve.current_balance; - - -- check balance - IF ( (balance.val <= in_history_fee.val) AND - ( (balance.frac < in_history_fee.frac) OR - (balance.val < in_history_fee.val) ) ) - THEN - out_balance_ok=FALSE; - RETURN; - END IF; - - new_balance.frac=balance.frac-in_history_fee.frac - + CASE - WHEN balance.frac < in_history_fee.frac - THEN 100000000 - ELSE 0 - END; - new_balance.val=balance.val-in_history_fee.val - - CASE - WHEN balance.frac < in_history_fee.frac - THEN 1 - ELSE 0 - END; - - -- Update reserve balance. - UPDATE exchange.reserves - SET current_balance=new_balance - WHERE reserve_pub=in_reserve_pub; - - ASSERT FOUND, 'reserve suddenly disappeared'; - - out_balance_ok=TRUE; - -END $$; diff --git a/src/exchangedb/pg_get_reserve_history.c b/src/exchangedb/pg_get_reserve_history.c index c0cb08f59..ba1db2a16 100644 --- a/src/exchangedb/pg_get_reserve_history.c +++ b/src/exchangedb/pg_get_reserve_history.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -433,62 +433,6 @@ add_p2p_merge (void *cls, * @param num_results number of rows in @a result */ static void -add_history_requests (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct ReserveHistoryContext *rhc = cls; - struct PostgresClosure *pg = rhc->pg; - - while (0 < num_results) - { - struct TALER_EXCHANGEDB_HistoryRequest *history; - struct TALER_EXCHANGEDB_ReserveHistory *tail; - - history = GNUNET_new (struct TALER_EXCHANGEDB_HistoryRequest); - { - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee", - &history->history_fee), - GNUNET_PQ_result_spec_timestamp ("request_timestamp", - &history->request_timestamp), - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &history->reserve_sig), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - --num_results)) - { - GNUNET_break (0); - GNUNET_free (history); - rhc->status = GNUNET_SYSERR; - return; - } - } - GNUNET_assert (0 <= - TALER_amount_add (&rhc->balance_out, - &rhc->balance_out, - &history->history_fee)); - history->reserve_pub = *rhc->reserve_pub; - tail = append_rh (rhc); - tail->type = TALER_EXCHANGEDB_RO_HISTORY_REQUEST; - tail->details.history = history; - } -} - - -/** - * Add paid for history requests to result set for - * #TEH_PG_get_reserve_history. - * - * @param cls a `struct ReserveHistoryContext *` - * @param result SQL result - * @param num_results number of rows in @a result - */ -static void add_open_requests (void *cls, PGresult *result, unsigned int num_results) @@ -598,6 +542,7 @@ add_close_requests (void *cls, enum GNUNET_DB_QueryStatus TEH_PG_get_reserve_history (void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, + uint64_t start_off, struct TALER_Amount *balance, struct TALER_EXCHANGEDB_ReserveHistory **rhp) { @@ -629,9 +574,6 @@ TEH_PG_get_reserve_history (void *cls, /** #TALER_EXCHANGEDB_RO_PURSE_MERGE */ { "merge_by_reserve", &add_p2p_merge }, - /** #TALER_EXCHANGEDB_RO_HISTORY_REQUEST */ - { "history_by_reserve", - &add_history_requests }, /** #TALER_EXCHANGEDB_RO_OPEN_REQUEST */ { "open_request_by_reserve", &add_open_requests }, @@ -793,14 +735,6 @@ TEH_PG_get_reserve_history (void *cls, " AND COALESCE(pm.partner_serial_id,0)=0" /* must be local! */ " AND NOT COALESCE (pdes.refunded, FALSE);"); PREPARE (pg, // done - "history_by_reserve", - "SELECT" - " history_fee" - ",request_timestamp" - ",reserve_sig" - " FROM history_requests" - " WHERE reserve_pub=$1;"); - PREPARE (pg, // done "open_request_by_reserve", "SELECT" " reserve_payment" @@ -866,293 +800,3 @@ TEH_PG_get_reserve_history (void *cls, &rhc.balance_out)); return qs; } - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_status (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_Amount *balance_in, - struct TALER_Amount *balance_out, - struct TALER_EXCHANGEDB_ReserveHistory **rhp) -{ - struct PostgresClosure *pg = cls; - struct ReserveHistoryContext rhc; - struct - { - /** - * Name of the prepared statement to run. - */ - const char *statement; - /** - * Function to use to process the results. - */ - GNUNET_PQ_PostgresResultHandler cb; - } work[] = { - /** #TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE */ - { "reserves_in_get_transactions_truncated", - add_bank_to_exchange }, - /** #TALER_EXCHANGEDB_RO_WITHDRAW_COIN */ - { "get_reserves_out_truncated", - &add_withdraw_coin }, - /** #TALER_EXCHANGEDB_RO_RECOUP_COIN */ - { "recoup_by_reserve_truncated", - &add_recoup }, - /** #TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK */ - { "close_by_reserve_truncated", - &add_exchange_to_bank }, - /** #TALER_EXCHANGEDB_RO_PURSE_MERGE */ - { "merge_by_reserve_truncated", - &add_p2p_merge }, - /** #TALER_EXCHANGEDB_RO_HISTORY_REQUEST */ - { "history_by_reserve_truncated", - &add_history_requests }, - /** #TALER_EXCHANGEDB_RO_OPEN_REQUEST */ - { "open_request_by_reserve_truncated", - &add_open_requests }, - /** #TALER_EXCHANGEDB_RO_CLOSE_REQUEST */ - { "close_request_by_reserve_truncated", - &add_close_requests }, - /* List terminator */ - { NULL, - NULL } - }; - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_TIME_Absolute timelimit; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_absolute_time (&timelimit), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "reserves_in_get_transactions_truncated", - /* - "SELECT" - " wire_reference" - ",credit" - ",execution_date" - ",payto_uri AS sender_account_details" - " FROM reserves_in" - " JOIN wire_targets" - " ON (wire_source_h_payto = wire_target_h_payto)" - " WHERE reserve_pub=$1" - " AND execution_date>=$2;", - */ - "WITH ri AS MATERIALIZED ( " - " SELECT * " - " FROM reserves_in " - " WHERE reserve_pub = $1 " - ") " - "SELECT " - " wire_reference" - " ,credit" - " ,execution_date" - " ,payto_uri AS sender_account_details" - " FROM wire_targets" - " JOIN ri" - " ON (wire_target_h_payto = wire_source_h_payto)" - " WHERE execution_date >= $2" - " AND wire_target_h_payto = ( " - " SELECT wire_source_h_payto FROM ri " - "); "); - PREPARE (pg, - "get_reserves_out_truncated", - /* - "SELECT" - " ro.h_blind_ev" - ",denom.denom_pub_hash" - ",ro.denom_sig" - ",ro.reserve_sig" - ",ro.execution_date" - ",ro.amount_with_fee" - ",denom.fee_withdraw" - " FROM reserves res" - " JOIN reserves_out_by_reserve ror" - " ON (res.reserve_uuid = ror.reserve_uuid)" - " JOIN reserves_out ro" - " ON (ro.h_blind_ev = ror.h_blind_ev)" - " JOIN denominations denom" - " ON (ro.denominations_serial = denom.denominations_serial)" - " WHERE res.reserve_pub=$1" - " AND execution_date>=$2;", - */ - "WITH robr AS MATERIALIZED ( " - " SELECT h_blind_ev " - " FROM reserves_out_by_reserve " - " WHERE reserve_uuid= ( " - " SELECT reserve_uuid " - " FROM reserves " - " WHERE reserve_pub = $1 " - " ) " - ") SELECT " - " ro.h_blind_ev" - " ,denom.denom_pub_hash" - " ,ro.denom_sig" - " ,ro.reserve_sig" - " ,ro.execution_date" - " ,ro.amount_with_fee" - " ,denom.fee_withdraw" - " FROM robr" - " JOIN reserves_out ro" - " ON (ro.h_blind_ev = robr.h_blind_ev)" - " JOIN denominations denom" - " ON (ro.denominations_serial = denom.denominations_serial)" - " WHERE ro.execution_date>=$2;"); - PREPARE (pg, - "recoup_by_reserve_truncated", - /* - "SELECT" - " recoup.coin_pub" - ",recoup.coin_sig" - ",recoup.coin_blind" - ",recoup.amount" - ",recoup.recoup_timestamp" - ",denominations.denom_pub_hash" - ",known_coins.denom_sig" - " FROM denominations" - " JOIN (known_coins" - " JOIN recoup " - " ON (recoup.coin_pub = known_coins.coin_pub))" - " ON (known_coins.denominations_serial = denominations.denominations_serial)" - " WHERE recoup_timestamp>=$2" - " AND recoup.coin_pub" - " IN (SELECT coin_pub" - " FROM recoup_by_reserve" - " JOIN (reserves_out" - " JOIN (reserves_out_by_reserve" - " JOIN reserves" - " ON (reserves.reserve_uuid = reserves_out_by_reserve.reserve_uuid))" - " ON (reserves_out_by_reserve.h_blind_ev = reserves_out.h_blind_ev))" - " ON (recoup_by_reserve.reserve_out_serial_id = reserves_out.reserve_out_serial_id)" - " WHERE reserves.reserve_pub=$1);", - */ - "SELECT robr.coin_pub " - " ,robr.coin_sig " - " ,robr.coin_blind " - " ,robr.amount" - " ,robr.recoup_timestamp " - " ,denominations.denom_pub_hash " - " ,robr.denom_sig " - "FROM denominations " - " JOIN exchange_do_recoup_by_reserve($1) robr" - " USING (denominations_serial)" - " WHERE recoup_timestamp>=$2;"); - PREPARE (pg, - "close_by_reserve_truncated", - "SELECT" - " amount" - ",closing_fee" - ",execution_date" - ",payto_uri AS receiver_account" - ",wtid" - " FROM reserves_close" - " JOIN wire_targets" - " USING (wire_target_h_payto)" - " WHERE reserve_pub=$1" - " AND execution_date>=$2;"); - PREPARE (pg, - "merge_by_reserve_truncated", - "SELECT" - " pr.amount_with_fee" - ",pr.balance" - ",pr.purse_fee" - ",pr.h_contract_terms" - ",pr.merge_pub" - ",am.reserve_sig" - ",pm.purse_pub" - ",pm.merge_timestamp" - ",pr.purse_expiration" - ",pr.age_limit" - ",pr.flags" - " FROM purse_merges pm" - " JOIN purse_requests pr" - " USING (purse_pub)" - " JOIN purse_decision pdes" - " USING (purse_pub)" - " JOIN account_merges am" - " ON (am.purse_pub = pm.purse_pub AND" - " am.reserve_pub = pm.reserve_pub)" - " WHERE pm.reserve_pub=$1" - " AND pm.merge_timestamp >= $2" - " AND COALESCE(pm.partner_serial_id,0)=0" /* must be local! */ - " AND NOT pdes.refunded;"); - PREPARE (pg, - "history_by_reserve_truncated", - "SELECT" - " history_fee" - ",request_timestamp" - ",reserve_sig" - " FROM history_requests" - " WHERE reserve_pub=$1" - " AND request_timestamp>=$2;"); - PREPARE (pg, - "open_request_by_reserve_truncated", - "SELECT" - " reserve_payment" - ",request_timestamp" - ",expiration_date" - ",requested_purse_limit" - ",reserve_sig" - " FROM reserves_open_requests" - " WHERE reserve_pub=$1" - " AND request_timestamp>=$2;"); - - PREPARE (pg, - "close_request_by_reserve_truncated", - "SELECT" - " close_timestamp" - ",payto_uri" - ",reserve_sig" - " FROM close_requests" - " WHERE reserve_pub=$1" - " AND close_timestamp>=$2;"); - - timelimit = GNUNET_TIME_absolute_subtract ( - GNUNET_TIME_absolute_get (), - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_WEEKS, - 5)); - rhc.reserve_pub = reserve_pub; - rhc.rh = NULL; - rhc.rh_tail = NULL; - rhc.pg = pg; - rhc.status = GNUNET_OK; - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (pg->currency, - &rhc.balance_in)); - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (pg->currency, - &rhc.balance_out)); - qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */ - for (unsigned int i = 0; NULL != work[i].cb; i++) - { - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - work[i].statement, - params, - work[i].cb, - &rhc); - if ( (0 > qs) || - (GNUNET_OK != rhc.status) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Query %s failed\n", - work[i].statement); - break; - } - } - if ( (qs < 0) || - (rhc.status != GNUNET_OK) ) - { - TEH_COMMON_free_reserve_history (cls, - rhc.rh); - rhc.rh = NULL; - if (qs >= 0) - { - /* status == SYSERR is a very hard error... */ - qs = GNUNET_DB_STATUS_HARD_ERROR; - } - } - *rhp = rhc.rh; - *balance_in = rhc.balance_in; - *balance_out = rhc.balance_out; - return qs; -} diff --git a/src/exchangedb/pg_get_reserve_history.h b/src/exchangedb/pg_get_reserve_history.h index ee47996b2..ca6740c6c 100644 --- a/src/exchangedb/pg_get_reserve_history.h +++ b/src/exchangedb/pg_get_reserve_history.h @@ -32,36 +32,18 @@ * * @param cls the `struct PostgresClosure` with the plugin-specific state * @param reserve_pub public key of the reserve + * @param start_off maximum starting offset in history to exclude from returning * @param[out] balance set to the reserve balance * @param[out] rhp set to known transaction history (NULL if reserve is unknown) * @return transaction status */ enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_history (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_Amount *balance, - struct TALER_EXCHANGEDB_ReserveHistory **rhp); - - -/** - * Get a truncated transaction history associated with the specified - * reserve. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param reserve_pub public key of the reserve - * @param[out] balance_in set to the total of inbound - * transactions in the returned history - * @param[out] balance_out set to the total of outbound - * transactions in the returned history - * @param[out] rhp set to known transaction history (NULL if reserve is unknown) - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_status (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_Amount *balance_in, - struct TALER_Amount *balance_out, - struct TALER_EXCHANGEDB_ReserveHistory **rhp); +TEH_PG_get_reserve_history ( + void *cls, + const struct TALER_ReservePublicKeyP *reserve_pub, + uint64_t start_off, + struct TALER_Amount *balance, + struct TALER_EXCHANGEDB_ReserveHistory **rhp); #endif diff --git a/src/exchangedb/pg_insert_history_request.c b/src/exchangedb/pg_insert_history_request.c deleted file mode 100644 index b13066b5c..000000000 --- a/src/exchangedb/pg_insert_history_request.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_insert_history_request.c - * @brief Implementation of the insert_history_request function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_insert_history_request.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_insert_history_request ( - void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_ReserveSignatureP *reserve_sig, - struct GNUNET_TIME_Timestamp request_timestamp, - const struct TALER_Amount *history_fee, - bool *balance_ok, - bool *idempotent) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_auto_from_type (reserve_sig), - GNUNET_PQ_query_param_timestamp (&request_timestamp), - TALER_PQ_query_param_amount (pg->conn, - history_fee), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("balance_ok", - balance_ok), - GNUNET_PQ_result_spec_bool ("idempotent", - idempotent), - GNUNET_PQ_result_spec_end - }; - /* Used in #postgres_insert_history_request() */ - PREPARE (pg, - "call_history_request", - "SELECT" - " out_balance_ok AS balance_ok" - " ,out_idempotent AS idempotent" - " FROM exchange_do_history_request" - " ($1, $2, $3, $4)"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_history_request", - params, - rs); -} diff --git a/src/exchangedb/pg_insert_history_request.h b/src/exchangedb/pg_insert_history_request.h deleted file mode 100644 index 75004a7e4..000000000 --- a/src/exchangedb/pg_insert_history_request.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_insert_history_request.h - * @brief implementation of the insert_history_request function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_INSERT_HISTORY_REQUEST_H -#define PG_INSERT_HISTORY_REQUEST_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" -/** - * Function called to persist a signature that - * prove that the client requested an - * account history. Debits the @a history_fee from - * the reserve (if possible). - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param reserve_pub account that the history was requested for - * @param reserve_sig signature affirming the request - * @param request_timestamp when was the request made - * @param history_fee how much should the @a reserve_pub be charged for the request - * @param[out] balance_ok set to TRUE if the reserve balance - * was sufficient - * @param[out] idempotent set to TRUE if the request is already in the DB - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_insert_history_request ( - void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_ReserveSignatureP *reserve_sig, - struct GNUNET_TIME_Timestamp request_timestamp, - const struct TALER_Amount *history_fee, - bool *balance_ok, - bool *idempotent); - -#endif diff --git a/src/exchangedb/pg_select_history_requests_above_serial_id.c b/src/exchangedb/pg_select_history_requests_above_serial_id.c deleted file mode 100644 index 2ff2f989c..000000000 --- a/src/exchangedb/pg_select_history_requests_above_serial_id.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_select_history_requests_above_serial_id.c - * @brief Implementation of the select_history_requests_above_serial_id function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_select_history_requests_above_serial_id.h" -#include "pg_helper.h" - -/** - * Closure for #purse_deposit_serial_helper_cb(). - */ -struct HistoryRequestSerialContext -{ - - /** - * Callback to call. - */ - TALER_EXCHANGEDB_HistoryRequestCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Status code, set to #GNUNET_SYSERR on hard errors. - */ - enum GNUNET_GenericReturnValue status; -}; - - -/** - * Helper function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct HistoryRequestSerialContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -history_request_serial_helper_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct HistoryRequestSerialContext *dsc = cls; - struct PostgresClosure *pg = dsc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - uint64_t rowid; - struct TALER_Amount history_fee; - struct GNUNET_TIME_Timestamp ts; - struct TALER_ReservePublicKeyP reserve_pub; - struct TALER_ReserveSignatureP reserve_sig; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee", - &history_fee), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &reserve_sig), - GNUNET_PQ_result_spec_uint64 ("history_request_serial_id", - &rowid), - GNUNET_PQ_result_spec_timestamp ("request_timestamp", - &ts), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_GenericReturnValue ret; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - dsc->status = GNUNET_SYSERR; - return; - } - ret = dsc->cb (dsc->cb_cls, - rowid, - &history_fee, - ts, - &reserve_pub, - &reserve_sig); - GNUNET_PQ_cleanup_result (rs); - if (GNUNET_OK != ret) - break; - } -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_select_history_requests_above_serial_id ( - void *cls, - uint64_t serial_id, - TALER_EXCHANGEDB_HistoryRequestCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&serial_id), - GNUNET_PQ_query_param_end - }; - struct HistoryRequestSerialContext dsc = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - .status = GNUNET_OK - }; - enum GNUNET_DB_QueryStatus qs; - PREPARE (pg, - "audit_get_history_requests_incr", - "SELECT" - " history_request_serial_id" - ",history_fee" - ",request_timestamp" - ",reserve_pub" - ",reserve_sig" - " FROM history_requests" - " WHERE (" - " (history_request_serial_id>=$1)" - " )" - " ORDER BY history_request_serial_id ASC;"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "audit_get_history_requests_incr", - params, - &history_request_serial_helper_cb, - &dsc); - if (GNUNET_OK != dsc.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/exchangedb/pg_select_history_requests_above_serial_id.h b/src/exchangedb/pg_select_history_requests_above_serial_id.h deleted file mode 100644 index b16efdce1..000000000 --- a/src/exchangedb/pg_select_history_requests_above_serial_id.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file exchangedb/pg_select_history_requests_above_serial_id.h - * @brief implementation of the select_history_requests_above_serial_id function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_SELECT_HISTORY_REQUESTS_ABOVE_SERIAL_ID_H -#define PG_SELECT_HISTORY_REQUESTS_ABOVE_SERIAL_ID_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" -/** - * Select history requests above @a serial_id in monotonically increasing - * order. - * - * @param cls closure - * @param serial_id highest serial ID to exclude (select strictly larger) - * @param cb function to call on each result - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_select_history_requests_above_serial_id ( - void *cls, - uint64_t serial_id, - TALER_EXCHANGEDB_HistoryRequestCallback cb, - void *cb_cls); - -#endif diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index c6e55d017..aacc29681 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -92,7 +92,6 @@ #include "pg_update_auditor.h" #include "pg_begin_revolving_shard.h" #include "pg_get_extension_manifest.h" -#include "pg_insert_history_request.h" #include "pg_do_purse_delete.h" #include "pg_do_purse_merge.h" #include "pg_start_read_committed.h" @@ -160,7 +159,6 @@ #include "pg_store_wire_transfer_out.h" #include "pg_gc.h" #include "pg_select_coin_deposits_above_serial_id.h" -#include "pg_select_history_requests_above_serial_id.h" #include "pg_select_purse_decisions_above_serial_id.h" #include "pg_select_purse_deposits_by_purse.h" #include "pg_select_refreshes_above_serial_id.h" @@ -429,8 +427,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_get_purse_request; plugin->get_reserve_history = &TEH_PG_get_reserve_history; - plugin->get_reserve_status - = &TEH_PG_get_reserve_status; plugin->get_unfinished_close_requests = &TEH_PG_get_unfinished_close_requests; plugin->insert_records_by_table @@ -531,8 +527,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_begin_revolving_shard; plugin->get_extension_manifest = &TEH_PG_get_extension_manifest; - plugin->insert_history_request - = &TEH_PG_insert_history_request; plugin->do_purse_merge = &TEH_PG_do_purse_merge; plugin->do_purse_delete @@ -667,8 +661,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_gc; plugin->select_coin_deposits_above_serial_id = &TEH_PG_select_coin_deposits_above_serial_id; - plugin->select_history_requests_above_serial_id - = &TEH_PG_select_history_requests_above_serial_id; plugin->select_purse_decisions_above_serial_id = &TEH_PG_select_purse_decisions_above_serial_id; plugin->select_purse_deposits_by_purse diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in index b963900c9..998c2c160 100644 --- a/src/exchangedb/procedures.sql.in +++ b/src/exchangedb/procedures.sql.in @@ -37,7 +37,6 @@ SET search_path TO exchange; #include "exchange_do_purse_merge.sql" #include "exchange_do_reserve_purse.sql" #include "exchange_do_expire_purse.sql" -#include "exchange_do_history_request.sql" #include "exchange_do_reserve_open_deposit.sql" #include "exchange_do_reserve_open.sql" #include "exchange_do_insert_or_update_policy_details.sql" diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 217df2bb4..9a30a1895 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1863,6 +1863,7 @@ run (void *cls) qs = plugin->get_reserve_history (plugin->cls, &reserve_pub, + 0, &balance, &rh); } |