donau

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

commit 643382a495b21acb62cd0c459a0098f95846075e
parent dfeb76c9f3e09bd2f322cd47f7fcbc9c17c2f0bf
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 23 Apr 2024 16:49:43 +0200

merge2

Diffstat:
Msrc/donau/donau-httpd_batch-submit.c | 99++++++++++++++++++-------------------------------------------------------------
Msrc/donaudb/0002-donau_receipts_submitted.sql | 4++--
Msrc/donaudb/Makefile.am | 2+-
Dsrc/donaudb/donau_do_gc.sql | 31-------------------------------
Asrc/donaudb/donau_do_insert_submitted_receipts.sql | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/pg_insert_submitted_receipt.c | 59-----------------------------------------------------------
Dsrc/donaudb/pg_insert_submitted_receipt.h | 50--------------------------------------------------
Asrc/donaudb/pg_insert_submitted_receipts.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/donaudb/pg_insert_submitted_receipts.h | 47+++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/plugin_donaudb_postgres.c | 17+++--------------
Msrc/include/donaudb_plugin.h | 5++---
11 files changed, 225 insertions(+), 237 deletions(-)

diff --git a/src/donau/donau-httpd_batch-submit.c b/src/donau/donau-httpd_batch-submit.c @@ -34,12 +34,12 @@ /** - * Closure for #insert_submitted_receipt() + * Closure for #insert_submitted_receipts() */ struct InsertReceiptContext { struct DONAU_HashDonorTaxId *h_tax_number; - struct DONAU_DonationReceipt *donation_receipt; + struct DONAU_DonationReceipt *donation_receipts; uint64_t donation_year; }; @@ -78,54 +78,6 @@ parse_json_dr (struct DONAU_DonationReceipt *dr, } -/** - * Function implementing insert submit-receipt transaction. - * - * Runs the transaction logic; IF it returns a non-error code, the - * transaction logic MUST NOT queue a MHD response. IF it returns an hard - * error, the transaction logic MUST queue a MHD response and set @a mhd_ret. - * IF it returns the soft error code, the function MAY be called again to - * retry and MUST not queue a MHD response. - * - * @param cls closure with a `struct InsertReceiptContext` - * @param connection MHD request which triggered the transaction - * @param[out] mhd_ret set to MHD response status for @a connection, - * if transaction failed (!) - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -insert_submitted_receipt (void *cls, - struct MHD_Connection *connection, - MHD_RESULT *mhd_ret) -{ - struct InsertReceiptContext *irc = cls; - enum GNUNET_DB_QueryStatus qs; - - qs = DH_plugin->insert_submitted_receipt (DH_plugin->cls, - irc->h_tax_number, - irc->donation_receipt->nonce, - &irc->donation_receipt-> - h_donation_unit_pub, // FIXME - &irc->donation_receipt->donau_sig, - irc->donation_year); - if (qs <= 0) - { - if (GNUNET_DB_STATUS_SOFT_ERROR != qs) - { - GNUNET_break (0); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "insert_submitted_receipt"); - return GNUNET_DB_STATUS_HARD_ERROR; - } - return qs; - } - - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; -} - - MHD_RESULT DH_handler_submit_receipts_post (struct DH_RequestContext *rc, const json_t *root, @@ -161,7 +113,6 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, /* parse the donation receipts */ const size_t num_dr = json_array_size (donation_receipts); - struct DONAU_DonationReceipt *dr_arr; if (0 == num_dr) { @@ -176,13 +127,13 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, json_t *dr_obj; size_t index; - dr_arr = GNUNET_new_array (num_dr, - struct DONAU_DonationReceipt); + irc.donation_receipts = GNUNET_new_array (num_dr, + struct DONAU_DonationReceipt); json_array_foreach (donation_receipts, index, dr_obj) { if (GNUNET_SYSERR == - parse_json_dr (&dr_arr[index], dr_obj)) + parse_json_dr (&irc.donation_receipts[index], dr_obj)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (rc->connection, @@ -198,36 +149,30 @@ DH_handler_submit_receipts_post (struct DH_RequestContext *rc, // FIXME Check sigs, Donation unit hashes, nonce } - MHD_RESULT mhd_ret; + enum GNUNET_DB_QueryStatus qs; - for (size_t i = 0; i < num_dr; i++) + qs = DH_plugin->insert_submitted_receipts ( + DH_plugin->cls, + irc.h_tax_number, + irc.donation_receipts, + num_dr, + irc.donation_year); + + if (qs < 0) { - // FIXME - struct InsertReceiptContext irc = { - .donation_receipt = &dr_arr[i] - }; - - if (GNUNET_OK != - DH_DB_run_transaction (rc->connection, - "insert_submitted_receipt", - DH_MT_REQUEST_OTHER, - &mhd_ret, - &insert_submitted_receipt, - &irc)) - { - return mhd_ret; - } + GNUNET_break (0); + // FIXME change error message + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "donation_receipts"); } // FIXME create donation statement // Send back DS - return TALER_MHD_reply_static ( - rc->connection, - MHD_HTTP_NO_CONTENT, - NULL, - NULL, - 0); + // FIXME + return MHD_HTTP_OK; } diff --git a/src/donaudb/0002-donau_receipts_submitted.sql b/src/donaudb/0002-donau_receipts_submitted.sql @@ -16,7 +16,7 @@ CREATE TABLE receipts_submitted (receipt_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE - ,hash_tax_number BYTEA NOT NULL + ,h_tax_number BYTEA NOT NULL ,nonce BYTEA NOT NULL UNIQUE CHECK (LENGTH(nonce)=32) ,donation_unit_pub BYTEA NOT NULL REFERENCES donation_units (donation_unit_pub) ,donau_sig BYTEA NOT NULL UNIQUE @@ -24,7 +24,7 @@ CREATE TABLE receipts_submitted ); COMMENT ON TABLE receipts_submitted IS 'Table containing information of the donation receips submitted from the donor.'; -COMMENT ON COLUMN receipts_submitted.hash_tax_number +COMMENT ON COLUMN receipts_submitted.h_tax_number IS 'The hash of the tax number and salt.'; COMMENT ON COLUMN receipts_submitted.donation_unit_pub IS 'Reference to public key used to sign.'; diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -91,7 +91,7 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \ pg_lookup_charity.h pg_lookup_charity.c \ pg_lookup_issued_receipts.h pg_lookup_issued_receipts.c \ pg_insert_issued_receipt.h pg_insert_issued_receipt.c \ - pg_insert_submitted_receipt.h pg_insert_submitted_receipt.c + pg_insert_submitted_receipts.h pg_insert_submitted_receipts.c libtaler_plugin_donaudb_postgres_la_LIBADD = \ diff --git a/src/donaudb/donau_do_gc.sql b/src/donaudb/donau_do_gc.sql @@ -1,31 +0,0 @@ --- --- This file is part of TALER --- Copyright (C) 2014--2022 Taler Systems SA --- --- TALER is free software; you can redistribute it and/or modify it under the --- terms of the GNU General Public License as published by the Free Software --- Foundation; either version 3, or (at your option) any later version. --- --- TALER is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR --- A PARTICULAR PURPOSE. See the GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License along with --- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> --- - -CREATE OR REPLACE PROCEDURE donau_do_gc( - IN in_ancient_date INT8, - IN in_now INT8) -LANGUAGE plpgsql -AS $$ -DECLARE - reserve_uuid_min INT8; -- minimum reserve UUID still alive - melt_min INT8; -- minimum melt still alive - coin_min INT8; -- minimum known_coin still alive - batch_deposit_min INT8; -- minimum deposit still alive - reserve_out_min INT8; -- minimum reserve_out still alive - denom_min INT8; -- minimum denomination still alive -BEGIN - -END $$; diff --git a/src/donaudb/donau_do_insert_submitted_receipts.sql b/src/donaudb/donau_do_insert_submitted_receipts.sql @@ -0,0 +1,68 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2024 Taler Systems SA +-- +-- TALER is free software; you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software +-- Foundation; either version 3, or (at your option) any later version. +-- +-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY +-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +-- A PARTICULAR PURPOSE. See the GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- +CREATE OR REPLACE FUNCTION donau_do_insert_submitted_receiptss( + IN in_h_tax_number BYTEA, + IN ina_h_donation_unit_pubs BYTEA[], + IN ina_nonces BYTEA[], + IN ina_donau_sigs BYTEA[], + IN in_dontation_year INT8, + -- + OUT out_conflict BOOL + ) +LANGUAGE plpgsql +AS $$ +DECLARE + i INT4; + ini_nonce BYTEA; + ini_h_donation_unit_pub BYTEA; + ini_donau_sig BYTEA; +BEGIN + +out_conflict=FALSE; + +-- Insert each donation receipt + +FOR i IN 1..array_length(ina_h_donation_unit_pubs,1) +LOOP + ini_nonce = ina_nonces[i]; + ini_h_donation_unit_pub = ina_h_donation_unit_pubs[i]; + ini_donau_sig = ina_donau_sigs[i]; + + INSERT INTO receipts_submitted + (h_tax_number + ,nonce + ,donation_unit_pub + ,donau_sig + ,donation_year + ) + VALUES + (in_h_tax_number + ,ini_nonce + ,ini_h_donation_unit_pub + ,ini_donau_sig + ,in_donation_year + ) + ON CONFLICT DO NOTHING; + + + IF NOT FOUND + THEN + -- FIXME + RETURN; + END IF; +END LOOP; -- end FOR all coins + +END $$; diff --git a/src/donaudb/pg_insert_submitted_receipt.c b/src/donaudb/pg_insert_submitted_receipt.c @@ -1,59 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/pg_insert_issed_receipt.c - * @brief Implementation of the insert_submitted_receipt function for Postgres - * @author Johannes Casaburi - */ -#include <taler/platform.h> -#include <taler/taler_error_codes.h> -#include <taler/taler_dbevents.h> -#include <taler/taler_pq_lib.h> -#include "pg_insert_submitted_receipt.h" -#include "pg_helper.h" -#include "donau_service.h" - -enum GNUNET_DB_QueryStatus -DH_PG_insert_submitted_receipt ( - void *cls, - const struct DONAU_HashDonorTaxId *h_tax_number, - const union GNUNET_CRYPTO_BlindSessionNonce *nonce, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const struct DONAU_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 - }; - - 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 @@ -1,50 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2023 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -/** - * @file donaudb/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/taler_util.h> -#include <taler/taler_json_lib.h> -#include "donaudb_plugin.h" -#include "donau_service.h" - -/** - * Insert submitted donation receipt from the donor. - * - * @param cls closure - * @param h_tax_number salted hash of the donors tax number - * @param nonce nonce that is part of the unique donation identifier - * @param donation_unit_pub donation unit public key - * @param donau_sig donau signature in case the sign keys changed - * @param donation_year year of the donation - * @return transaction status code - */ -enum GNUNET_DB_QueryStatus -DH_PG_insert_submitted_receipt ( - void *cls, - const struct DONAU_HashDonorTaxId *h_tax_number, - const union GNUNET_CRYPTO_BlindSessionNonce *nonce, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const struct DONAU_DonauSignatureP *donau_sig, - const uint64_t donation_year - ); - -#endif diff --git a/src/donaudb/pg_insert_submitted_receipts.c b/src/donaudb/pg_insert_submitted_receipts.c @@ -0,0 +1,80 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_insert_issed_receipt.c + * @brief Implementation of the insert_submitted_receipts function for Postgres + * @author Johannes Casaburi + */ +#include <taler/platform.h> +#include <taler/taler_error_codes.h> +#include <taler/taler_dbevents.h> +#include <taler/taler_pq_lib.h> +#include "pg_insert_submitted_receipts.h" +#include "pg_helper.h" +#include "donau_service.h" + +enum GNUNET_DB_QueryStatus +DH_PG_insert_submitted_receipts ( + void *cls, + const struct DONAU_HashDonorTaxId *h_tax_number, + const struct DONAU_DonationReceipt *donation_receipts, + const size_t num_dr, + const uint64_t donation_year) +{ + struct PostgresClosure *pg = cls; + + struct DONAU_DonationUnitHashP *h_donation_unit_pubs; + union GNUNET_CRYPTO_BlindSessionNonce *nonces; + struct DONAU_DonauSignatureP *donau_sigs; + + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (h_tax_number), + GNUNET_PQ_query_param_array_ptrs_auto_from_type (num_dr, + &h_donation_unit_pubs, + pg->conn), + GNUNET_PQ_query_param_array_ptrs_auto_from_type (num_dr, + &nonces, + pg->conn), + GNUNET_PQ_query_param_array_ptrs_auto_from_type (num_dr, + &donau_sigs, + pg->conn), + GNUNET_PQ_query_param_uint64 (&donation_year), + GNUNET_PQ_query_param_end + }; + + for (unsigned int i = 0; i < num_dr; i++) + { + const struct DONAU_DonationReceipt *dr = &donation_receipts[i]; + + h_donation_unit_pubs[i] = dr->h_donation_unit_pub; + nonces[i] = *dr->nonce; + donau_sigs[i] = dr->donau_sig; + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Do insert submitted receipt\n"); + } + + PREPARE (pg, + "call_insert_submitted_receipts", + "SELECT " + " out_conflict AS conflicted" + " FROM do_insert_submitted_receipts" + " ($1,$2,$3,$4,$5);"); + + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "call_insert_submitted_receipts", + params); +} diff --git a/src/donaudb/pg_insert_submitted_receipts.h b/src/donaudb/pg_insert_submitted_receipts.h @@ -0,0 +1,47 @@ +/* + This file is part of TALER + Copyright (C) 2023 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file donaudb/pg_insert_submitted_receipts.h + * @brief implementation of the insert_submitted_receipts function for Postgres + * @author Johannes Casaburi + */ +#ifndef PG_INSERT_SUBMITTED_RECEIPT_H +#define PG_INSERT_SUBMITTED_RECEIPT_H + +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "donaudb_plugin.h" +#include "donau_service.h" + +/** + * Insert submitted donation receipt from the donor. + * + * @param cls closure + * @param h_tax_number salted hash of the donors tax number + * @param donation_receipts array of donation receipts + * @param donation_year year of the donation + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +DH_PG_insert_submitted_receipts ( + void *cls, + const struct DONAU_HashDonorTaxId *h_tax_number, + const struct DONAU_DonationReceipt *donation_receipts, + const size_t num_dr, + const uint64_t donation_year + ); + +#endif diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -44,7 +44,7 @@ #include "pg_insert_history_entry.h" #include "pg_get_history.h" #include "pg_insert_issued_receipt.h" -#include "pg_insert_submitted_receipt.h" +#include "pg_insert_submitted_receipts.h" #include "pg_insert_signing_key.h" #include "pg_iterate_active_signing_keys.h" #include "pg_lookup_signing_key.h" @@ -206,10 +206,6 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_commit; plugin->preflight = &DH_PG_preflight; - // plugin->start_read_committed - // = &DH_PG_start_read_committed; - // plugin->start_read_only - // = &DH_PG_start_read_only; plugin->start = &DH_PG_start; plugin->rollback @@ -222,13 +218,6 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_event_listen_cancel; plugin->event_notify = &DH_PG_event_notify; - // plugin->get_policy_details - // = &DH_PG_get_policy_details; - // plugin->persist_policy_details - // = &DH_PG_persist_policy_details; - // plugin->gc - // = &DH_PG_gc; - plugin->insert_donation_unit = &DH_PG_insert_donation_unit; plugin->iterate_donation_units @@ -241,8 +230,8 @@ libtaler_plugin_donaudb_postgres_init (void *cls) = &DH_PG_insert_issued_receipt; plugin->lookup_issued_receipts = &DH_PG_lookup_issued_receipts; - plugin->insert_submitted_receipt - = &DH_PG_insert_submitted_receipt; + plugin->insert_submitted_receipts + = &DH_PG_insert_submitted_receipts; plugin->insert_signing_key = &DH_PG_insert_signing_key; plugin->lookup_signing_key diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -530,9 +530,8 @@ struct DONAUDB_Plugin (*insert_submitted_receipt)( void *cls, const struct DONAU_HashDonorTaxId *h_tax_number, - const union GNUNET_CRYPTO_BlindSessionNonce *nonce, - const struct DONAU_DonationUnitPublicKey *donation_unit_pub, - const struct DONAU_DonauSignatureP *donau_sig, + const struct DONAU_DonationReceipt *donation_receipts, + const size_t num_dr, const uint64_t donation_year); /**