donau

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

commit f4d80b5ddc929aeacb428d66741482e0dbcb1a89
parent dd8924ceb8ed5abe219eb9763d0fd2ffb6bcf7fb
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Wed, 24 Apr 2024 12:24:31 +0200

rename sql file

Diffstat:
Asrc/donaudb/donau_do_insert_issued_receipts.sql | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donaudb/donau_do_save_issue_receipts_request.sql | 64----------------------------------------------------------------
Msrc/donaudb/pg_insert_issued_receipt.c | 2+-
Msrc/donaudb/procedures.sql.in | 3++-
4 files changed, 67 insertions(+), 66 deletions(-)

diff --git a/src/donaudb/donau_do_insert_issued_receipts.sql b/src/donaudb/donau_do_insert_issued_receipts.sql @@ -0,0 +1,64 @@ +-- +-- 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 do_insert_issued_receipts ( + IN in_charity_id BIGINT -- charity id which made the issue receitps request + --,IN in_blinded_sig BYTEA[] -- blinded signatures + ,IN in_receipt_hash BYTEA -- hash over all budi key pairs (primary key) + ,IN in_amount taler_amount -- total amount of the requested receipts + ,OUT out_smaller_than_max_per_year BOOLEAN +) +LANGUAGE plpgsql +AS $$ +DECLARE + new_receipts_to_date taler_amount; + may_per_year taler_amount; + tmp taler_amount; +BEGIN + -- Get charity values + SELECT + (chari.receipts_to_date).val + ,(chari.receipts_to_date).frac + ,(chari.max_per_year).val + ,(chari.max_per_year).frac + INTO + new_receipts_to_date.val + ,new_receipts_to_date.frac + ,may_per_year.val + ,may_per_year.frac + FROM charities chari + WHERE charity_id=in_charity_id; + -- calculate sum of the recent amount of receipts and the issued amount + SELECT * FROM amount_add(new_receipts_to_date, in_amount) INTO new_receipts_to_date; + -- check if the new receipts to date is below or equal the limit for the charity + IF (may_per_year.val > new_receipts_to_date.val) + OR (may_per_year.val = new_receipts_to_date.val) + AND (may_per_year.frac >= new_receipts_to_date.frac) + THEN + out_smaller_than_max_per_year=TRUE; + UPDATE charities + SET receipts_to_date=in_amount + WHERE charity_id=in_charity_id; + INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_hash, amount) + VALUES (/*in_blinded_sig,*/ in_charity_id, in_receipt_hash, in_amount); + ELSE + out_smaller_than_max_per_year=FALSE; + END IF; +END $$; +COMMIT; + +COMMENT ON FUNCTION do_insert_issued_receipts + IS 'This is a transaction for updating the current amount of receipts of a year of a charity and saves the receipts request what makes it idempotent'; diff --git a/src/donaudb/donau_do_save_issue_receipts_request.sql b/src/donaudb/donau_do_save_issue_receipts_request.sql @@ -1,64 +0,0 @@ --- --- 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 transaction_save_issue_receipts_request ( - IN in_charity_id BIGINT -- charity id which made the issue receitps request - --,IN in_blinded_sig BYTEA[] -- blinded signatures - ,IN in_receipt_hash BYTEA -- hash over all budi key pairs (primary key) - ,IN in_amount taler_amount -- total amount of the requested receipts - ,OUT out_smaller_than_max_per_year BOOLEAN -) -LANGUAGE plpgsql -AS $$ -DECLARE - new_receipts_to_date taler_amount; - may_per_year taler_amount; - tmp taler_amount; -BEGIN - -- Get charity values - SELECT - (chari.receipts_to_date).val - ,(chari.receipts_to_date).frac - ,(chari.max_per_year).val - ,(chari.max_per_year).frac - INTO - new_receipts_to_date.val - ,new_receipts_to_date.frac - ,may_per_year.val - ,may_per_year.frac - FROM charities chari - WHERE charity_id=in_charity_id; - -- calculate sum of the recent amount of receipts and the issued amount - SELECT * FROM amount_add(new_receipts_to_date, in_amount) INTO new_receipts_to_date; - -- check if the new receipts to date is below or equal the limit for the charity - IF (may_per_year.val > new_receipts_to_date.val) - OR (may_per_year.val = new_receipts_to_date.val) - AND (may_per_year.frac >= new_receipts_to_date.frac) - THEN - out_smaller_than_max_per_year=TRUE; - UPDATE charities - SET receipts_to_date=in_amount - WHERE charity_id=in_charity_id; - INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_hash, amount) - VALUES (/*in_blinded_sig,*/ in_charity_id, in_receipt_hash, in_amount); - ELSE - out_smaller_than_max_per_year=FALSE; - END IF; -END $$; -COMMIT; - -COMMENT ON FUNCTION transaction_save_issue_receipts_request - IS 'This is a transaction for updating the current amount of receipts of a year of a charity and saves the receipts request what makes it idempotent'; diff --git a/src/donaudb/pg_insert_issued_receipt.c b/src/donaudb/pg_insert_issued_receipt.c @@ -63,7 +63,7 @@ DH_PG_insert_issued_receipt ( "insert_issued_receipts_request", "SELECT " " out_smaller_than_max_per_year AS smaller_than_max_per_year" - " FROM transaction_save_issue_receipts_request" + " FROM do_insert_issued_receipts" "($1,$2,$3);"); qs = GNUNET_PQ_eval_prepared_singleton_select (pc->conn, diff --git a/src/donaudb/procedures.sql.in b/src/donaudb/procedures.sql.in @@ -20,6 +20,7 @@ SET search_path TO donau; #include "donau_do_gc.sql" #include "donau_do_amount_specific.sql" -#include "donau_do_save_issue_receipts_request.sql" +#include "donau_do_insert_submitted_receipts.sql" +#include "donau_do_insert_issued_receipts.sql" COMMIT;