donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 4f7290acd5983a7e44c543d8fe4dc5503f54aad3
parent 71fb5c13bfe8dbcdae5eb06cb87115d2d87e7bb0
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Mon, 23 Oct 2023 15:17:35 +0200

[db] cleanup working on pg headers

Diffstat:
Msrc/donaudb/pg_activate_signing_key.c | 6++----
Msrc/donaudb/pg_activate_signing_key.h | 6++----
Dsrc/donaudb/pg_add_denomination_key.h | 46----------------------------------------------
Rsrc/donaudb/pg_add_denomination_key.c -> src/donaudb/pg_add_donation_unit_key.c | 0
Asrc/donaudb/pg_add_donation_unit_key.h | 42++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/pg_batch_ensure_coin_known.c | 470-------------------------------------------------------------------------------
Dsrc/donaudb/pg_batch_ensure_coin_known.h | 47-----------------------------------------------
Dsrc/donaudb/pg_do_batch_withdraw.c | 85-------------------------------------------------------------------------------
Dsrc/donaudb/pg_do_batch_withdraw.h | 57---------------------------------------------------------
Dsrc/donaudb/pg_do_batch_withdraw_insert.c | 77-----------------------------------------------------------------------------
Dsrc/donaudb/pg_do_batch_withdraw_insert.h | 52----------------------------------------------------
Dsrc/donaudb/pg_do_deposit.c | 116-------------------------------------------------------------------------------
Dsrc/donaudb/pg_do_deposit.h | 51---------------------------------------------------
Dsrc/donaudb/pg_do_withdraw.c | 95-------------------------------------------------------------------------------
Dsrc/donaudb/pg_do_withdraw.h | 59-----------------------------------------------------------
Msrc/donaudb/pg_ensure_coin_known.h | 5++---
Dsrc/donaudb/pg_get_coin_denomination.c | 69---------------------------------------------------------------------
Dsrc/donaudb/pg_get_coin_denomination.h | 43-------------------------------------------
Dsrc/donaudb/pg_get_coin_transactions.c | 948-------------------------------------------------------------------------------
Dsrc/donaudb/pg_get_coin_transactions.h | 44--------------------------------------------
Msrc/donaudb/pg_get_denomination_info.h | 18+++++++++---------
Dsrc/donaudb/pg_get_denomination_revocation.c | 63---------------------------------------------------------------
Dsrc/donaudb/pg_get_denomination_revocation.h | 45---------------------------------------------
Dsrc/donaudb/pg_get_expired_reserves.c | 174-------------------------------------------------------------------------------
Dsrc/donaudb/pg_get_expired_reserves.h | 45---------------------------------------------
Dsrc/donaudb/pg_get_ready_deposit.c | 74--------------------------------------------------------------------------
Dsrc/donaudb/pg_get_ready_deposit.h | 46----------------------------------------------
Dsrc/donaudb/pg_get_reserve_balance.c | 55-------------------------------------------------------
Dsrc/donaudb/pg_get_reserve_balance.h | 40----------------------------------------
Dsrc/donaudb/pg_get_reserve_by_h_blind.c | 63---------------------------------------------------------------
Dsrc/donaudb/pg_get_reserve_by_h_blind.h | 44--------------------------------------------
Dsrc/donaudb/pg_get_withdraw_info.c | 79-------------------------------------------------------------------------------
Dsrc/donaudb/pg_get_withdraw_info.h | 43-------------------------------------------
Dsrc/donaudb/pg_have_deposit2.c | 117-------------------------------------------------------------------------------
Dsrc/donaudb/pg_have_deposit2.h | 53-----------------------------------------------------
Msrc/donaudb/pg_insert_denomination_info.h | 17++++++++---------
Dsrc/donaudb/pg_insert_denomination_revocation.c | 54------------------------------------------------------
Dsrc/donaudb/pg_insert_denomination_revocation.h | 42------------------------------------------
Msrc/donaudb/pg_insert_signkey_revocation.h | 6++----
Dsrc/donaudb/pg_iterate_active_signkeys.c | 144-------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_active_signkeys.h | 43-------------------------------------------
Dsrc/donaudb/pg_iterate_denomination_info.c | 180-------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_denomination_info.h | 41-----------------------------------------
Dsrc/donaudb/pg_iterate_denominations.c | 172-------------------------------------------------------------------------------
Dsrc/donaudb/pg_iterate_denominations.h | 44--------------------------------------------
Msrc/donaudb/pg_lookup_signing_key.h | 2+-
Msrc/donaudb/pg_lookup_signkey_revocation.h | 6++----
Dsrc/donaudb/pg_reserves_get.c | 61-------------------------------------------------------------
Dsrc/donaudb/pg_reserves_get.h | 40----------------------------------------
Dsrc/donaudb/pg_reserves_get_origin.c | 57---------------------------------------------------------
Dsrc/donaudb/pg_reserves_get_origin.h | 41-----------------------------------------
Dsrc/donaudb/pg_reserves_in_insert.c | 372-------------------------------------------------------------------------------
Dsrc/donaudb/pg_reserves_in_insert.h | 47-----------------------------------------------
Dsrc/donaudb/pg_reserves_update.c | 53-----------------------------------------------------
Dsrc/donaudb/pg_reserves_update.h | 40----------------------------------------
Msrc/include/taler_donaudb_plugin.h | 5-----
56 files changed, 70 insertions(+), 4674 deletions(-)

