donau

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

commit 2c88077c75c7fd1e944eb61f02db9be50de473ed
parent 5cdbbc8cfee68320e0d09d4df4ff47221aafbd38
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Mon, 23 Oct 2023 23:30:22 +0200

[db] added pg transactions

Diffstat:
Msrc/donaudb/pg_add_donation_unit_key.h | 8++++----
Msrc/donaudb/pg_insert_charity.c | 2+-
Asrc/donaudb/pg_insert_history_entry.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_history_entry.h | 44++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_issued_receipt.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_issued_receipt.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_submitted_receipt.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_submitted_receipt.h | 46++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 309 insertions(+), 5 deletions(-)

diff --git a/src/donaudb/pg_add_donation_unit_key.h b/src/donaudb/pg_add_donation_unit_key.h @@ -14,8 +14,8 @@ 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 + * @file donaudb/pg_add_donation_unit_key.h + * @brief implementation of the add_donation_unit_key function for Postgres * @author Johannes Casaburi */ #ifndef PG_ADD_DONATION_UNIT_KEY_H @@ -37,6 +37,6 @@ enum GNUNET_DB_QueryStatus TEH_PG_add_donation_unit_key ( void *cls, - const struct TALER_DenominationPublicKey *denom_pub, - const struct TALER_DONAUDB_DenominationKeyMetaInfo *meta) + const struct TALER_DonationUnitPublicKey *donation_unit_pub, + const struct TALER_DONAUDB_DonationUnitKeyMetaInfo *meta) #endif diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c @@ -16,7 +16,7 @@ /** * @file exchangedb/pg_insert_charity.c * @brief Implementation of the insert_charity function for Postgres - * @author Christian Grothoff + * @author Johannes Casaburi */ #include "platform.h" #include "taler_error_codes.h" diff --git a/src/donaudb/pg_insert_history_entry.c b/src/donaudb/pg_insert_history_entry.c @@ -0,0 +1,54 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_insert_history_entry.c + * @brief Implementation of the insert_history_entry function for Postgres + * @author Johannes Casaburi + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_insert_history_entry.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TEH_PG_insert_history_entry (void *cls, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (charity_id), + GNUNET_PQ_query_param_amount (final_amount), + GNUNET_PQ_query_param_uint64 (donation_year), + GNUNET_PQ_query_param_end + }; + + /* used in #postgres_insert_history_entry() */ + PREPARE (pg, + "insert_history_entry", + "INSERT INTO history " + "(charity_id" + ",final_amount" + ",donation_year" + ") VALUES " + "($1, $2, $3);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_history_entry", + params); +} diff --git a/src/donaudb/pg_insert_history_entry.h b/src/donaudb/pg_insert_history_entry.h @@ -0,0 +1,44 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_insert_history_entry.h + * @brief implementation of the insert_history_entry function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_INSERT_HISTORY_ENTRY_H +#define PG_INSERT_HISTORY_ENTRY_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_donaudb_plugin.h" + +/** + * Insert information about an auditor that will audit this exchange. + * + * @param cls closure + * @param auditor_pub key of the auditor + * @param auditor_url base URL of the auditor's REST service + * @param auditor_name name of the auditor (for humans) + * @param start_date date when the auditor was added by the offline system + * (only to be used for replay detection) + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_insert_history_entry (void *cls, + const uint64_t charity_id, + const struct TALER_Amount *final_amount, + const uint64_t donation_year); +#endif diff --git a/src/donaudb/pg_insert_issued_receipt.c b/src/donaudb/pg_insert_issued_receipt.c @@ -0,0 +1,57 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_insert_issed_receipt.c + * @brief Implementation of the insert_issued_receipt function for Postgres + * @author Johannes Casaburi + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_insert_issued_receipt.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TEH_PG_insert_issued_receipt (void *cls, + const struct TALER_CharitySignatureP *charity_sig, + const uint64_t charity_id, + const struct TALER_DonationReceiptHashP h_receipt, + const struct TALER_Amount *amount) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (charity_sig), + GNUNET_PQ_query_param_uint64 (charity_id), + GNUNET_PQ_query_param_auto_from_type (h_receipt), + GNUNET_PQ_query_param_amount (amount), + GNUNET_PQ_query_param_end + }; + + /* used in #postgres_insert_issued_receipt() */ + PREPARE (pg, + "insert_issued_receipts", + "INSERT INTO receipts_issued " + "(charity_sig" + ",charity_id" + ",h_receipt" + ",amount" + ") VALUES " + "($1, $2, $3, $4);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_issued_receipt", + params); +} diff --git a/src/donaudb/pg_insert_issued_receipt.h b/src/donaudb/pg_insert_issued_receipt.h @@ -0,0 +1,45 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_insert_issued_receipt.h + * @brief implementation of the insert_issued_receipt function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_INSERT_ISSUED_RECEIPT_H +#define PG_INSERT_ISSUED_RECEIPT_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_donaudb_plugin.h" + +/** + * Insert information about an auditor that will audit this exchange. + * + * @param cls closure + * @param auditor_pub key of the auditor + * @param auditor_url base URL of the auditor's REST service + * @param auditor_name name of the auditor (for humans) + * @param start_date date when the auditor was added by the offline system + * (only to be used for replay detection) + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_insert_auditor (void *cls, + const struct TALER_CharitySignatureP *charity_sig, + const uint64_t charity_id, + const struct TALER_DonationReceiptHashP *h_receipt, + const struct TALER_Amount *amount); +#endif diff --git a/src/donaudb/pg_insert_submitted_receipt.c b/src/donaudb/pg_insert_submitted_receipt.c @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_insert_issed_receipt.c + * @brief Implementation of the insert_submitted_receipt function for Postgres + * @author Johannes Casaburi + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_insert_submitted_receipt.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TEH_PG_insert_submitted_receipt (void *cls, + const struct TALER_TaxNumberHashP *h_tax_number, + const struct TALER_CsNonce *nonce, + const struct TALER_DonationUnitPublicKey *donation_unit_pub, + const struct TALER_DonauSignatureP *donau_sig, + const uint64_t donation_year) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_tax_number), + GNUNET_PQ_query_param_auto_from_type (nonce), + GNUNET_PQ_query_param_auto_from_type (donau_sig), + GNUNET_PQ_query_param_uint64 (donation_year), + GNUNET_PQ_query_param_end + }; + + /* used in #postgres_insert_submitted_receipt() */ + PREPARE (pg, + "insert_submitted_receipt", + "INSERT INTO receipts_submitted " + "(h_tax_number" + ",nonce" + ",donau_sig" + ",donation_year" + ") VALUES " + "($1, $2, $3, $4);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_submitted_receipt", + params); +} diff --git a/src/donaudb/pg_insert_submitted_receipt.h b/src/donaudb/pg_insert_submitted_receipt.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_insert_submitted_receipt.h + * @brief implementation of the insert_submitted_receipt function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_INSERT_SUBMITTED_RECEIPT_H +#define PG_INSERT_SUBMITTED_RECEIPT_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_donaudb_plugin.h" + +/** + * Insert information about an auditor that will audit this exchange. + * + * @param cls closure + * @param auditor_pub key of the auditor + * @param auditor_url base URL of the auditor's REST service + * @param auditor_name name of the auditor (for humans) + * @param start_date date when the auditor was added by the offline system + * (only to be used for replay detection) + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +TEH_PG_insert_submitted_receipt (void *cls, + const struct TALER_TaxNumberHashP *h_tax_number, + const struct TALER_CsNonce *nonce, + const struct TALER_DonationUnitPublicKey *donation_unit_pub, + const struct TALER_DonauSignatureP *donau_sig, + const uint64_t donation_year); +#endif