donau

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

commit 79c041cd8dde2142250d26b2e971b59c83561716
parent 354c630648c5f86310718eaaabe224595bd4cb38
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Wed, 17 Apr 2024 16:51:48 +0200

[donaudb] work on insert issued receipts

Diffstat:
Msrc/donaudb/0002-donau_receipts_issued.sql | 27+--------------------------
Asrc/donaudb/donau_do_save_issue_receipts_request.sql | 40++++++++++++++++++++++++++++++++++++++++
Msrc/donaudb/pg_insert_issued_receipt.c | 4++--
Msrc/donaudb/procedures.sql.in | 1+
4 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/src/donaudb/0002-donau_receipts_issued.sql b/src/donaudb/0002-donau_receipts_issued.sql @@ -16,7 +16,7 @@ CREATE TABLE receipts_issued (receipt_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE - ,blinded_sig BYTEA[] NOT NULL + ,blinded_sig BYTEA[] ,charity_id BIGINT NOT NULL REFERENCES charities (charity_id) ON DELETE CASCADE ,receipt_hash BYTEA PRIMARY KEY CHECK (LENGTH(receipt_hash)=64) ,amount taler_amount NOT NULL @@ -27,28 +27,3 @@ COMMENT ON COLUMN receipts_issued.blinded_sig IS 'Signature from the charity.'; COMMENT ON COLUMN receipts_issued.receipt_hash IS 'Hash value over all the blinded donation receipt received plus the hash of the donation units public key.'; - - -CREATE OR REPLACE FUNCTION transaction_save_issue_receipts_request( - IN charity_id BIGINT -- charity id which made the issue receitps request - --,IN blinded_sig BYTEA[] -- blinded signatures - ,IN receipt_h BYTEA -- hash over all budi key pairs (primary key) - ,IN amount taler_amount -- total amount of the requested receipts - ,IN new_total_amount taler_amount -- new total amount of a charity - ,OUT out_receipt_id BIGINT -) -LANGUAGE plpgsql -AS $$ -BEGIN --- Update table charity -UPDATE charity SET receipts_to_date = new_total_amount; --- Insert into the table receipts_issued -INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_h, amount) VALUES (/*'blinded_sig',*/ 'charity_id', 'receipts_hash', 'amount'); --- Get the receipts id -SELECT receipt_id into out_receipt_id FROM receipts_issued WHERE receipt_hash=receipt_h; --- Commit the transaction if everything is successful -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/donau_do_save_issue_receipts_request.sql b/src/donaudb/donau_do_save_issue_receipts_request.sql @@ -0,0 +1,40 @@ +-- +-- 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 + ,IN in_new_total_amount taler_amount -- new total amount of a charity + ,OUT out_receipt_id BIGINT +) +LANGUAGE plpgsql +AS $$ +BEGIN +-- Update table charities +UPDATE charities SET receipts_to_date = in_new_total_amount; +-- Insert into the table receipts_issued +INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_hash, amount) +VALUES (/*in_blinded_sig,*/ in_charity_id, in_receipt_hash, in_amount) RETURNING receipt_id INTO out_receipt_id; +-- Get the receipts id +-- SELECT receipt_id INTO out_receipt_id SELECT WHERE receipt_hash=in_receipts_hash FROM receipts_issued ; +-- Commit the transaction if everything is successful +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 @@ -52,9 +52,9 @@ DH_PG_insert_issued_receipt ( // DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, // signatures, pc->conn), GNUNET_PQ_query_param_auto_from_type (&h_receipt->hash), - TALER_PQ_query_param_amount_with_currency (pc->conn, + TALER_PQ_query_param_amount (pc->conn, amount_receipts_request), - TALER_PQ_query_param_amount_with_currency (pc->conn, charity_new_amount), + TALER_PQ_query_param_amount (pc->conn, charity_new_amount), GNUNET_PQ_query_param_end }; diff --git a/src/donaudb/procedures.sql.in b/src/donaudb/procedures.sql.in @@ -19,5 +19,6 @@ BEGIN; SET search_path TO donau; #include "donau_do_gc.sql" +#include "donau_do_save_issue_receipts_request.sql" COMMIT;