diff --git a/src/donaudb/pg_activate_signing_key.c b/src/donaudb/pg_activate_signing_key.c @@ -29,8 +29,7 @@ enum GNUNET_DB_QueryStatus TEH_PG_activate_signing_key ( void *cls, const struct TALER_DonauPublicKeyP *donau_pub, - const struct TALER_DONAUDB_SignkeyMetaData *meta, - const struct TALER_MasterSignatureP *master_sig) + const struct TALER_DONAUDB_SignkeyMetaData *meta) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam iparams[] = { @@ -49,9 +48,8 @@ TEH_PG_activate_signing_key ( ",valid_from" ",expire_sign" ",expire_legal" - ",master_sig" ") VALUES " - "($1, $2, $3, $4, $5);"); + "($1, $2, $3, $4);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_signkey", iparams); diff --git a/src/donaudb/pg_activate_signing_key.h b/src/donaudb/pg_activate_signing_key.h @@ -16,7 +16,7 @@ /** * @file donaudb/pg_activate_signing_key.h * @brief implementation of the activate_signing_key function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #ifndef PG_ACTIVATE_SIGNING_KEY_H #define PG_ACTIVATE_SIGNING_KEY_H @@ -31,14 +31,12 @@ * @param cls closure * @param donau_pub the donau online signing public key * @param meta meta data about @a donau_pub - * @param master_sig master signature to add * @return transaction status code */ enum GNUNET_DB_QueryStatus TEH_PG_activate_signing_key ( void *cls, const struct TALER_DonauPublicKeyP *donau_pub, - const struct TALER_DONAUDB_SignkeyMetaData *meta, - const struct TALER_MasterSignatureP *master_sig); + const struct TALER_DONAUDB_SignkeyMetaData *meta); #endif diff --git a/src/donaudb/pg_add_denomination_key.h b/src/donaudb/pg_add_denomination_key.h @@ -1,46 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_add_denomination_key.h - * @brief implementation of the add_denomination_key function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ADD_DENOMINATION_KEY_H -#define PG_ADD_DENOMINATION_KEY_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Activate denomination key, turning it into a "current" or "valid" - * denomination key by adding the master signature. - * - * @param cls closure - * @param h_denom_pub hash of the denomination public key - * @param denom_pub the actual denomination key - * @param meta meta data about the denomination - * @param master_sig master signature to add - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_add_denomination_key ( - void *cls, - const struct TALER_DenominationHashP *h_denom_pub, - const struct TALER_DenominationPublicKey *denom_pub, - const struct TALER_DONAUDB_DenominationKeyMetaData *meta, - const struct TALER_MasterSignatureP *master_sig); -#endif diff --git a/src/donaudb/pg_add_denomination_key.c b/src/donaudb/pg_add_donation_unit_key.c diff --git a/src/donaudb/pg_add_donation_unit_key.h b/src/donaudb/pg_add_donation_unit_key.h @@ -0,0 +1,42 @@ +/* + This file is part of TALER + Copyright (C) 2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_add_denomination_key.h + * @brief implementation of the add_denomination_key function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_ADD_DONATION_UNIT_KEY_H +#define PG_ADD_DONATION_UNIT_KEY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_donaudb_plugin.h" + +/** + * Activate donation unit key, turning it into a "current" or "valid" + * denomination key by adding the master signature. + * + * @param cls closure + * @param denom_pub the actual denomination key + * @param info information about the donation unit key + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_add_donation_unit_key ( + void *cls, + const struct TALER_DenominationPublicKey *denom_pub, + const struct TALER_DONAUDB_DenominationKeyInformation *info) +#endif diff --git a/src/donaudb/pg_batch_ensure_coin_known.c b/src/donaudb/pg_batch_ensure_coin_known.c @@ -1,470 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_batch_ensure_coin_known.c - * @brief Implementation of the batch_ensure_coin_known 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_batch_ensure_coin_known.h" -#include "pg_helper.h" - - -static enum GNUNET_DB_QueryStatus -insert1 (struct PostgresClosure *pg, - const struct TALER_CoinPublicInfo coin[1], - struct TALER_DONAUDB_CoinInfo result[1]) -{ - enum GNUNET_DB_QueryStatus qs; - bool is_denom_pub_hash_null = false; - bool is_age_hash_null = false; - PREPARE (pg, - "batch1_known_coin", - "SELECT" - " existed1 AS existed" - ",known_coin_id1 AS known_coin_id" - ",denom_pub_hash1 AS denom_hash" - ",age_commitment_hash1 AS h_age_commitment" - " FROM donau_do_batch1_known_coin" - " ($1, $2, $3, $4);" - ); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[0].denom_sig), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("existed", - &result[0].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id", - &result[0].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &result[0].denom_hash), - &is_denom_pub_hash_null), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &result[0].h_age_commitment), - &is_age_hash_null), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "batch1_known_coin", - params, - rs); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - return qs; - case GNUNET_DB_STATUS_SOFT_ERROR: - return qs; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); /* should be impossible */ - return GNUNET_DB_STATUS_HARD_ERROR; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; /* continued below */ - } - - if ( (! is_denom_pub_hash_null) && - (0 != GNUNET_memcmp (&result[0].denom_hash, - &coin->denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[0].denom_conflict = true; - } - - if ( (! is_age_hash_null) && - (0 != GNUNET_memcmp (&result[0].h_age_commitment, - &coin->h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[0].h_age_commitment)); - GNUNET_break_op (0); - result[0].age_conflict = true; - } - return qs; -} - - -static enum GNUNET_DB_QueryStatus -insert2 (struct PostgresClosure *pg, - const struct TALER_CoinPublicInfo coin[2], - struct TALER_DONAUDB_CoinInfo result[2]) -{ - enum GNUNET_DB_QueryStatus qs; - bool is_denom_pub_hash_null = false; - bool is_age_hash_null = false; - bool is_denom_pub_hash_null2 = false; - bool is_age_hash_null2 = false; - - PREPARE (pg, - "batch2_known_coin", - "SELECT" - " existed1 AS existed" - ",known_coin_id1 AS known_coin_id" - ",denom_pub_hash1 AS denom_hash" - ",age_commitment_hash1 AS h_age_commitment" - ",existed2 AS existed2" - ",known_coin_id2 AS known_coin_id2" - ",denom_pub_hash2 AS denom_hash2" - ",age_commitment_hash2 AS h_age_commitment2" - " FROM donau_do_batch2_known_coin" - " ($1, $2, $3, $4, $5, $6, $7, $8);" - ); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[0].denom_sig), - - GNUNET_PQ_query_param_auto_from_type (&coin[1].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[1].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[1].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[0].denom_sig), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("existed", - &result[0].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id", - &result[0].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &result[0].denom_hash), - &is_denom_pub_hash_null), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &result[0].h_age_commitment), - &is_age_hash_null), - GNUNET_PQ_result_spec_bool ("existed2", - &result[1].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id2", - &result[1].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash2", - &result[1].denom_hash), - &is_denom_pub_hash_null2), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash2", - &result[1].h_age_commitment), - &is_age_hash_null2), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "batch2_known_coin", - params, - rs); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - return qs; - case GNUNET_DB_STATUS_SOFT_ERROR: - return qs; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); /* should be impossible */ - return GNUNET_DB_STATUS_HARD_ERROR; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; /* continued below */ - } - - if ( (! is_denom_pub_hash_null) && - (0 != GNUNET_memcmp (&result[0].denom_hash, - &coin[0].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[0].denom_conflict = true; - } - - if ( (! is_age_hash_null) && - (0 != GNUNET_memcmp (&result[0].h_age_commitment, - &coin[0].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[0].h_age_commitment)); - GNUNET_break_op (0); - result[0].age_conflict = true; - } - if ( (! is_denom_pub_hash_null2) && - (0 != GNUNET_memcmp (&result[1].denom_hash, - &coin[1].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[1].denom_conflict = true; - } - - if ( (! is_age_hash_null) && - (0 != GNUNET_memcmp (&result[1].h_age_commitment, - &coin[1].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[1].h_age_commitment)); - GNUNET_break_op (0); - result[1].age_conflict = true; - } - return qs; -} - - -static enum GNUNET_DB_QueryStatus -insert4 (struct PostgresClosure *pg, - const struct TALER_CoinPublicInfo coin[4], - struct TALER_DONAUDB_CoinInfo result[4]) -{ - enum GNUNET_DB_QueryStatus qs; - bool is_denom_pub_hash_null = false; - bool is_age_hash_null = false; - bool is_denom_pub_hash_null2 = false; - bool is_age_hash_null2 = false; - bool is_denom_pub_hash_null3 = false; - bool is_age_hash_null3 = false; - bool is_denom_pub_hash_null4 = false; - bool is_age_hash_null4 = false; - PREPARE (pg, - "batch4_known_coin", - "SELECT" - " existed1 AS existed" - ",known_coin_id1 AS known_coin_id" - ",denom_pub_hash1 AS denom_hash" - ",age_commitment_hash1 AS h_age_commitment" - ",existed2 AS existed2" - ",known_coin_id2 AS known_coin_id2" - ",denom_pub_hash2 AS denom_hash2" - ",age_commitment_hash2 AS h_age_commitment2" - ",existed3 AS existed3" - ",known_coin_id3 AS known_coin_id3" - ",denom_pub_hash3 AS denom_hash3" - ",age_commitment_hash3 AS h_age_commitment3" - ",existed4 AS existed4" - ",known_coin_id4 AS known_coin_id4" - ",denom_pub_hash4 AS denom_hash4" - ",age_commitment_hash4 AS h_age_commitment4" - " FROM donau_do_batch2_known_coin" - " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16);" - ); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[0].denom_sig), - - GNUNET_PQ_query_param_auto_from_type (&coin[1].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[1].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[1].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[0].denom_sig), - - GNUNET_PQ_query_param_auto_from_type (&coin[2].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[2].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[2].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[2].denom_sig), - - GNUNET_PQ_query_param_auto_from_type (&coin[3].coin_pub), - GNUNET_PQ_query_param_auto_from_type (&coin[3].denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&coin[3].h_age_commitment), - TALER_PQ_query_param_denom_sig (&coin[3].denom_sig), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("existed", - &result[0].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id", - &result[0].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &result[0].denom_hash), - &is_denom_pub_hash_null), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &result[0].h_age_commitment), - &is_age_hash_null), - GNUNET_PQ_result_spec_bool ("existed2", - &result[1].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id2", - &result[1].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash2", - &result[1].denom_hash), - &is_denom_pub_hash_null2), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash2", - &result[1].h_age_commitment), - &is_age_hash_null2), - GNUNET_PQ_result_spec_bool ("existed3", - &result[2].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id3", - &result[2].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash3", - &result[2].denom_hash), - &is_denom_pub_hash_null3), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash3", - &result[2].h_age_commitment), - &is_age_hash_null3), - GNUNET_PQ_result_spec_bool ("existed4", - &result[3].existed), - GNUNET_PQ_result_spec_uint64 ("known_coin_id4", - &result[3].known_coin_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash4", - &result[3].denom_hash), - &is_denom_pub_hash_null4), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash4", - &result[3].h_age_commitment), - &is_age_hash_null4), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "batch4_known_coin", - params, - rs); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - return qs; - case GNUNET_DB_STATUS_SOFT_ERROR: - return qs; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); /* should be impossible */ - return GNUNET_DB_STATUS_HARD_ERROR; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - break; /* continued below */ - } - - if ( (! is_denom_pub_hash_null) && - (0 != GNUNET_memcmp (&result[0].denom_hash, - &coin[0].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[0].denom_conflict = true; - } - if ( (! is_age_hash_null) && - (0 != GNUNET_memcmp (&result[0].h_age_commitment, - &coin[0].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[0].h_age_commitment)); - GNUNET_break_op (0); - result[0].age_conflict = true; - } - - if ( (! is_denom_pub_hash_null2) && - (0 != GNUNET_memcmp (&result[1].denom_hash, - &coin[1].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[1].denom_conflict = true; - } - if ( (! is_age_hash_null2) && - (0 != GNUNET_memcmp (&result[1].h_age_commitment, - &coin[1].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[1].h_age_commitment)); - GNUNET_break_op (0); - result[1].age_conflict = true; - } - - if ( (! is_denom_pub_hash_null3) && - (0 != GNUNET_memcmp (&result[2].denom_hash, - &coin[2].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[2].denom_conflict = true; - } - if ( (! is_age_hash_null3) && - (0 != GNUNET_memcmp (&result[2].h_age_commitment, - &coin[2].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[2].h_age_commitment)); - GNUNET_break_op (0); - result[2].age_conflict = true; - } - - if ( (! is_denom_pub_hash_null4) && - (0 != GNUNET_memcmp (&result[3].denom_hash, - &coin[3].denom_pub_hash)) ) - { - GNUNET_break_op (0); - result[3].denom_conflict = true; - } - if ( (! is_age_hash_null4) && - (0 != GNUNET_memcmp (&result[3].h_age_commitment, - &coin[3].h_age_commitment)) ) - { - GNUNET_break (GNUNET_is_zero (&result[3].h_age_commitment)); - GNUNET_break_op (0); - result[3].age_conflict = true; - } - return qs; -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_batch_ensure_coin_known ( - void *cls, - const struct TALER_CoinPublicInfo *coin, - struct TALER_DONAUDB_CoinInfo *result, - unsigned int coin_length, - unsigned int batch_size) -{ - struct PostgresClosure *pg = cls; - enum GNUNET_DB_QueryStatus qs = 0; - unsigned int i = 0; - - while ( (qs >= 0) && - (i < coin_length) ) - { - unsigned int bs = GNUNET_MIN (batch_size, - coin_length - i); - if (bs >= 4) - { - qs = insert4 (pg, - &coin[i], - &result[i]); - i += 4; - continue; - } - switch (bs) - { - case 3: - case 2: - qs = insert2 (pg, - &coin[i], - &result[i]); - i += 2; - break; - case 1: - qs = insert1 (pg, - &coin[i], - &result[i]); - i += 1; - break; - case 0: - GNUNET_assert (0); - break; - } - } /* end while */ - if (qs < 0) - return qs; - return i; -} diff --git a/src/donaudb/pg_batch_ensure_coin_known.h b/src/donaudb/pg_batch_ensure_coin_known.h @@ -1,47 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_batch_ensure_coin_known.h - * @brief implementation of the batch_ensure_coin_known function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_BATCH_ENSURE_COIN_KNOWN_H -#define PG_BATCH_ENSURE_COIN_KNOWN_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - - -/** - * Make sure the array of given @a coin is known to the database. - * - * @param cls database connection plugin state - * @param coin array of coins that must be made known - * @param[out] result array where to store information about each coin - * @param coin_length length of the @a coin and @a result arraysf - * @param batch_size desired (maximum) batch size - * @return database transaction status, non-negative on success - */ -enum GNUNET_DB_QueryStatus -TEH_PG_batch_ensure_coin_known ( - void *cls, - const struct TALER_CoinPublicInfo *coin, - struct TALER_DONAUDB_CoinInfo *result, - unsigned int coin_length, - unsigned int batch_size); - -#endif diff --git a/src/donaudb/pg_do_batch_withdraw.c b/src/donaudb/pg_do_batch_withdraw.c @@ -1,85 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_batch_withdraw.c - * @brief Implementation of the do_batch_withdraw function for Postgres - * @author Christian Grothoff - * @author Özgür Kesim - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_do_batch_withdraw.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_do_batch_withdraw ( - void *cls, - struct GNUNET_TIME_Timestamp now, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *amount, - bool do_age_check, - bool *found, - bool *balance_ok, - bool *age_ok, - uint16_t *allowed_maximum_age, - uint64_t *ruuid) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_TIME_Timestamp gc; - struct GNUNET_PQ_QueryParam params[] = { - TALER_PQ_query_param_amount (pg->conn, - amount), - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_timestamp (&gc), - GNUNET_PQ_query_param_bool (do_age_check), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("reserve_found", - found), - GNUNET_PQ_result_spec_bool ("balance_ok", - balance_ok), - GNUNET_PQ_result_spec_bool ("age_ok", - age_ok), - GNUNET_PQ_result_spec_uint16 ("allowed_maximum_age", - allowed_maximum_age), - GNUNET_PQ_result_spec_uint64 ("ruuid", - ruuid), - GNUNET_PQ_result_spec_end - }; - - gc = GNUNET_TIME_absolute_to_timestamp ( - GNUNET_TIME_absolute_add (now.abs_time, - pg->legal_reserve_expiration_time)); - PREPARE (pg, - "call_batch_withdraw", - "SELECT " - " reserve_found" - ",balance_ok" - ",age_ok" - ",allowed_maximum_age" - ",ruuid" - " FROM donau_do_batch_withdraw" - " ($1,$2,$3,$4,$5);"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_batch_withdraw", - params, - rs); -} diff --git a/src/donaudb/pg_do_batch_withdraw.h b/src/donaudb/pg_do_batch_withdraw.h @@ -1,57 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_batch_withdraw.h - * @brief implementation of the do_batch_withdraw function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_DO_BATCH_WITHDRAW_H -#define PG_DO_BATCH_WITHDRAW_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Perform reserve update as part of a batch withdraw operation, checking - * for sufficient balance. Persisting the withdrawal details is done - * separately! - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param now current time (rounded) - * @param reserve_pub public key of the reserve to debit - * @param amount total amount to withdraw - * @param age_check_required if true, fail if age requirements are set on the reserve - * @param[out] found set to true if the reserve was found - * @param[out] balance_ok set to true if the balance was sufficient - * @param[out] age_ok set to true if no age requirements are present on the reserve - * @param[out] allowed_maximum_age if @e age_ok is false, set to the maximum allowed age when withdrawing from this reserve (client needs to call age-withdraw) - * @param[out] ruuid set to the reserve's UUID (reserves table row) - * @return query execution status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_do_batch_withdraw ( - void *cls, - struct GNUNET_TIME_Timestamp now, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_Amount *amount, - bool age_check_required, - bool *found, - bool *balance_ok, - bool *age_ok, - uint16_t *allowed_maximum_age, - uint64_t *ruuid); - -#endif diff --git a/src/donaudb/pg_do_batch_withdraw_insert.c b/src/donaudb/pg_do_batch_withdraw_insert.c @@ -1,77 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_batch_withdraw_insert.c - * @brief Implementation of the do_batch_withdraw_insert 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_do_batch_withdraw_insert.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_do_batch_withdraw_insert ( - void *cls, - const struct TALER_CsNonce *nonce, - const struct TALER_DONAUDB_CollectableBlindcoin *collectable, - struct GNUNET_TIME_Timestamp now, - uint64_t ruuid, - bool *denom_unknown, - bool *conflict, - bool *nonce_reuse) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - NULL == nonce - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_auto_from_type (nonce), - TALER_PQ_query_param_amount (pg->conn, - &collectable->amount_with_fee), - GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash), - GNUNET_PQ_query_param_uint64 (&ruuid), - GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig), - GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope), - TALER_PQ_query_param_blinded_denom_sig (&collectable->sig), - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("denom_unknown", - denom_unknown), - GNUNET_PQ_result_spec_bool ("conflict", - conflict), - GNUNET_PQ_result_spec_bool ("nonce_reuse", - nonce_reuse), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "call_batch_withdraw_insert", - "SELECT " - " out_denom_unknown AS denom_unknown" - ",out_conflict AS conflict" - ",out_nonce_reuse AS nonce_reuse" - " FROM donau_do_batch_withdraw_insert" - " ($1,$2,$3,$4,$5,$6,$7,$8);"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_batch_withdraw_insert", - params, - rs); -} diff --git a/src/donaudb/pg_do_batch_withdraw_insert.h b/src/donaudb/pg_do_batch_withdraw_insert.h @@ -1,52 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_batch_withdraw_insert.h - * @brief implementation of the do_batch_withdraw_insert function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_DO_BATCH_WITHDRAW_INSERT_H -#define PG_DO_BATCH_WITHDRAW_INSERT_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Perform insert as part of a batch withdraw operation, and persisting the - * withdrawal details. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals - * @param collectable corresponding collectable coin (blind signature) - * @param now current time (rounded) - * @param ruuid reserve UUID - * @param[out] denom_unknown set if the denomination is unknown in the DB - * @param[out] conflict if the envelope was already in the DB - * @param[out] nonce_reuse if @a nonce was non-NULL and reused - * @return query execution status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_do_batch_withdraw_insert ( - void *cls, - const struct TALER_CsNonce *nonce, - const struct TALER_DONAUDB_CollectableBlindcoin *collectable, - struct GNUNET_TIME_Timestamp now, - uint64_t ruuid, - bool *denom_unknown, - bool *conflict, - bool *nonce_reuse); - -#endif diff --git a/src/donaudb/pg_do_deposit.c b/src/donaudb/pg_do_deposit.c @@ -1,116 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_deposit.c - * @brief Implementation of the do_deposit 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_do_deposit.h" -#include "pg_helper.h" -#include "pg_compute_shard.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_do_deposit ( - void *cls, - const struct TALER_DONAUDB_BatchDeposit *bd, - struct GNUNET_TIME_Timestamp *donau_timestamp, - bool *balance_ok, - uint32_t *bad_balance_index, - bool *ctr_conflict) -{ - struct PostgresClosure *pg = cls; - uint64_t deposit_shard = TEH_PG_compute_shard (&bd->charity_pub); - const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)]; - const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)]; - struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)]; - struct GNUNET_PQ_QueryParam params[] = { - /* data for batch_deposits */ - GNUNET_PQ_query_param_uint64 (&deposit_shard), - GNUNET_PQ_query_param_auto_from_type (&bd->charity_pub), - GNUNET_PQ_query_param_timestamp (&bd->wallet_timestamp), - GNUNET_PQ_query_param_timestamp (donau_timestamp), - GNUNET_PQ_query_param_timestamp (&bd->refund_deadline), - GNUNET_PQ_query_param_timestamp (&bd->wire_deadline), - GNUNET_PQ_query_param_auto_from_type (&bd->h_contract_terms), - (bd->no_wallet_data_hash) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash), - GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt), - GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto), - (0 == bd->policy_details_serial_id) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id), - GNUNET_PQ_query_param_bool (bd->policy_blocked), - /* to create entry in wire_targets */ - GNUNET_PQ_query_param_string (bd->receiver_wire_account), - /* arrays for coin_deposits */ - GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, - coin_pubs, - pg->conn), - GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis, - coin_sigs, - pg->conn), - TALER_PQ_query_param_array_amount (bd->num_cdis, - amounts_with_fee, - pg->conn), - GNUNET_PQ_query_param_end - }; - bool no_time; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_timestamp ("donau_timestamp", - donau_timestamp), - &no_time), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("insufficient_balance_coin_index", - bad_balance_index), - balance_ok), - GNUNET_PQ_result_spec_bool ("conflicted", - ctr_conflict), - GNUNET_PQ_result_spec_end - }; - - for (unsigned int i = 0; i < bd->num_cdis; i++) - { - const struct TALER_DONAUDB_CoinDepositInformation *cdi - = &bd->cdis[i]; - - amounts_with_fee[i] = cdi->amount_with_fee; - coin_pubs[i] = &cdi->coin.coin_pub; - coin_sigs[i] = &cdi->csig; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Do deposit %u = %s\n", - i, - TALER_B2S (&cdi->coin.coin_pub)); - } - PREPARE (pg, - "call_deposit", - "SELECT " - " out_donau_timestamp AS donau_timestamp" - ",out_insufficient_balance_coin_index AS insufficient_balance_coin_index" - ",out_conflict AS conflicted" - " FROM donau_do_deposit" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_deposit", - params, - rs); -} diff --git a/src/donaudb/pg_do_deposit.h b/src/donaudb/pg_do_deposit.h @@ -1,51 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_deposit.h - * @brief implementation of the do_deposit function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_DO_DEPOSIT_H -#define PG_DO_DEPOSIT_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - - -/** - * Perform deposit operation, checking for sufficient balance - * of the coins and possibly persisting the deposit details. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param bd batch deposit operation details - * @param[in,out] donau_timestamp time to use for the deposit (possibly updated) - * @param[out] balance_ok set to true if the balance was sufficient - * @param[out] bad_balance_index set to the first index of a coin for which the balance was insufficient, - * only used if @a balance_ok is set to false. - * @param[out] in_conflict set to true if the deposit conflicted - * @return query execution status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_do_deposit ( - void *cls, - const struct TALER_DONAUDB_BatchDeposit *bd, - struct GNUNET_TIME_Timestamp *donau_timestamp, - bool *balance_ok, - uint32_t *bad_balance_index, - bool *in_conflict); - -#endif diff --git a/src/donaudb/pg_do_withdraw.c b/src/donaudb/pg_do_withdraw.c @@ -1,95 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_withdraw.c - * @brief Implementation of the do_withdraw 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_do_withdraw.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_do_withdraw ( - void *cls, - const struct TALER_CsNonce *nonce, - const struct TALER_DONAUDB_CollectableBlindcoin *collectable, - struct GNUNET_TIME_Timestamp now, - bool do_age_check, - bool *found, - bool *balance_ok, - bool *nonce_ok, - bool *age_ok, - uint16_t *allowed_maximum_age, - uint64_t *ruuid) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_TIME_Timestamp gc; - struct GNUNET_PQ_QueryParam params[] = { - NULL == nonce - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_auto_from_type (nonce), - TALER_PQ_query_param_amount (pg->conn, - &collectable->amount_with_fee), - GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub), - GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig), - GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope), - TALER_PQ_query_param_blinded_denom_sig (&collectable->sig), - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_timestamp (&gc), - GNUNET_PQ_query_param_bool (do_age_check), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("reserve_found", - found), - GNUNET_PQ_result_spec_bool ("balance_ok", - balance_ok), - GNUNET_PQ_result_spec_bool ("nonce_ok", - nonce_ok), - GNUNET_PQ_result_spec_bool ("age_ok", - age_ok), - GNUNET_PQ_result_spec_uint16 ("allowed_maximum_age", - allowed_maximum_age), - GNUNET_PQ_result_spec_uint64 ("ruuid", - ruuid), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "call_withdraw", - "SELECT " - " reserve_found" - ",balance_ok" - ",nonce_ok" - ",age_ok" - ",allowed_maximum_age" - ",ruuid" - " FROM donau_do_withdraw" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);"); - gc = GNUNET_TIME_absolute_to_timestamp ( - GNUNET_TIME_absolute_add (now.abs_time, - pg->legal_reserve_expiration_time)); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "call_withdraw", - params, - rs); -} diff --git a/src/donaudb/pg_do_withdraw.h b/src/donaudb/pg_do_withdraw.h @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_do_withdraw.h - * @brief implementation of the do_withdraw function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_DO_WITHDRAW_H -#define PG_DO_WITHDRAW_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Perform withdraw operation, checking for sufficient balance - * and possibly persisting the withdrawal details. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals - * @param[in,out] collectable corresponding collectable coin (blind signature) if a coin is found; possibly updated if a (different) signature exists already - * @param now current time (rounded) - * @param do_age_check set to true if age requirements must be verified - * @param[out] found set to true if the reserve was found - * @param[out] balance_ok set to true if the balance was sufficient - * @param[out] nonce_ok set to false if the nonce was reused - * @param[out] age_ok set to true if age requirements are met - * @param[out] allowed_maximum_age if @e age_ok is false, the maximum age (in years) that is allowed during age-withdraw - * @param[out] ruuid set to the reserve's UUID (reserves table row) - * @return query execution status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_do_withdraw ( - void *cls, - const struct TALER_CsNonce *nonce, - const struct TALER_DONAUDB_CollectableBlindcoin *collectable, - struct GNUNET_TIME_Timestamp now, - bool do_age_check, - bool *found, - bool *balance_ok, - bool *nonce_ok, - bool *age_ok, - uint16_t *allowed_maximum_age, - uint64_t *ruuid); - -#endif diff --git a/src/donaudb/pg_ensure_coin_known.h b/src/donaudb/pg_ensure_coin_known.h @@ -25,7 +25,7 @@ #include "taler_json_lib.h" #include "taler_donaudb_plugin.h" /** - * Make sure the given @a coin is known to the database. + * Make sure the given @a donation unit is known to the database. * * @param cls database connection plugin state * @param coin the coin that must be made known @@ -39,7 +39,6 @@ enum TALER_DONAUDB_CoinKnownStatus TEH_PG_ensure_coin_known (void *cls, const struct TALER_CoinPublicInfo *coin, uint64_t *known_coin_id, - struct TALER_DenominationHashP *denom_hash, - struct TALER_AgeCommitmentHash *h_age_commitment); + struct TALER_DenominationHashP *denom_hash); #endif diff --git a/src/donaudb/pg_get_coin_denomination.c b/src/donaudb/pg_get_coin_denomination.c @@ -1,69 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_coin_denomination.c - * @brief Implementation of the get_coin_denomination 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_get_coin_denomination.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TEH_PG_get_coin_denomination ( - void *cls, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - uint64_t *known_coin_id, - struct TALER_DenominationHashP *denom_hash) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (coin_pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - denom_hash), - GNUNET_PQ_result_spec_uint64 ("known_coin_id", - known_coin_id), - GNUNET_PQ_result_spec_end - }; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Getting coin denomination of coin %s\n", - TALER_B2S (coin_pub)); - - /* Used in #postgres_get_coin_denomination() to fetch - the denomination public key hash for - a coin known to the donau. */ - PREPARE (pg, - "get_coin_denomination", - "SELECT" - " denominations.denom_pub_hash" - ",known_coin_id" - " FROM known_coins" - " JOIN denominations USING (denominations_serial)" - " WHERE coin_pub=$1" - " FOR SHARE;"); - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_coin_denomination", - params, - rs); -} diff --git a/src/donaudb/pg_get_coin_denomination.h b/src/donaudb/pg_get_coin_denomination.h @@ -1,43 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_coin_denomination.h - * @brief implementation of the get_coin_denomination function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_COIN_DENOMINATION_H -#define PG_GET_COIN_DENOMINATION_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Retrieve the denomination of a known coin. - * - * @param cls the plugin closure - * @param coin_pub the public key of the coin to search for - * @param[out] known_coin_id set to the ID of the coin in the known_coins table - * @param[out] denom_hash where to store the hash of the coins denomination - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_coin_denomination ( - void *cls, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - uint64_t *known_coin_id, - struct TALER_DenominationHashP *denom_hash); - -#endif diff --git a/src/donaudb/pg_get_coin_transactions.c b/src/donaudb/pg_get_coin_transactions.c @@ -1,948 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file pg_get_coin_transactions.c - * @brief Low-level (statement-level) Postgres database access for the donau - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_get_coin_transactions.h" -#include "pg_helper.h" -#include "plugin_donaudb_common.h" - - -/** - * Closure for callbacks called from #postgres_get_coin_transactions() - */ -struct CoinHistoryContext -{ - /** - * Head of the coin's history list. - */ - struct TALER_DONAUDB_TransactionList *head; - - /** - * Public key of the coin we are building the history for. - */ - const struct TALER_CoinSpendPublicKeyP *coin_pub; - - /** - * Closure for all callbacks of this database plugin. - */ - void *db_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Set to 'true' if the transaction failed. - */ - bool failed; - - /** - * Set to 'true' if we found a deposit or melt (for invariant check). - */ - bool have_deposit_or_melt; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_deposit (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_DONAUDB_DepositListEntry *deposit; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - chc->have_deposit_or_melt = true; - deposit = GNUNET_new (struct TALER_DONAUDB_DepositListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &deposit->amount_with_fee), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", - &deposit->deposit_fee), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &deposit->h_denom_pub), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &deposit->h_age_commitment), - &deposit->no_age_commitment), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("wallet_data_hash", - &deposit->wallet_data_hash), - &deposit->no_wallet_data_hash), - GNUNET_PQ_result_spec_timestamp ("wallet_timestamp", - &deposit->timestamp), - GNUNET_PQ_result_spec_timestamp ("refund_deadline", - &deposit->refund_deadline), - GNUNET_PQ_result_spec_timestamp ("wire_deadline", - &deposit->wire_deadline), - GNUNET_PQ_result_spec_auto_from_type ("charity_pub", - &deposit->charity_pub), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &deposit->h_contract_terms), - GNUNET_PQ_result_spec_auto_from_type ("wire_salt", - &deposit->wire_salt), - GNUNET_PQ_result_spec_string ("payto_uri", - &deposit->receiver_wire_account), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &deposit->csig), - GNUNET_PQ_result_spec_uint64 ("coin_deposit_serial_id", - &serial_id), - GNUNET_PQ_result_spec_auto_from_type ("done", - &deposit->done), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (deposit); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_DEPOSIT; - tl->details.deposit = deposit; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_purse_deposit (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_DONAUDB_PurseDepositListEntry *deposit; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - chc->have_deposit_or_melt = true; - deposit = GNUNET_new (struct TALER_DONAUDB_PurseDepositListEntry); - { - bool not_finished; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &deposit->amount), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", - &deposit->deposit_fee), - GNUNET_PQ_result_spec_auto_from_type ("purse_pub", - &deposit->purse_pub), - GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id", - &serial_id), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("partner_base_url", - &deposit->donau_base_url), - NULL), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &deposit->coin_sig), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &deposit->h_age_commitment), - &deposit->no_age_commitment), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_bool ("refunded", - &deposit->refunded), - &not_finished), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (deposit); - chc->failed = true; - return; - } - if (not_finished) - deposit->refunded = false; - deposit->no_age_commitment = GNUNET_is_zero (&deposit->h_age_commitment); - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_PURSE_DEPOSIT; - tl->details.purse_deposit = deposit; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_melt (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_MeltListEntry *melt; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - chc->have_deposit_or_melt = true; - melt = GNUNET_new (struct TALER_DONAUDB_MeltListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("rc", - &melt->rc), - /* oldcoin_index not needed */ - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &melt->h_denom_pub), - GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig", - &melt->coin_sig), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &melt->amount_with_fee), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", - &melt->melt_fee), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash", - &melt->h_age_commitment), - &melt->no_age_commitment), - GNUNET_PQ_result_spec_uint64 ("melt_serial_id", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (melt); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_MELT; - tl->details.melt = melt; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_refund (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_RefundListEntry *refund; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - refund = GNUNET_new (struct TALER_DONAUDB_RefundListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("charity_pub", - &refund->charity_pub), - GNUNET_PQ_result_spec_auto_from_type ("charity_sig", - &refund->charity_sig), - GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", - &refund->h_contract_terms), - GNUNET_PQ_result_spec_uint64 ("rtransaction_id", - &refund->rtransaction_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &refund->refund_amount), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", - &refund->refund_fee), - GNUNET_PQ_result_spec_uint64 ("refund_serial_id", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (refund); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_REFUND; - tl->details.refund = refund; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_purse_decision (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_PurseRefundListEntry *prefund; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - prefund = GNUNET_new (struct TALER_DONAUDB_PurseRefundListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("purse_pub", - &prefund->purse_pub), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &prefund->refund_amount), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", - &prefund->refund_fee), - GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (prefund); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_PURSE_REFUND; - tl->details.purse_refund = prefund; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_old_coin_recoup (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_RecoupRefreshListEntry *recoup; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - recoup = GNUNET_new (struct TALER_DONAUDB_RecoupRefreshListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("coin_pub", - &recoup->coin.coin_pub), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &recoup->coin_sig), - GNUNET_PQ_result_spec_auto_from_type ("coin_blind", - &recoup->coin_blind), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &recoup->value), - GNUNET_PQ_result_spec_timestamp ("recoup_timestamp", - &recoup->timestamp), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &recoup->coin.denom_pub_hash), - TALER_PQ_result_spec_denom_sig ("denom_sig", - &recoup->coin.denom_sig), - GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (recoup); - chc->failed = true; - return; - } - recoup->old_coin_pub = *chc->coin_pub; - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_OLD_COIN_RECOUP; - tl->details.old_coin_recoup = recoup; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_recoup (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_RecoupListEntry *recoup; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - recoup = GNUNET_new (struct TALER_DONAUDB_RecoupListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &recoup->reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &recoup->coin_sig), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &recoup->h_denom_pub), - GNUNET_PQ_result_spec_auto_from_type ("coin_blind", - &recoup->coin_blind), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &recoup->value), - GNUNET_PQ_result_spec_timestamp ("recoup_timestamp", - &recoup->timestamp), - GNUNET_PQ_result_spec_uint64 ("recoup_uuid", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (recoup); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_RECOUP; - tl->details.recoup = recoup; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_recoup_refresh (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_RecoupRefreshListEntry *recoup; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - recoup = GNUNET_new (struct TALER_DONAUDB_RecoupRefreshListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub", - &recoup->old_coin_pub), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &recoup->coin_sig), - GNUNET_PQ_result_spec_auto_from_type ("coin_blind", - &recoup->coin_blind), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", - &recoup->value), - GNUNET_PQ_result_spec_timestamp ("recoup_timestamp", - &recoup->timestamp), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &recoup->coin.denom_pub_hash), - TALER_PQ_result_spec_denom_sig ("denom_sig", - &recoup->coin.denom_sig), - GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (recoup); - chc->failed = true; - return; - } - recoup->coin.coin_pub = *chc->coin_pub; - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_RECOUP_REFRESH; - tl->details.recoup_refresh = recoup; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure of type `struct CoinHistoryContext` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -add_coin_reserve_open (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct CoinHistoryContext *chc = cls; - struct PostgresClosure *pg = chc->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_ReserveOpenListEntry *role; - struct TALER_DONAUDB_TransactionList *tl; - uint64_t serial_id; - - role = GNUNET_new (struct TALER_DONAUDB_ReserveOpenListEntry); - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &role->reserve_sig), - GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &role->coin_sig), - TALER_PQ_RESULT_SPEC_AMOUNT ("contribution", - &role->coin_contribution), - GNUNET_PQ_result_spec_uint64 ("reserve_open_deposit_uuid", - &serial_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - GNUNET_free (role); - chc->failed = true; - return; - } - } - tl = GNUNET_new (struct TALER_DONAUDB_TransactionList); - tl->next = chc->head; - tl->type = TALER_DONAUDB_TT_RESERVE_OPEN; - tl->details.reserve_open = role; - tl->serial_id = serial_id; - chc->head = tl; - } -} - - -/** - * Work we need to do. - */ -struct Work -{ - /** - * SQL prepared statement name. - */ - const char *statement; - - /** - * Function to call to handle the result(s). - */ - GNUNET_PQ_PostgresResultHandler cb; -}; - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_coin_transactions ( - void *cls, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - struct TALER_DONAUDB_TransactionList **tlp) -{ - struct PostgresClosure *pg = cls; - static const struct Work work[] = { - /** #TALER_DONAUDB_TT_DEPOSIT */ - { "get_deposit_with_coin_pub", - &add_coin_deposit }, - /** #TALER_DONAUDB_TT_MELT */ - { "get_refresh_session_by_coin", - &add_coin_melt }, - /** #TALER_DONAUDB_TT_PURSE_DEPOSIT */ - { "get_purse_deposit_by_coin_pub", - &add_coin_purse_deposit }, - /** #TALER_DONAUDB_TT_PURSE_REFUND */ - { "get_purse_decision_by_coin_pub", - &add_coin_purse_decision }, - /** #TALER_DONAUDB_TT_REFUND */ - { "get_refunds_by_coin", - &add_coin_refund }, - /** #TALER_DONAUDB_TT_OLD_COIN_RECOUP */ - { "recoup_by_old_coin", - &add_old_coin_recoup }, - /** #TALER_DONAUDB_TT_RECOUP */ - { "recoup_by_coin", - &add_coin_recoup }, - /** #TALER_DONAUDB_TT_RECOUP_REFRESH */ - { "recoup_by_refreshed_coin", - &add_coin_recoup_refresh }, - /** #TALER_DONAUDB_TT_RESERVE_OPEN */ - { "reserve_open_by_coin", - &add_coin_reserve_open }, - { NULL, NULL } - }; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (coin_pub), - GNUNET_PQ_query_param_end - }; - enum GNUNET_DB_QueryStatus qs; - struct CoinHistoryContext chc = { - .head = NULL, - .coin_pub = coin_pub, - .pg = pg, - .db_cls = cls - }; - - PREPARE (pg, - "get_deposit_with_coin_pub", - "SELECT" - " cdep.amount_with_fee" - ",denoms.fee_deposit" - ",denoms.denom_pub_hash" - ",kc.age_commitment_hash" - ",bdep.wallet_timestamp" - ",bdep.refund_deadline" - ",bdep.wire_deadline" - ",bdep.charity_pub" - ",bdep.h_contract_terms" - ",bdep.wallet_data_hash" - ",bdep.wire_salt" - ",wt.payto_uri" - ",cdep.coin_sig" - ",cdep.coin_deposit_serial_id" - ",bdep.done" - " FROM coin_deposits cdep" - " JOIN batch_deposits bdep" - " USING (batch_deposit_serial_id)" - " JOIN wire_targets wt" - " USING (wire_target_h_payto)" - " JOIN known_coins kc" - " ON (kc.coin_pub = cdep.coin_pub)" - " JOIN denominations denoms" - " USING (denominations_serial)" - " WHERE cdep.coin_pub=$1;"); - PREPARE (pg, - "get_refresh_session_by_coin", - "SELECT" - " rc" - ",old_coin_sig" - ",amount_with_fee" - ",denoms.denom_pub_hash" - ",denoms.fee_refresh" - ",kc.age_commitment_hash" - ",melt_serial_id" - " FROM refresh_commitments" - " JOIN known_coins kc" - " ON (refresh_commitments.old_coin_pub = kc.coin_pub)" - " JOIN denominations denoms" - " USING (denominations_serial)" - " WHERE old_coin_pub=$1;"); - PREPARE (pg, - "get_purse_deposit_by_coin_pub", - "SELECT" - " partner_base_url" - ",pd.amount_with_fee" - ",denoms.fee_deposit" - ",pd.purse_pub" - ",kc.age_commitment_hash" - ",pd.coin_sig" - ",pd.purse_deposit_serial_id" - ",pdes.refunded" - " FROM purse_deposits pd" - " LEFT JOIN partners" - " USING (partner_serial_id)" - " JOIN purse_requests pr" - " USING (purse_pub)" - " LEFT JOIN purse_decision pdes" - " USING (purse_pub)" - " JOIN known_coins kc" - " ON (pd.coin_pub = kc.coin_pub)" - " JOIN denominations denoms" - " USING (denominations_serial)" - // FIXME: use to-be-created materialized index - // on coin_pub (query crosses partitions!) - " WHERE pd.coin_pub=$1;"); - PREPARE (pg, - "get_refunds_by_coin", - "SELECT" - " bdep.charity_pub" - ",ref.charity_sig" - ",bdep.h_contract_terms" - ",ref.rtransaction_id" - ",ref.amount_with_fee" - ",denom.fee_refund" - ",ref.refund_serial_id" - " FROM refunds ref" - " JOIN coin_deposits cdep" - " ON (ref.coin_pub = cdep.coin_pub AND ref.batch_deposit_serial_id = cdep.batch_deposit_serial_id)" - " JOIN batch_deposits bdep" - " ON (ref.batch_deposit_serial_id = bdep.batch_deposit_serial_id)" - " JOIN known_coins kc" - " ON (ref.coin_pub = kc.coin_pub)" - " JOIN denominations denom" - " USING (denominations_serial)" - " WHERE ref.coin_pub=$1;"); - PREPARE (pg, - "get_purse_decision_by_coin_pub", - "SELECT" - " pdes.purse_pub" - ",pd.amount_with_fee" - ",denom.fee_refund" - ",pdes.purse_decision_serial_id" - " FROM purse_deposits pd" - " JOIN purse_decision pdes" - " USING (purse_pub)" - " JOIN known_coins kc" - " ON (pd.coin_pub = kc.coin_pub)" - " JOIN denominations denom" - " USING (denominations_serial)" - " WHERE pd.coin_pub=$1" - " AND pdes.refunded;"); - PREPARE (pg, - "recoup_by_old_coin", - "SELECT" - " coins.coin_pub" - ",coin_sig" - ",coin_blind" - ",amount" - ",recoup_timestamp" - ",denoms.denom_pub_hash" - ",coins.denom_sig" - ",recoup_refresh_uuid" - " FROM recoup_refresh" - " JOIN known_coins coins" - " USING (coin_pub)" - " JOIN denominations denoms" - " USING (denominations_serial)" - " WHERE rrc_serial IN" - " (SELECT rrc.rrc_serial" - " FROM refresh_commitments" - " JOIN refresh_revealed_coins rrc" - " USING (melt_serial_id)" - " WHERE old_coin_pub=$1);"); - PREPARE (pg, - "recoup_by_coin", - "SELECT" - " reserves.reserve_pub" - ",denoms.denom_pub_hash" - ",coin_sig" - ",coin_blind" - ",amount" - ",recoup_timestamp" - ",recoup_uuid" - " FROM recoup rcp" - /* NOTE: suboptimal JOIN follows: crosses shards! - Could theoretically be improved via a materialized - index. But likely not worth it (query is rare and - number of reserve shards might be limited) */ - " JOIN reserves_out ro" - " USING (reserve_out_serial_id)" - " JOIN reserves" - " USING (reserve_uuid)" - " JOIN known_coins coins" - " USING (coin_pub)" - " JOIN denominations denoms" - " ON (denoms.denominations_serial = coins.denominations_serial)" - " WHERE coins.coin_pub=$1;"); - /* Used in #postgres_get_coin_transactions() to obtain recoup transactions - for a refreshed coin */ - PREPARE (pg, - "recoup_by_refreshed_coin", - "SELECT" - " old_coins.coin_pub AS old_coin_pub" - ",coin_sig" - ",coin_blind" - ",amount" - ",recoup_timestamp" - ",denoms.denom_pub_hash" - ",coins.denom_sig" - ",recoup_refresh_uuid" - " FROM recoup_refresh" - " JOIN refresh_revealed_coins rrc" - " USING (rrc_serial)" - " JOIN refresh_commitments rfc" - " ON (rrc.melt_serial_id = rfc.melt_serial_id)" - " JOIN known_coins old_coins" - " ON (rfc.old_coin_pub = old_coins.coin_pub)" - " JOIN known_coins coins" - " ON (recoup_refresh.coin_pub = coins.coin_pub)" - " JOIN denominations denoms" - " ON (denoms.denominations_serial = coins.denominations_serial)" - " WHERE coins.coin_pub=$1;"); - PREPARE (pg, - "reserve_open_by_coin", - "SELECT" - " reserve_open_deposit_uuid" - ",coin_sig" - ",reserve_sig" - ",contribution" - " FROM reserves_open_deposits" - " WHERE coin_pub=$1;"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Getting transactions for coin %s\n", - TALER_B2S (coin_pub)); - for (unsigned int i = 0; NULL != work[i].statement; i++) - { - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - work[i].statement, - params, - work[i].cb, - &chc); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Coin %s yielded %d transactions of type %s\n", - TALER_B2S (coin_pub), - qs, - work[i].statement); - if ( (0 > qs) || - (chc.failed) ) - { - if (NULL != chc.head) - TEH_COMMON_free_coin_transaction_list (cls, - chc.head); - *tlp = NULL; - if (chc.failed) - qs = GNUNET_DB_STATUS_HARD_ERROR; - return qs; - } - } - *tlp = chc.head; - if (NULL == chc.head) - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; -} diff --git a/src/donaudb/pg_get_coin_transactions.h b/src/donaudb/pg_get_coin_transactions.h @@ -1,44 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file pg_get_coin_transactions.h - * @brief implementation of the get_coin_transactions function - * @author Christian Grothoff - */ -#ifndef PG_GET_COIN_TRANSACTIONS_H -#define PG_GET_COIN_TRANSACTIONS_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - - -/** - * Compile a list of all (historic) transactions performed with the given coin - * (/refresh/melt, /deposit, /refund and /recoup operations). - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param coin_pub coin to investigate - * @param[out] tlp set to list of transactions, NULL if coin is fresh - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_coin_transactions ( - void *cls, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - struct TALER_DONAUDB_TransactionList **tlp); - -#endif diff --git a/src/donaudb/pg_get_denomination_info.h b/src/donaudb/pg_get_denomination_info.h @@ -16,26 +16,26 @@ /** * @file donaudb/pg_get_denomination_info.h * @brief implementation of the get_denomination_info function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ -#ifndef PG_GET_DENOMINATION_INFO_H -#define PG_GET_DENOMINATION_INFO_H +#ifndef PG_GET_DONATION_UNIT_INFO_H +#define PG_GET_DONATION_UNIT_INFO_H #include "taler_util.h" #include "taler_json_lib.h" #include "taler_donaudb_plugin.h" /** - * Fetch information about a denomination key. + * Fetch information about a donation unit key. * * @param cls the @e cls of this struct with the plugin-specific state - * @param denom_pub_hash hash of the public key used for signing coins of this denomination - * @param[out] issue set to issue information with value, fees and other info about the coin + * @param donation_unit_pub_hash hash of the public key + * @param[out] info information with value, fees and other info about the coin * @return transaction status code */ enum GNUNET_DB_QueryStatus -TEH_PG_get_denomination_info ( +TEH_PG_get_donation_unit_info ( void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - struct TALER_DONAUDB_DenominationKeyInformation *issue); + const struct TALER_DonationUNitHashP *donation_unit_pub_hash, + struct TALER_DONAUDB_DonationUnitKeyInformation *info); #endif diff --git a/src/donaudb/pg_get_denomination_revocation.c b/src/donaudb/pg_get_denomination_revocation.c @@ -1,63 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_denomination_revocation.c - * @brief Implementation of the get_denomination_revocation 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_get_denomination_revocation.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TEH_PG_get_denomination_revocation ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - struct TALER_MasterSignatureP *master_sig, - uint64_t *rowid) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - master_sig), - GNUNET_PQ_result_spec_uint64 ("denom_revocations_serial_id", - rowid), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "denomination_revocation_get", - "SELECT" - " master_sig" - ",denom_revocations_serial_id" - " FROM denomination_revocations" - " WHERE denominations_serial=" - " (SELECT denominations_serial" - " FROM denominations" - " WHERE denom_pub_hash=$1);"); - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "denomination_revocation_get", - params, - rs); -} diff --git a/src/donaudb/pg_get_denomination_revocation.h b/src/donaudb/pg_get_denomination_revocation.h @@ -1,45 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_denomination_revocation.h - * @brief implementation of the get_denomination_revocation function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_DENOMINATION_REVOCATION_H -#define PG_GET_DENOMINATION_REVOCATION_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Obtain information about a denomination key's revocation from - * the database. - * - * @param cls closure - * @param denom_pub_hash hash of the revoked denomination key - * @param[out] master_sig signature affirming the revocation - * @param[out] rowid row where the information is stored - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_denomination_revocation ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - struct TALER_MasterSignatureP *master_sig, - uint64_t *rowid); - -#endif diff --git a/src/donaudb/pg_get_expired_reserves.c b/src/donaudb/pg_get_expired_reserves.c @@ -1,174 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file pg_get_expired_reserves.c - * @brief Low-level (statement-level) Postgres database access for the donau - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_get_expired_reserves.h" -#include "pg_helper.h" - - -/** - * Closure for #reserve_expired_cb(). - */ -struct ExpiredReserveContext -{ - /** - * Function to call for each expired reserve. - */ - TALER_DONAUDB_ReserveExpiredCallback rec; - - /** - * Closure to give to @e rec. - */ - void *rec_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Set to #GNUNET_SYSERR on error. - */ - enum GNUNET_GenericReturnValue status; -}; - - -/** - * Function to be called with the results of a SELECT statement - * that has returned @a num_results results. - * - * @param cls closure - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -reserve_expired_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct ExpiredReserveContext *erc = cls; - struct PostgresClosure *pg = erc->pg; - enum GNUNET_GenericReturnValue ret; - - ret = GNUNET_OK; - for (unsigned int i = 0; i<num_results; i++) - { - struct GNUNET_TIME_Timestamp exp_date; - char *account_details; - struct TALER_ReservePublicKeyP reserve_pub; - struct TALER_Amount remaining_balance; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_timestamp ("expiration_date", - &exp_date), - GNUNET_PQ_result_spec_string ("account_details", - &account_details), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &reserve_pub), - TALER_PQ_result_spec_amount ("current_balance", - pg->currency, - &remaining_balance), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ret = GNUNET_SYSERR; - break; - } - ret = erc->rec (erc->rec_cls, - &reserve_pub, - &remaining_balance, - account_details, - exp_date, - 0); - GNUNET_PQ_cleanup_result (rs); - if (GNUNET_OK != ret) - break; - } - erc->status = ret; -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_expired_reserves (void *cls, - struct GNUNET_TIME_Timestamp now, - TALER_DONAUDB_ReserveExpiredCallback rec, - void *rec_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&now), - GNUNET_PQ_query_param_end - }; - struct ExpiredReserveContext ectx = { - .rec = rec, - .rec_cls = rec_cls, - .pg = pg, - .status = GNUNET_OK - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "get_expired_reserves", - "WITH ed AS MATERIALIZED ( " - " SELECT * " - " FROM reserves " - " WHERE expiration_date <= $1 " - " AND ((current_balance).val != 0 OR (current_balance).frac != 0) " - " ORDER BY expiration_date ASC " - " LIMIT 1 " - ") " - "SELECT " - " ed.expiration_date " - " ,payto_uri AS account_details " - " ,ed.reserve_pub " - " ,current_balance " - "FROM ( " - " SELECT " - " * " - " FROM reserves_in " - " WHERE reserve_pub = ( " - " SELECT reserve_pub FROM ed) " - " ) ri " - "JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto) " - "JOIN ed ON (ri.reserve_pub = ed.reserve_pub);"); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "get_expired_reserves", - params, - &reserve_expired_cb, - &ectx); - switch (ectx.status) - { - case GNUNET_SYSERR: - return GNUNET_DB_STATUS_HARD_ERROR; - case GNUNET_NO: - return GNUNET_DB_STATUS_SOFT_ERROR; - case GNUNET_OK: - break; - } - return qs; -} diff --git a/src/donaudb/pg_get_expired_reserves.h b/src/donaudb/pg_get_expired_reserves.h @@ -1,45 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file pg_get_expired_reserves.h - * @brief implementation of the get_expired_reserves function - * @author Christian Grothoff - */ -#ifndef PG_GET_EXPIRED_RESERVES_H -#define PG_GET_EXPIRED_RESERVES_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - - -/** - * Obtain information about expired reserves and their - * remaining balances. - * - * @param cls closure of the plugin - * @param now timestamp based on which we decide expiration - * @param rec function to call on expired reserves - * @param rec_cls closure for @a rec - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_expired_reserves (void *cls, - struct GNUNET_TIME_Timestamp now, - TALER_DONAUDB_ReserveExpiredCallback rec, - void *rec_cls); - -#endif diff --git a/src/donaudb/pg_get_ready_deposit.c b/src/donaudb/pg_get_ready_deposit.c @@ -1,74 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022, 2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_ready_deposit.c - * @brief Implementation of the get_ready_deposit 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_get_ready_deposit.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_ready_deposit (void *cls, - uint64_t start_shard_row, - uint64_t end_shard_row, - struct TALER_CharityPublicKeyP *charity_pub, - char **payto_uri) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_TIME_Absolute now - = GNUNET_TIME_absolute_get (); - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_uint64 (&start_shard_row), - GNUNET_PQ_query_param_uint64 (&end_shard_row), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("charity_pub", - charity_pub), - GNUNET_PQ_result_spec_string ("payto_uri", - payto_uri), - GNUNET_PQ_result_spec_end - }; - const char *query = "deposits_get_ready"; - - PREPARE (pg, - query, - "SELECT" - " wts.payto_uri" - ",bdep.charity_pub" - " FROM batch_deposits bdep" - " JOIN wire_targets wts" - " USING (wire_target_h_payto)" - " WHERE NOT (bdep.done OR bdep.policy_blocked)" - " AND bdep.wire_deadline<=$1" - " AND bdep.shard >= $2" - " AND bdep.shard <= $3" - " ORDER BY " - " bdep.wire_deadline ASC" - " ,bdep.shard ASC" - " LIMIT 1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - query, - params, - rs); -} diff --git a/src/donaudb/pg_get_ready_deposit.h b/src/donaudb/pg_get_ready_deposit.h @@ -1,46 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_ready_deposit.h - * @brief implementation of the get_ready_deposit function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_READY_DEPOSIT_H -#define PG_GET_READY_DEPOSIT_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Obtain information about deposits that are ready to be executed. Such - * deposits must not be marked as "done", the execution time must be - * in the past, and the KYC status must be 'ok'. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param start_shard_row minimum shard row to select - * @param end_shard_row maximum shard row to select (inclusive) - * @param[out] charity_pub set to the public key of a charity with a ready deposit - * @param[out] payto_uri set to the account of the charity, to be freed by caller - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_ready_deposit (void *cls, - uint64_t start_shard_row, - uint64_t end_shard_row, - struct TALER_CharityPublicKeyP *charity_pub, - char **payto_uri); - -#endif diff --git a/src/donaudb/pg_get_reserve_balance.c b/src/donaudb/pg_get_reserve_balance.c @@ -1,55 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_reserve_balance.c - * @brief Implementation of the get_reserve_balance 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_get_reserve_balance.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_balance (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_Amount *balance) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("current_balance", - pg->currency, - balance), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "get_reserve_balance", - "SELECT" - " current_balance" - " FROM reserves" - " WHERE reserve_pub=$1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_reserve_balance", - params, - rs); -} diff --git a/src/donaudb/pg_get_reserve_balance.h b/src/donaudb/pg_get_reserve_balance.h @@ -1,40 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_reserve_balance.h - * @brief implementation of the get_reserve_balance function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_RESERVE_BALANCE_H -#define PG_GET_RESERVE_BALANCE_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Get the balance of the specified reserve. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param reserve_pub public key of the reserve - * @param[out] balance set to the reserve balance - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_balance (void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_Amount *balance); - -#endif diff --git a/src/donaudb/pg_get_reserve_by_h_blind.c b/src/donaudb/pg_get_reserve_by_h_blind.c @@ -1,63 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_reserve_by_h_blind.c - * @brief Implementation of the get_reserve_by_h_blind 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_get_reserve_by_h_blind.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_by_h_blind ( - void *cls, - const struct TALER_BlindedCoinHashP *bch, - struct TALER_ReservePublicKeyP *reserve_pub, - uint64_t *reserve_out_serial_id) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (bch), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - reserve_pub), - GNUNET_PQ_result_spec_uint64 ("reserve_out_serial_id", - reserve_out_serial_id), - GNUNET_PQ_result_spec_end - }; - /* Used in #postgres_get_reserve_by_h_blind() */ - PREPARE (pg, - "reserve_by_h_blind", - "SELECT" - " reserves.reserve_pub" - ",reserve_out_serial_id" - " FROM reserves_out" - " JOIN reserves" - " USING (reserve_uuid)" - " WHERE h_blind_ev=$1" - " LIMIT 1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "reserve_by_h_blind", - params, - rs); -} diff --git a/src/donaudb/pg_get_reserve_by_h_blind.h b/src/donaudb/pg_get_reserve_by_h_blind.h @@ -1,44 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_reserve_by_h_blind.h - * @brief implementation of the get_reserve_by_h_blind function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_RESERVE_BY_H_BLIND_H -#define PG_GET_RESERVE_BY_H_BLIND_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Obtain information about which reserve a coin was generated - * from given the hash of the blinded coin. - * - * @param cls closure - * @param bch hash that uniquely identifies the withdraw request - * @param[out] reserve_pub set to information about the reserve (on success only) - * @param[out] reserve_out_serial_id set to row of the @a h_blind_ev in reserves_out - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_reserve_by_h_blind ( - void *cls, - const struct TALER_BlindedCoinHashP *bch, - struct TALER_ReservePublicKeyP *reserve_pub, - uint64_t *reserve_out_serial_id); - -#endif diff --git a/src/donaudb/pg_get_withdraw_info.c b/src/donaudb/pg_get_withdraw_info.c @@ -1,79 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_withdraw_info.c - * @brief Implementation of the get_withdraw_info 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_get_withdraw_info.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_get_withdraw_info ( - void *cls, - const struct TALER_BlindedCoinHashP *bch, - struct TALER_DONAUDB_CollectableBlindcoin *collectable) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (bch), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &collectable->denom_pub_hash), - TALER_PQ_result_spec_blinded_denom_sig ("denom_sig", - &collectable->sig), - GNUNET_PQ_result_spec_auto_from_type ("reserve_sig", - &collectable->reserve_sig), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", - &collectable->reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev", - &collectable->h_coin_envelope), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &collectable->amount_with_fee), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", - &collectable->withdraw_fee), - GNUNET_PQ_result_spec_end - }; - - PREPARE (pg, - "get_withdraw_info", - "SELECT" - " denom.denom_pub_hash" - ",denom_sig" - ",reserve_sig" - ",reserves.reserve_pub" - ",execution_date" - ",h_blind_ev" - ",amount_with_fee" - ",denom.fee_withdraw" - " FROM reserves_out" - " JOIN reserves" - " USING (reserve_uuid)" - " JOIN denominations denom" - " USING (denominations_serial)" - " WHERE h_blind_ev=$1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_withdraw_info", - params, - rs); -} diff --git a/src/donaudb/pg_get_withdraw_info.h b/src/donaudb/pg_get_withdraw_info.h @@ -1,43 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_get_withdraw_info.h - * @brief implementation of the get_withdraw_info function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_GET_WITHDRAW_INFO_H -#define PG_GET_WITHDRAW_INFO_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Locate the response for a /reserve/withdraw request under the - * key of the hash of the blinded message. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param bch hash that uniquely identifies the withdraw operation - * @param collectable corresponding collectable coin (blind signature) - * if a coin is found - * @return statement execution status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_get_withdraw_info ( - void *cls, - const struct TALER_BlindedCoinHashP *bch, - struct TALER_DONAUDB_CollectableBlindcoin *collectable); - -#endif diff --git a/src/donaudb/pg_have_deposit2.c b/src/donaudb/pg_have_deposit2.c @@ -1,117 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_have_deposit2.c - * @brief Implementation of the have_deposit2 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_have_deposit2.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_have_deposit2 ( - void *cls, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_CharityWireHashP *h_wire, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_CharityPublicKeyP *charity, - struct GNUNET_TIME_Timestamp refund_deadline, - struct TALER_Amount *deposit_fee, - struct GNUNET_TIME_Timestamp *donau_timestamp) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (coin_pub), - GNUNET_PQ_query_param_auto_from_type (h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (charity), - GNUNET_PQ_query_param_end - }; - struct TALER_DONAUDB_Deposit deposit2; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", - &deposit2.amount_with_fee), - GNUNET_PQ_result_spec_timestamp ("wallet_timestamp", - &deposit2.timestamp), - GNUNET_PQ_result_spec_timestamp ("donau_timestamp", - donau_timestamp), - GNUNET_PQ_result_spec_timestamp ("refund_deadline", - &deposit2.refund_deadline), - GNUNET_PQ_result_spec_timestamp ("wire_deadline", - &deposit2.wire_deadline), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", - deposit_fee), - GNUNET_PQ_result_spec_auto_from_type ("wire_salt", - &deposit2.wire_salt), - GNUNET_PQ_result_spec_string ("receiver_wire_account", - &deposit2.receiver_wire_account), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - struct TALER_CharityWireHashP h_wire2; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Getting deposits for coin %s\n", - TALER_B2S (coin_pub)); - PREPARE (pg, - "get_deposit", - "SELECT" - " cdep.amount_with_fee" - ",denominations.fee_deposit" - ",bdep.wallet_timestamp" - ",bdep.donau_timestamp" - ",bdep.refund_deadline" - ",bdep.wire_deadline" - ",bdep.h_contract_terms" - ",bdep.wire_salt" - ",wt.payto_uri AS receiver_wire_account" - " FROM coin_deposits cdep" - " JOIN batch_deposits bdep USING (batch_deposit_serial_id)" - " JOIN known_coins kc ON (kc.coin_pub = cdep.coin_pub)" - " JOIN denominations USING (denominations_serial)" - " JOIN wire_targets wt USING (wire_target_h_payto)" - " WHERE cdep.coin_pub=$1" - " AND bdep.charity_pub=$3" - " AND bdep.h_contract_terms=$2;"); - /* Note: query might be made more efficient if we computed the 'shard' - from charity_pub and included that as a constraint on bdep! */ - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_deposit", - params, - rs); - if (0 >= qs) - return qs; - TALER_charity_wire_signature_hash (deposit2.receiver_wire_account, - &deposit2.wire_salt, - &h_wire2); - GNUNET_free (deposit2.receiver_wire_account); - /* Now we check that the other information in @a deposit - also matches, and if not report inconsistencies. */ - if ( (GNUNET_TIME_timestamp_cmp (refund_deadline, - !=, - deposit2.refund_deadline)) || - (0 != GNUNET_memcmp (h_wire, - &h_wire2) ) ) - { - /* Inconsistencies detected! Does not match! */ - return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; - } - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; -} diff --git a/src/donaudb/pg_have_deposit2.h b/src/donaudb/pg_have_deposit2.h @@ -1,53 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_have_deposit2.h - * @brief implementation of the have_deposit2 function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_HAVE_DEPOSIT2_H -#define PG_HAVE_DEPOSIT2_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Check if we have the specified deposit already in the database. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param h_contract_terms contract to check for - * @param h_wire wire hash to check for - * @param coin_pub public key of the coin to check for - * @param charity charity public key to check for - * @param refund_deadline expected refund deadline - * @param[out] deposit_fee set to the deposit fee the donau charged - * @param[out] donau_timestamp set to the time when the donau received the deposit - * @return 1 if we know this operation, - * 0 if this exact deposit is unknown to us, - * otherwise transaction error status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_have_deposit2 ( - void *cls, - const struct TALER_PrivateContractHashP *h_contract_terms, - const struct TALER_CharityWireHashP *h_wire, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const struct TALER_CharityPublicKeyP *charity, - struct GNUNET_TIME_Timestamp refund_deadline, - struct TALER_Amount *deposit_fee, - struct GNUNET_TIME_Timestamp *donau_timestamp); -#endif diff --git a/src/donaudb/pg_insert_denomination_info.h b/src/donaudb/pg_insert_denomination_info.h @@ -16,27 +16,26 @@ /** * @file donaudb/pg_insert_denomination_info.h * @brief implementation of the insert_denomination_info function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ -#ifndef PG_INSERT_DENOMINATION_INFO_H -#define PG_INSERT_DENOMINATION_INFO_H +#ifndef PG_INSERT_DONATION_UNIT_INFO_H +#define PG_INSERT_DONATION_UNIT_INFO_H #include "taler_util.h" #include "taler_json_lib.h" #include "taler_donaudb_plugin.h" /** - * Insert a denomination key's public information into the database for - * reference by auditors and other consistency checks. + * Insert a donation unit key's public information into the database * * @param cls the @e cls of this struct with the plugin-specific state - * @param denom_pub the public key used for signing coins of this denomination - * @param issue issuing information with value, fees and other info about the coin + * @param donation_unit_pub the public key used for signing coins of this denomination + * @param info information with value, fees and other info about the coin * @return status of the query */ enum GNUNET_DB_QueryStatus TEH_PG_insert_denomination_info ( void *cls, - const struct TALER_DenominationPublicKey *denom_pub, - const struct TALER_DONAUDB_DenominationKeyInformation *issue); + const struct TALER_DonationUnitPublicKey *donation_unit_pub, + const struct TALER_DONAUDB_DonationUnitKeyInformation *info); #endif diff --git a/src/donaudb/pg_insert_denomination_revocation.c b/src/donaudb/pg_insert_denomination_revocation.c @@ -1,54 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_insert_denomination_revocation.c - * @brief Implementation of the insert_denomination_revocation 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_denomination_revocation.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_insert_denomination_revocation ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - const struct TALER_MasterSignatureP *master_sig) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), - GNUNET_PQ_query_param_auto_from_type (master_sig), - GNUNET_PQ_query_param_end - }; - - /* Used in #postgres_insert_denomination_revocation() */ - PREPARE (pg, - "denomination_revocation_insert", - "INSERT INTO denomination_revocations " - "(denominations_serial" - ",master_sig" - ") SELECT denominations_serial,$2" - " FROM denominations" - " WHERE denom_pub_hash=$1;"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "denomination_revocation_insert", - params); -} diff --git a/src/donaudb/pg_insert_denomination_revocation.h b/src/donaudb/pg_insert_denomination_revocation.h @@ -1,42 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_insert_denomination_revocation.h - * @brief implementation of the insert_denomination_revocation function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_INSERT_DENOMINATION_REVOCATION_H -#define PG_INSERT_DENOMINATION_REVOCATION_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Store information that a denomination key was revoked - * in the database. - * - * @param cls closure - * @param denom_pub_hash hash of the revoked denomination key - * @param master_sig signature affirming the revocation - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_insert_denomination_revocation ( - void *cls, - const struct TALER_DenominationHashP *denom_pub_hash, - const struct TALER_MasterSignatureP *master_sig); -#endif diff --git a/src/donaudb/pg_insert_signkey_revocation.h b/src/donaudb/pg_insert_signkey_revocation.h @@ -26,16 +26,14 @@ #include "taler_donaudb_plugin.h" /** - * Store information about a revoked online signing key. + * Store information about a revoked signing key. * * @param cls closure * @param donau_pub donau online signing key that was revoked - * @param master_sig signature affirming the revocation * @return transaction status code */ enum GNUNET_DB_QueryStatus TEH_PG_insert_signkey_revocation ( void *cls, - const struct TALER_DonauPublicKeyP *donau_pub, - const struct TALER_MasterSignatureP *master_sig); + const struct TALER_DonauPublicKeyP *donau_pub); #endif diff --git a/src/donaudb/pg_iterate_active_signkeys.c b/src/donaudb/pg_iterate_active_signkeys.c @@ -1,144 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_active_signkeys.c - * @brief Implementation of the iterate_active_signkeys 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_iterate_active_signkeys.h" -#include "pg_helper.h" - - -/** - * Closure for #signkeys_cb_helper() - */ -struct SignkeysIteratorContext -{ - /** - * Function to call with the results. - */ - TALER_DONAUDB_ActiveSignkeysCallback cb; - - /** - * Closure to pass to @e cb - */ - void *cb_cls; - -}; - - -/** - * Helper function for #TEH_PG_iterate_active_signkeys(). - * Calls the callback with each signkey. - * - * @param cls a `struct SignkeysIteratorContext` - * @param result db results - * @param num_results number of results in @a result - */ -static void -signkeys_cb_helper (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct SignkeysIteratorContext *dic = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_SignkeyMetaData meta; - struct TALER_DonauPublicKeyP donau_pub; - struct TALER_MasterSignatureP master_sig; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &master_sig), - GNUNET_PQ_result_spec_auto_from_type ("donau_pub", - &donau_pub), - GNUNET_PQ_result_spec_timestamp ("valid_from", - &meta.start), - GNUNET_PQ_result_spec_timestamp ("expire_sign", - &meta.expire_sign), - GNUNET_PQ_result_spec_timestamp ("expire_legal", - &meta.expire_legal), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - return; - } - dic->cb (dic->cb_cls, - &donau_pub, - &meta, - &master_sig); - } -} - - -/** - * Function called to invoke @a cb on every non-revoked donau signing key - * that has been signed by the master key. Revoked and (for signing!) - * expired keys are skipped. Runs in its own read-only transaction. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param cb function to call on each signing key - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_active_signkeys (void *cls, - TALER_DONAUDB_ActiveSignkeysCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_TIME_Absolute now = {0}; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_absolute_time (&now), - GNUNET_PQ_query_param_end - }; - struct SignkeysIteratorContext dic = { - .cb = cb, - .cb_cls = cb_cls, - }; - - PREPARE (pg, - "select_signkeys", - "SELECT" - " master_sig" - ",donau_pub" - ",valid_from" - ",expire_sign" - ",expire_legal" - " FROM donau_sign_keys esk" - " WHERE" - " expire_sign > $1" - " AND NOT EXISTS " - " (SELECT esk_serial " - " FROM signkey_revocations skr" - " WHERE esk.esk_serial = skr.esk_serial);"); - now = GNUNET_TIME_absolute_get (); - return GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "select_signkeys", - params, - &signkeys_cb_helper, - &dic); -} diff --git a/src/donaudb/pg_iterate_active_signkeys.h b/src/donaudb/pg_iterate_active_signkeys.h @@ -1,43 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_active_signkeys.h - * @brief implementation of the iterate_active_signkeys function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ITERATE_ACTIVE_SIGNKEYS_H -#define PG_ITERATE_ACTIVE_SIGNKEYS_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Function called to invoke @a cb on every non-revoked donau signing key - * that has been signed by the master key. Revoked and (for signing!) - * expired keys are skipped. Runs in its own read-only transaction. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param cb function to call on each signing key - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_active_signkeys (void *cls, - TALER_DONAUDB_ActiveSignkeysCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_iterate_denomination_info.c b/src/donaudb/pg_iterate_denomination_info.c @@ -1,180 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_denomination_info.c - * @brief Implementation of the iterate_denomination_info 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_iterate_denomination_info.h" -#include "pg_helper.h" - - -/** - * Closure for #domination_cb_helper() - */ -struct DenomIteratorContext -{ - /** - * Function to call with the results. - */ - TALER_DONAUDB_DenominationCallback cb; - - /** - * Closure to pass to @e cb - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; -}; - - -/** - * Helper function for #TEH_PG_iterate_denomination_info(). - * Calls the callback with each denomination key. - * - * @param cls a `struct DenomIteratorContext` - * @param result db results - * @param num_results number of results in @a result - */ -static void -domination_cb_helper (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct DenomIteratorContext *dic = cls; - struct PostgresClosure *pg = dic->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_DenominationKeyInformation issue; - struct TALER_DenominationPublicKey denom_pub; - struct TALER_DenominationHashP denom_hash; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &issue.signature), - GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", - &denom_hash), - GNUNET_PQ_result_spec_timestamp ("valid_from", - &issue.start), - GNUNET_PQ_result_spec_timestamp ("expire_withdraw", - &issue.expire_withdraw), - GNUNET_PQ_result_spec_timestamp ("expire_deposit", - &issue.expire_deposit), - GNUNET_PQ_result_spec_timestamp ("expire_legal", - &issue.expire_legal), - TALER_PQ_RESULT_SPEC_AMOUNT ("coin", - &issue.value), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", - &issue.fees.withdraw), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", - &issue.fees.deposit), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", - &issue.fees.refresh), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", - &issue.fees.refund), - TALER_PQ_result_spec_denom_pub ("denom_pub", - &denom_pub), - GNUNET_PQ_result_spec_uint32 ("age_mask", - &issue.age_mask.bits), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - return; - } - - /* Unfortunately we have to carry the age mask in both, the - * TALER_DenominationPublicKey and - * TALER_DONAUDB_DenominationKeyInformation at different times. - * Here we use _both_ so let's make sure the values are the same. */ - denom_pub.age_mask = issue.age_mask; - TALER_denom_pub_hash (&denom_pub, - &issue.denom_hash); - if (0 != - GNUNET_memcmp (&issue.denom_hash, - &denom_hash)) - { - GNUNET_break (0); - } - else - { - dic->cb (dic->cb_cls, - &denom_pub, - &issue); - } - TALER_denom_pub_free (&denom_pub); - } -} - - -/** - * Fetch information about all known denomination keys. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param cb function to call on each denomination key - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_denomination_info (void *cls, - TALER_DONAUDB_DenominationCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct DenomIteratorContext dic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - - PREPARE (pg, - "denomination_iterate", - "SELECT" - " master_sig" - ",denom_pub_hash" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin" /* value of this denom */ - ",fee_withdraw" - ",fee_deposit" - ",fee_refresh" - ",fee_refund" - ",denom_pub" - ",age_mask" - " FROM denominations;"); - return GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "denomination_iterate", - params, - &domination_cb_helper, - &dic); -} diff --git a/src/donaudb/pg_iterate_denomination_info.h b/src/donaudb/pg_iterate_denomination_info.h @@ -1,41 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_denomination_info.h - * @brief implementation of the iterate_denomination_info function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ITERATE_DENOMINATION_INFO_H -#define PG_ITERATE_DENOMINATION_INFO_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Fetch information about all known denomination keys. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param cb function to call on each denomination key - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_denomination_info (void *cls, - TALER_DONAUDB_DenominationCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_iterate_denominations.c b/src/donaudb/pg_iterate_denominations.c @@ -1,172 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_denominations.c - * @brief Implementation of the iterate_denominations 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_iterate_denominations.h" -#include "pg_helper.h" - - -/** - * Closure for #dominations_cb_helper() - */ -struct DenomsIteratorContext -{ - /** - * Function to call with the results. - */ - TALER_DONAUDB_DenominationsCallback cb; - - /** - * Closure to pass to @e cb - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; -}; - - -/** - * Helper function for #TEH_PG_iterate_denominations(). - * Calls the callback with each denomination key. - * - * @param cls a `struct DenomsIteratorContext` - * @param result db results - * @param num_results number of results in @a result - */ -static void -dominations_cb_helper (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct DenomsIteratorContext *dic = cls; - struct PostgresClosure *pg = dic->pg; - - for (unsigned int i = 0; i<num_results; i++) - { - struct TALER_DONAUDB_DenominationKeyMetaData meta = {0}; - struct TALER_DenominationPublicKey denom_pub = {0}; - struct TALER_MasterSignatureP master_sig = {0}; - struct TALER_DenominationHashP h_denom_pub = {0}; - bool revoked; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("denominations_serial", - &meta.serial), - GNUNET_PQ_result_spec_auto_from_type ("master_sig", - &master_sig), - GNUNET_PQ_result_spec_bool ("revoked", - &revoked), - GNUNET_PQ_result_spec_timestamp ("valid_from", - &meta.start), - GNUNET_PQ_result_spec_timestamp ("expire_withdraw", - &meta.expire_withdraw), - GNUNET_PQ_result_spec_timestamp ("expire_deposit", - &meta.expire_deposit), - GNUNET_PQ_result_spec_timestamp ("expire_legal", - &meta.expire_legal), - TALER_PQ_RESULT_SPEC_AMOUNT ("coin", - &meta.value), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", - &meta.fees.withdraw), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", - &meta.fees.deposit), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", - &meta.fees.refresh), - TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", - &meta.fees.refund), - TALER_PQ_result_spec_denom_pub ("denom_pub", - &denom_pub), - GNUNET_PQ_result_spec_uint32 ("age_mask", - &meta.age_mask.bits), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - return; - } - - /* make sure the mask information is the same */ - denom_pub.age_mask = meta.age_mask; - - TALER_denom_pub_hash (&denom_pub, - &h_denom_pub); - dic->cb (dic->cb_cls, - &denom_pub, - &h_denom_pub, - &meta, - &master_sig, - revoked); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_denominations (void *cls, - TALER_DONAUDB_DenominationsCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_end - }; - struct DenomsIteratorContext dic = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg - }; - - PREPARE (pg, - "select_denominations", - "SELECT" - " denominations_serial" - ",denominations.master_sig" - ",denom_revocations_serial_id IS NOT NULL AS revoked" - ",valid_from" - ",expire_withdraw" - ",expire_deposit" - ",expire_legal" - ",coin" /* value of this denom */ - ",fee_withdraw" - ",fee_deposit" - ",fee_refresh" - ",fee_refund" - ",denom_type" - ",age_mask" - ",denom_pub" - " FROM denominations" - " LEFT JOIN " - " denomination_revocations USING (denominations_serial);"); - return GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "select_denominations", - params, - &dominations_cb_helper, - &dic); -} diff --git a/src/donaudb/pg_iterate_denominations.h b/src/donaudb/pg_iterate_denominations.h @@ -1,44 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_iterate_denominations.h - * @brief implementation of the iterate_denominations function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_ITERATE_DENOMINATIONS_H -#define PG_ITERATE_DENOMINATIONS_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Function called to invoke @a cb on every known denomination key (revoked - * and non-revoked) that has been signed by the master key. Runs in its own - * read-only transaction. - * - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param cb function to call on each denomination key - * @param cb_cls closure for @a cb - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_iterate_denominations (void *cls, - TALER_DONAUDB_DenominationsCallback cb, - void *cb_cls); - -#endif diff --git a/src/donaudb/pg_lookup_signing_key.h b/src/donaudb/pg_lookup_signing_key.h @@ -16,7 +16,7 @@ /** * @file donaudb/pg_lookup_signing_key.h * @brief implementation of the lookup_signing_key function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #ifndef PG_LOOKUP_SIGNING_KEY_H #define PG_LOOKUP_SIGNING_KEY_H diff --git a/src/donaudb/pg_lookup_signkey_revocation.h b/src/donaudb/pg_lookup_signkey_revocation.h @@ -16,7 +16,7 @@ /** * @file donaudb/pg_lookup_signkey_revocation.h * @brief implementation of the lookup_signkey_revocation function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #ifndef PG_LOOKUP_SIGNKEY_REVOCATION_H #define PG_LOOKUP_SIGNKEY_REVOCATION_H @@ -30,13 +30,11 @@ * * @param cls closure * @param donau_pub donau online signing key - * @param[out] master_sig set to signature affirming the revocation (if revoked) * @return transaction status code */ enum GNUNET_DB_QueryStatus TEH_PG_lookup_signkey_revocation ( void *cls, - const struct TALER_DonauPublicKeyP *donau_pub, - struct TALER_MasterSignatureP *master_sig); + const struct TALER_DonauPublicKeyP *donau_pub); #endif diff --git a/src/donaudb/pg_reserves_get.c b/src/donaudb/pg_reserves_get.c @@ -1,61 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_get.c - * @brief Implementation of the reserves_get 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_reserves_get.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_get (void *cls, - struct TALER_DONAUDB_Reserve *reserve) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&reserve->pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_amount ("current_balance", - pg->currency, - &reserve->balance), - GNUNET_PQ_result_spec_timestamp ("expiration_date", - &reserve->expiry), - GNUNET_PQ_result_spec_timestamp ("gc_date", - &reserve->gc), - GNUNET_PQ_result_spec_end - }; - /* Used in #postgres_reserves_get() */ - PREPARE (pg, - "reserves_get", - "SELECT" - " current_balance" - ",expiration_date" - ",gc_date" - " FROM reserves" - " WHERE reserve_pub=$1" - " LIMIT 1;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "reserves_get", - params, - rs); -} diff --git a/src/donaudb/pg_reserves_get.h b/src/donaudb/pg_reserves_get.h @@ -1,40 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_get.h - * @brief implementation of the reserves_get function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_RESERVES_GET_H -#define PG_RESERVES_GET_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Get the summary of a reserve. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param[in,out] reserve the reserve data. The public key of the reserve should be - * set in this structure; it is used to query the database. The balance - * and expiration are then filled accordingly. - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_get (void *cls, - struct TALER_DONAUDB_Reserve *reserve); - -#endif diff --git a/src/donaudb/pg_reserves_get_origin.c b/src/donaudb/pg_reserves_get_origin.c @@ -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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_get_origin.c - * @brief Implementation of the reserves_get_origin 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_reserves_get_origin.h" -#include "pg_helper.h" - - -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_get_origin ( - void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_PaytoHashP *h_payto) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (reserve_pub), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("wire_source_h_payto", - h_payto), - GNUNET_PQ_result_spec_end - }; - - - PREPARE (pg, - "get_h_wire_source_of_reserve", - "SELECT" - " wire_source_h_payto" - " FROM reserves_in" - " WHERE reserve_pub=$1"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "get_h_wire_source_of_reserve", - params, - rs); -} diff --git a/src/donaudb/pg_reserves_get_origin.h b/src/donaudb/pg_reserves_get_origin.h @@ -1,41 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_get_origin.h - * @brief implementation of the reserves_get_origin function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_RESERVES_GET_ORIGIN_H -#define PG_RESERVES_GET_ORIGIN_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" -/** - * Get the origin of funds of a reserve. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param reserve_pub public key of the reserve - * @param[out] h_payto set to hash of the wire source payto://-URI - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_get_origin ( - void *cls, - const struct TALER_ReservePublicKeyP *reserve_pub, - struct TALER_PaytoHashP *h_payto); - -#endif diff --git a/src/donaudb/pg_reserves_in_insert.c b/src/donaudb/pg_reserves_in_insert.c @@ -1,372 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_in_insert.c - * @brief Implementation of the reserves_in_insert function for Postgres - * @author Christian Grothoff - * @author Joseph Xu - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_reserves_in_insert.h" -#include "pg_helper.h" -#include "pg_start.h" -#include "pg_start_read_committed.h" -#include "pg_commit.h" -#include "pg_preflight.h" -#include "pg_rollback.h" -#include "pg_reserves_get.h" -#include "pg_reserves_update.h" -#include "pg_setup_wire_target.h" -#include "pg_event_notify.h" - - -/** - * Generate event notification for the reserve change. - * - * @param reserve_pub reserve to notfiy on - * @return string to pass to postgres for the notification - */ -static char * -compute_notify_on_reserve (const struct TALER_ReservePublicKeyP *reserve_pub) -{ - struct TALER_ReserveEventP rep = { - .header.size = htons (sizeof (rep)), - .header.type = htons (TALER_DBEVENT_DONAU_RESERVE_INCOMING), - .reserve_pub = *reserve_pub - }; - - return GNUNET_PG_get_event_notify_channel (&rep.header); -} - - -/** - * Closure for our helper_cb() - */ -struct Context -{ - /** - * Array of reserve UUIDs to initialize. - */ - uint64_t *reserve_uuids; - - /** - * Array with entries set to 'true' for duplicate transactions. - */ - bool *transaction_duplicates; - - /** - * Array with entries set to 'true' for rows with conflicts. - */ - bool *conflicts; - - /** - * Set to #GNUNET_SYSERR on failures. - */ - enum GNUNET_GenericReturnValue status; - - /** - * Single value (no array) set to true if we need - * to follow-up with an update. - */ - bool needs_update; -}; - - -/** - * 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 Context *` - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -helper_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct Context *ctx = cls; - - for (unsigned int i = 0; i<num_results; i++) - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ( - "transaction_duplicate", - &ctx->transaction_duplicates[i]), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint64 ("ruuid", - &ctx->reserve_uuids[i]), - &ctx->conflicts[i]), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->status = GNUNET_SYSERR; - return; - } - if (! ctx->transaction_duplicates[i]) - ctx->needs_update |= ctx->conflicts[i]; - } -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_in_insert ( - void *cls, - const struct TALER_DONAUDB_ReserveInInfo *reserves, - unsigned int reserves_length, - enum GNUNET_DB_QueryStatus *results) -{ - struct PostgresClosure *pg = cls; - unsigned int dups = 0; - - struct TALER_PaytoHashP h_paytos[GNUNET_NZL (reserves_length)]; - char *notify_s[GNUNET_NZL (reserves_length)]; - struct TALER_ReservePublicKeyP reserve_pubs[GNUNET_NZL (reserves_length)]; - struct TALER_Amount balances[GNUNET_NZL (reserves_length)]; - struct GNUNET_TIME_Timestamp execution_times[GNUNET_NZL (reserves_length)]; - const char *sender_account_details[GNUNET_NZL (reserves_length)]; - const char *donau_account_names[GNUNET_NZL (reserves_length)]; - uint64_t wire_references[GNUNET_NZL (reserves_length)]; - uint64_t reserve_uuids[GNUNET_NZL (reserves_length)]; - bool transaction_duplicates[GNUNET_NZL (reserves_length)]; - bool conflicts[GNUNET_NZL (reserves_length)]; - struct GNUNET_TIME_Timestamp reserve_expiration - = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); - struct GNUNET_TIME_Timestamp gc - = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time); - enum GNUNET_DB_QueryStatus qs; - bool need_update; - - for (unsigned int i = 0; i<reserves_length; i++) - { - const struct TALER_DONAUDB_ReserveInInfo *reserve = &reserves[i]; - - TALER_payto_hash (reserve->sender_account_details, - &h_paytos[i]); - notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub); - reserve_pubs[i] = *reserve->reserve_pub; - balances[i] = *reserve->balance; - execution_times[i] = reserve->execution_time; - sender_account_details[i] = reserve->sender_account_details; - donau_account_names[i] = reserve->donau_account_name; - wire_references[i] = reserve->wire_reference; - } - - /* NOTE: kind-of pointless to explicitly start a transaction here... */ - if (GNUNET_OK != - TEH_PG_preflight (pg)) - { - GNUNET_break (0); - qs = GNUNET_DB_STATUS_HARD_ERROR; - goto finished; - } - if (GNUNET_OK != - TEH_PG_start_read_committed (pg, - "READ_COMMITED")) - { - GNUNET_break (0); - qs = GNUNET_DB_STATUS_HARD_ERROR; - goto finished; - } - PREPARE (pg, - "reserves_insert_with_array", - "SELECT" - " transaction_duplicate" - ",ruuid" - " FROM donau_do_array_reserves_insert" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);"); - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&gc), - GNUNET_PQ_query_param_timestamp (&reserve_expiration), - GNUNET_PQ_query_param_array_auto_from_type (reserves_length, - reserve_pubs, - pg->conn), - GNUNET_PQ_query_param_array_uint64 (reserves_length, - wire_references, - pg->conn), - TALER_PQ_query_param_array_amount ( - reserves_length, - balances, - pg->conn), - GNUNET_PQ_query_param_array_ptrs_string ( - reserves_length, - (const char **) donau_account_names, - pg->conn), - GNUNET_PQ_query_param_array_timestamp ( - reserves_length, - execution_times, - pg->conn), - GNUNET_PQ_query_param_array_auto_from_type ( - reserves_length, - h_paytos, - pg->conn), - GNUNET_PQ_query_param_array_ptrs_string ( - reserves_length, - (const char **) sender_account_details, - pg->conn), - GNUNET_PQ_query_param_array_ptrs_string ( - reserves_length, - (const char **) notify_s, - pg->conn), - GNUNET_PQ_query_param_end - }; - struct Context ctx = { - .reserve_uuids = reserve_uuids, - .transaction_duplicates = transaction_duplicates, - .conflicts = conflicts, - .needs_update = false, - .status = GNUNET_OK - }; - - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - "reserves_insert_with_array", - params, - &helper_cb, - &ctx); - if ( (qs < 0) || - (GNUNET_OK != ctx.status) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to insert into reserves (%d)\n", - qs); - goto finished; - } - need_update = ctx.needs_update; - } - - { - enum GNUNET_DB_QueryStatus cs; - - cs = TEH_PG_commit (pg); - if (cs < 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit\n"); - qs = cs; - goto finished; - } - } - - for (unsigned int i = 0; i<reserves_length; i++) - { - if (transaction_duplicates[i]) - dups++; - results[i] = transaction_duplicates[i] - ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS - : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - } - - if (! need_update) - { - qs = reserves_length; - goto finished; - } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve update needed for some reserves in the batch\n"); - PREPARE (pg, - "reserves_update", - "SELECT" - " out_duplicate AS duplicate " - "FROM donau_do_batch_reserves_update" - " ($1,$2,$3,$4,$5,$6,$7);"); - - if (GNUNET_OK != - TEH_PG_start (pg, - "reserve-insert-continued")) - { - GNUNET_break (0); - qs = GNUNET_DB_STATUS_HARD_ERROR; - goto finished; - } - - for (unsigned int i = 0; i<reserves_length; i++) - { - if (transaction_duplicates[i]) - continue; - if (! conflicts[i]) - continue; - { - bool duplicate; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (&reserve_pubs[i]), - GNUNET_PQ_query_param_timestamp (&reserve_expiration), - GNUNET_PQ_query_param_uint64 (&wire_references[i]), - TALER_PQ_query_param_amount (pg->conn, - &balances[i]), - GNUNET_PQ_query_param_string (donau_account_names[i]), - GNUNET_PQ_query_param_auto_from_type (&h_paytos[i]), - GNUNET_PQ_query_param_string (notify_s[i]), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_bool ("duplicate", - &duplicate), - GNUNET_PQ_result_spec_end - }; - enum GNUNET_DB_QueryStatus qs; - - qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "reserves_update", - params, - rs); - if (qs < 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to update reserves (%d)\n", - qs); - results[i] = qs; - goto finished; - } - results[i] = duplicate - ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS - : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; - } - } - { - enum GNUNET_DB_QueryStatus cs; - - cs = TEH_PG_commit (pg); - if (cs < 0) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit\n"); - qs = cs; - goto finished; - } - } -finished: - for (unsigned int i = 0; i<reserves_length; i++) - GNUNET_free (notify_s[i]); - if (qs < 0) - return qs; - GNUNET_PQ_event_do_poll (pg->conn); - if (0 != dups) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "%u/%u duplicates among incoming transactions. Try increasing WIREWATCH_IDLE_SLEEP_INTERVAL in the [donau] configuration section (if this happens a lot).\n", - dups, - reserves_length); - return qs; -} diff --git a/src/donaudb/pg_reserves_in_insert.h b/src/donaudb/pg_reserves_in_insert.h @@ -1,47 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_in_insert.h - * @brief implementation of the reserves_in_insert function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_RESERVES_IN_INSERT_H -#define PG_RESERVES_IN_INSERT_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - - -/** - * Insert an incoming transaction into reserves. New reserves are also - * created through this function. Runs its own transaction(s). - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param reserves array of reserves to insert - * @param reserves_length length of the @a reserves array - * @param[out] results set to query status per reserve, must be of length @a reserves_length - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_in_insert ( - void *cls, - const struct TALER_DONAUDB_ReserveInInfo *reserves, - unsigned int reserves_length, - enum GNUNET_DB_QueryStatus *results); - - -#endif diff --git a/src/donaudb/pg_reserves_update.c b/src/donaudb/pg_reserves_update.c @@ -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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_update.c - * @brief Implementation of the reserves_update 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_reserves_update.h" -#include "pg_helper.h" - -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_update (void *cls, - const struct TALER_DONAUDB_Reserve *reserve) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_timestamp (&reserve->expiry), - GNUNET_PQ_query_param_timestamp (&reserve->gc), - TALER_PQ_query_param_amount (pg->conn, - &reserve->balance), - GNUNET_PQ_query_param_auto_from_type (&reserve->pub), - GNUNET_PQ_query_param_end - }; - - PREPARE (pg, - "reserve_update", - "UPDATE reserves" - " SET" - " expiration_date=$1" - ",gc_date=$2" - ",current_balance=$3" - " WHERE reserve_pub=$4;"); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "reserve_update", - params); -} diff --git a/src/donaudb/pg_reserves_update.h b/src/donaudb/pg_reserves_update.h @@ -1,40 +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 CHARITYABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_reserves_update.h - * @brief implementation of the reserves_update function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_RESERVES_UPDATE_H -#define PG_RESERVES_UPDATE_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_donaudb_plugin.h" - -/** - * Updates a reserve with the data from the given reserve structure. - * - * @param cls the `struct PostgresClosure` with the plugin-specific state - * @param reserve the reserve structure whose data will be used to update the - * corresponding record in the database. - * @return transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_reserves_update (void *cls, - const struct TALER_DONAUDB_Reserve *reserve); - -#endif diff --git a/src/include/taler_donaudb_plugin.h b/src/include/taler_donaudb_plugin.h @@ -33,11 +33,6 @@ struct TALER_DONAUDB_DonationUnitKeyInformation { /** - * Serial of the donation unit key as in the DB. - */ - uint64_t serial; - - /** * The value of the donation unit. */ struct TALER_Amount value;