commit 47fadc9be7e2800b05aa4c9352845ea84fdd67f3
parent 2e3723cb9f921b4500467907d5a59dcefc9d8c50
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date: Wed, 28 Feb 2024 16:56:07 +0100
working on donation units pg
Diffstat:
18 files changed, 329 insertions(+), 438 deletions(-)
diff --git a/src/donau/donau-httpd_keys.c b/src/donau/donau-httpd_keys.c
@@ -465,7 +465,7 @@ struct HelperState
};
/**
- * Closure for #add_donation_unit_key_cb.
+ * Closure for #insert_donation_unit_cb.
*/
struct DonationUnitKeyCtx
{
@@ -606,7 +606,7 @@ finish_keys_response (struct DH_KeyStateHandle *ksh)
// };
// GNUNET_CONTAINER_multihashmap_iterate (ksh->donation_unit_key_map,
- // &add_donation_unit_key_cb,
+ // &insert_donation_unit_cb,
// &dkc);
// ksh->rekey_frequency
// = GNUNET_TIME_relative_min (dkc.min_dk_frequency,
@@ -1364,7 +1364,7 @@ DH_keys_get_state ()
/**
- * Closure for #add_donation_unit_cb and #add_signkey_cb.
+ * Closure for #insert_donation_unit_cb and #add_signkey_cb.
*/
struct KeysBuilderContext
{
@@ -1397,15 +1397,15 @@ struct KeysBuilderContext
* @return #GNUNET_OK (continue to iterate)
*/
static enum GNUNET_GenericReturnValue
-add_donation_unitkey_cb (void *cls,
- const struct GNUNET_HashCode *h_donation_unit_pub,
- void *value)
+insert_donation_unitkey_cb (void *cls,
+ const struct GNUNET_HashCode *h_donation_unit_pub,
+ void *value)
{
struct KeysBuilderContext *kbc = cls;
struct HelperDonationUnit *helper_donation_unit = value;
struct DH_DonationUnitKey *donation_unit_key;
- struct DONAUDB_DonationUnitKeyMetaData meta =
- { 0 };
+ // struct TALER_Amount *value;
+ // uint64_t validity_year;
donation_unit_key = GNUNET_CONTAINER_multihashmap_get (
kbc->ksh->donation_unit_key_map,
@@ -1417,9 +1417,9 @@ add_donation_unitkey_cb (void *cls,
GNUNET_assert (
0 == json_array_append_new (kbc->donation_units, GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("value", &meta.value),
- GNUNET_JSON_pack_uint64 (
- "year", meta.validity_year),
+ TALER_JSON_pack_amount ("value", &value),
+ // GNUNET_JSON_pack_uint64 (
+ // "year", validity_year),
GNUNET_JSON_pack_data_auto (
"donation_unit_pub",
&
@@ -1524,7 +1524,7 @@ DH_handler_keys (struct DH_RequestContext *rc,
GNUNET_assert (NULL != kbc.signkeys);
GNUNET_assert (NULL != DH_currency);
GNUNET_CONTAINER_multihashmap_iterate (ksh->helpers->donation_unit_keys,
- &add_donation_unitkey_cb, &kbc);
+ &insert_donation_unitkey_cb, &kbc);
GNUNET_CONTAINER_multipeermap_iterate (ksh->helpers->esign_keys,
&add_signkey_cb, &kbc);
reply = GNUNET_JSON_PACK (
diff --git a/src/donau/donau-httpd_keys.h b/src/donau/donau-httpd_keys.h
@@ -50,10 +50,14 @@ struct DH_DonationUnitKey
struct DONAU_DonationUnitHashP h_donation_unit_pub;
/**
- * Meta data about the type of the donation unit, containing the validity
- * year and the value of the donation unit.
+ * Value that the donation unit represents.
*/
- struct DONAUDB_DonationUnitKeyMetaData meta;
+ struct TALER_Amount value;
+
+ /**
+ * The validity year.
+ */
+ uint64_t validity_year;
};
diff --git a/src/donaudb/0002-donation_units.sql b/src/donaudb/0002-donation_units.sql
@@ -16,7 +16,7 @@
CREATE TABLE donation_units
(donation_unit_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,donation_unit_hash BYTEA PRIMARY KEY CHECK (LENGTH(donation_unit_hash)=64)
+ ,h_donation_unit_pub BYTEA PRIMARY KEY CHECK (LENGTH(h_donation_unit_pub)=64)
,donation_unit_pub BYTEA UNIQUE NOT NULL
,validity_year INT4 NOT NULL
,value taler_amount NOT NULL
diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am
@@ -80,9 +80,8 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \
pg_start_read_only.h pg_start_read_only.c \
pg_insert_signing_key.c pg_insert_signing_key.h \
pg_lookup_signing_key.h pg_lookup_signing_key.c \
- pg_add_donation_unit_key.c pg_add_donation_unit_key.h \
- pg_lookup_donation_unit.c pg_lookup_donation_unit.h \
- pg_get_donation_units.c pg_get_donation_units.h \
+ pg_insert_donation_unit.c pg_insert_donation_unit.h \
+ pg_iterate_donation_units.c pg_iterate_donation_units.h \
pg_get_history.h pg_get_history.c \
pg_get_charities.h pg_get_charities.c \
pg_insert_charity.h pg_insert_charity.c \
diff --git a/src/donaudb/pg_add_donation_unit_key.c b/src/donaudb/pg_add_donation_unit_key.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 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_add_donation_unit_key.c
- * @brief Implementation of the add_donation_unit_key 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_add_donation_unit_key.h"
-#include "pg_helper.h"
-
-
-enum GNUNET_DB_QueryStatus
-DH_PG_add_donation_unit_key (
- void *cls,
- const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (&meta->donation_unit_hash),
- GNUNET_PQ_query_param_auto_from_type (donation_unit_pub),
- GNUNET_PQ_query_param_uint64 (&meta->validity_year),
- TALER_PQ_query_param_amount (pg->conn,
- &meta->value),
- GNUNET_PQ_query_param_end
- };
-
- PREPARE (pg,
- "donation_unit_insert",
- "INSERT INTO donation_units "
- "(donation_unit_hash"
- ",donation_unit_pub"
- ",validity_year"
- ",value"
- ") VALUES "
- "($1, $2, $3, $4);");
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "donation_unit_insert",
- iparams);
-}
diff --git a/src/donaudb/pg_add_donation_unit_key.h b/src/donaudb/pg_add_donation_unit_key.h
@@ -1,42 +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_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
-#define PG_ADD_DONATION_UNIT_KEY_H
-
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-#include "donaudb_plugin.h"
-
-/**
- * Add donation unit key.
- *
- * @param cls closure
- * @param donation_unit_pub the actual donation_unit key
- * @param meta meta information about the donation unit key
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-DH_PG_add_donation_unit_key (
- void *cls,
- const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta);
-
-#endif
diff --git a/src/donaudb/pg_get_donation_units.c b/src/donaudb/pg_get_donation_units.c
@@ -1,55 +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_get_donation_units.c
- * @brief Implementation of the get_donation_units 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_get_donation_units.h"
-#include "pg_helper.h"
-
-enum GNUNET_DB_QueryStatus
-DH_PG_get_donation_units (
- void *cls,
- struct DONAUDB_DonationUnitKeyMetaData *meta)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("validity_year",
- &meta->validity_year),
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &meta->value),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "get_donation_units",
- "SELECT"
- " validity_year"
- ",value"
- " FROM donation_units");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_donation_units",
- params,
- rs);
-}
diff --git a/src/donaudb/pg_get_donation_units.h b/src/donaudb/pg_get_donation_units.h
@@ -1,39 +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_get_donation_units.h
- * @brief implementation of the get_donation_units function for Postgres
- * @author Johannes Casaburi
- */
-#ifndef PG_LOOKUP_DONATION_UNIT_KEY_H
-#define PG_LOOKUP_DONATION_UNIT_KEY_H
-
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-#include "donaudb_plugin.h"
-/**
- * Lookup information about current donation unit key.
- *
- * @param cls closure
- * @param[out] meta set to various meta data about the key
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-DH_PG_get_donation_units (
- void *cls,
- struct DONAUDB_DonationUnitKeyMetaData *meta);
-
-#endif
diff --git a/src/donaudb/pg_insert_charity.h b/src/donaudb/pg_insert_charity.h
@@ -15,7 +15,7 @@
*/
/**
* @file donaudb/pg_insert_charity.h
- * @brief implementation of the add_donation_unit_key function for Postgres
+ * @brief implementation of the insert_charity function for Postgres
* @author Johannes Casaburi
*/
#ifndef PG_INSERT_CHARITY_H
diff --git a/src/donaudb/pg_insert_donation_unit.c b/src/donaudb/pg_insert_donation_unit.c
@@ -0,0 +1,58 @@
+/*
+ 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 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_donation_unit.c
+ * @brief Implementation of the insert_donation_unit 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_donation_unit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+DH_PG_insert_donation_unit (
+ void *cls,
+ const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
+ const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
+ struct TALER_Amount *value,
+ uint64_t validity_year)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam iparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub),
+ GNUNET_PQ_query_param_auto_from_type (donation_unit_pub),
+ GNUNET_PQ_query_param_uint64 (&validity_year),
+ TALER_PQ_query_param_amount (pg->conn, value),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "donation_unit_insert",
+ "INSERT INTO donation_units "
+ "(h_donation_unit_pub"
+ ",donation_unit_pub"
+ ",validity_year"
+ ",value"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "donation_unit_insert",
+ iparams);
+}
diff --git a/src/donaudb/pg_insert_donation_unit.h b/src/donaudb/pg_insert_donation_unit.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 donaudb/pg_insert_donation_unit.h
+ * @brief implementation of the insert_donation_unit function for Postgres
+ * @author Johannes Casaburi
+ */
+#ifndef PG_INSERT_DONATION_UNIT_H
+#define PG_INSERT_DONATION_UNIT_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "donaudb_plugin.h"
+
+/**
+ * Add donation unit key.
+ *
+ * @param cls closure
+ * @param donation_unit_pub the actual donation_unit key
+ * @param donation_unit_hash hash of the public key
+ * @param value value that the donation unit represents
+ * @param validity_year validity year
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+DH_PG_insert_donation_unit (
+ void *cls,
+ const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
+ const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
+ struct TALER_Amount *value,
+ uint64_t validity_year);
+
+#endif
diff --git a/src/donaudb/pg_iterate_donation_units.c b/src/donaudb/pg_iterate_donation_units.c
@@ -0,0 +1,135 @@
+/*
+ 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_iterate_donation_units.c
+ * @brief Implementation of the iterate_donation_units 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_iterate_donation_units.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #get_donation_units_cb().
+ */
+struct IterateDonationUnitsContext
+{
+ /**
+ * Function to call per result.
+ */
+ DONAUDB_IterateDonationUnitsCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+iterate_donation_units_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct IterateDonationUnitsContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct DONAU_DonationUnitHashP h_donation_unit_pub;
+ struct DONAU_DonationUnitPublicKey donation_unit_pub;
+ uint64_t validity_year;
+ struct TALER_Amount value;
+
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_donation_unit_pub",
+ &h_donation_unit_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("donation_unit_pub",
+ &donation_unit_pub),
+ GNUNET_PQ_result_spec_uint64 ("validity_year",
+ &validity_year),
+ TALER_PQ_result_spec_amount ("value",
+ "EUR", // TODO: Error if using TALER_PQ_RESULT_SPEC_AMOUNT
+ &value),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ h_donation_unit_pub,
+ donation_unit_pub,
+ validity_year,
+ value);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+DH_PG_iterate_donation_units (void *cls,
+ DONAUDB_IterateDonationUnitsCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct IterateDonationUnitsContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "iterate_donation_units",
+ "SELECT"
+ " h_donation_unit_pub"
+ ",donation_unit_pub"
+ ",validity_year"
+ ",value"
+ " FROM donation_units");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_donation_units",
+ params,
+ &iterate_donation_units_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/donaudb/pg_iterate_donation_units.h b/src/donaudb/pg_iterate_donation_units.h
@@ -0,0 +1,39 @@
+/*
+ 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_iterate_donation_units.h
+ * @brief implementation of the iterate_donation_units function for Postgres
+ * @author Johannes Casaburi
+ */
+#ifndef PG_ITERATE_DONATION_UNITS_H
+#define PG_ITERATE_DONATION_UNITS_H
+
+#include "donaudb_plugin.h"
+
+/**
+ * Obtain information about the enabled wire accounts of the exchange.
+ *
+ * @param cls closure
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+DH_PG_iterate_donation_units (void *cls,
+ DONAUDB_IterateDonationUnitsCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/donaudb/pg_lookup_donation_unit.c b/src/donaudb/pg_lookup_donation_unit.c
@@ -1,58 +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_lookup_donation_unit.c
- * @brief Implementation of the lookup_donation_unit 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_lookup_donation_unit.h"
-#include "pg_helper.h"
-
-enum GNUNET_DB_QueryStatus
-DH_PG_lookup_donation_unit (
- void *cls,
- const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("validity_year",
- &meta->validity_year),
- TALER_PQ_RESULT_SPEC_AMOUNT ("value",
- &meta->value),
- GNUNET_PQ_result_spec_end
- };
-
- PREPARE (pg,
- "lookup_donation_unit",
- "SELECT"
- " validity_year"
- ",value"
- " FROM donation_units"
- " WHERE donation_unit_hash=$1;");
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_donation_unit",
- params,
- rs);
-}
diff --git a/src/donaudb/pg_lookup_donation_unit.h b/src/donaudb/pg_lookup_donation_unit.h
@@ -1,41 +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_lookup_donation_unit.h
- * @brief implementation of the lookup_donation_unit function for Postgres
- * @author Johannes Casaburi
- */
-#ifndef PG_LOOKUP_DONATION_UNIT_KEY_H
-#define PG_LOOKUP_DONATION_UNIT_KEY_H
-
-#include <taler/taler_util.h>
-#include <taler/taler_json_lib.h>
-#include "donaudb_plugin.h"
-/**
- * Lookup information about current donation unit key.
- *
- * @param cls closure
- * @param h_donation_unit_pub hash of the donation_unit public key
- * @param[out] meta set to various meta data about the key
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-DH_PG_lookup_donation_unit (
- void *cls,
- const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta);
-
-#endif
diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c
@@ -49,8 +49,8 @@
// #include "pg_delete_shard_locks.h"
// #include "pg_compute_shard.h"
-#include "pg_add_donation_unit_key.h"
-#include "pg_lookup_donation_unit.h"
+#include "pg_insert_donation_unit.h"
+#include "pg_iterate_donation_units.h"
#include "pg_insert_history_entry.h"
#include "pg_get_history.h"
#include "pg_insert_issued_receipt.h"
@@ -188,52 +188,6 @@ libtaler_plugin_donaudb_postgres_init (void *cls)
GNUNET_free (pg);
return NULL;
}
- // if ( (GNUNET_OK !=
- // GNUNET_CONFIGURATION_get_value_time (cfg,
- // "donaudb",
- // "IDLE_RESERVE_EXPIRATION_TIME",
- // &pg->idle_reserve_expiration_time))
- // ||
- // (GNUNET_OK !=
- // GNUNET_CONFIGURATION_get_value_time (cfg,
- // "donaudb",
- // "LEGAL_RESERVE_EXPIRATION_TIME",
- // &pg->legal_reserve_expiration_time)) )
- // {
- // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- // "donaudb",
- // "LEGAL/IDLE_RESERVE_EXPIRATION_TIME");
- // GNUNET_free (pg->donau_url);
- // GNUNET_free (pg->sql_dir);
- // GNUNET_free (pg);
- // return NULL;
- // }
- // if (GNUNET_OK !=
- // GNUNET_CONFIGURATION_get_value_time (cfg,
- // "donaudb",
- // "AGGREGATOR_SHIFT",
- // &pg->aggregator_shift))
- // {
- // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- // "donaudb",
- // "AGGREGATOR_SHIFT");
- // }
- // if (GNUNET_OK !=
- // GNUNET_CONFIGURATION_get_value_number (cfg,
- // "donaudb",
- // "DEFAULT_PURSE_LIMIT",
- // &dpl))
- // {
- // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- // "donaudb",
- // "DEFAULT_PURSE_LIMIT");
- // pg->def_purse_limit = 1;
- // }
- // else
- // {
- // pg->def_purse_limit = (uint32_t) dpl;
- // }
-
if (GNUNET_OK !=
TALER_config_get_currency (cfg,
&pg->currency))
@@ -283,10 +237,10 @@ libtaler_plugin_donaudb_postgres_init (void *cls)
// plugin->gc
// = &DH_PG_gc;
- plugin->add_donation_unit_key
- = &DH_PG_add_donation_unit_key;
- plugin->lookup_donation_unit
- = &DH_PG_lookup_donation_unit;
+ plugin->insert_donation_unit
+ = &DH_PG_insert_donation_unit;
+ plugin->iterate_donation_units
+ = &DH_PG_iterate_donation_units;
plugin->insert_history_entry
= &DH_PG_insert_history_entry;
plugin->get_history
diff --git a/src/include/donau_crypto_lib.h b/src/include/donau_crypto_lib.h
@@ -349,11 +349,11 @@ DONAU_blinded_donation_unit_sig_free (
// * Compute the hash of the given @a donation_unit_pub.
// *
// * @param donation_unit_pub public key to hash
-// * @param[out] donation_unit_hash resulting hash value
+// * @param[out] h_donation_unit_pub resulting hash value
// */
// void
// TALER_donation_unit_pub_hash (const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
-// struct DONAU_DonationUnitHashP *donation_unit_hash);
+// struct DONAU_DonationUnitHashP *h_donation_unit_pub);
//
//
///**
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -27,28 +27,6 @@
#include "donau_util.h"
/**
- * Meta data about a donation unit key.
- */
-struct DONAUDB_DonationUnitKeyMetaData
-{
- /**
- * The value of the donation unit.
- */
- struct TALER_Amount value;
-
- /**
- * The year for which this donation unit is valid.
- */
- uint64_t validity_year;
-
- /**
- * Hash code of the donation unit public key.
- */
- struct DONAU_DonationUnitHashP donation_unit_hash; // already in GNUNET_CRYPTO_BlindSignPublicKey -> part of every public donation unit
-
-};
-
-/**
* Meta data about an donau signing key.
*/
struct DONAUDB_SignkeyMetaData
@@ -133,32 +111,6 @@ struct DONAUDB_DonationUnitKey
/**
* Signature of a function called with information about the donau's
- * donation unit keys.
- *
- * @param cls closure with a `struct DH_KeyStateHandle *`
- * @param donation_unit_pub public key of the donation unit
- * @param info donation unit key information
- */
-typedef void
-(*DONAUDB_DonationUnitCallback)(
- void *cls,
- const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *info);
-
-/**
- * Signature of a function called with information about the donau's
- * donation unit keys.
- *
- * @param cls closure with a `struct DH_KeyStateHandle *`
- * @param info donation unit key information
- */
-typedef void
-(*DONAUDB_GetDonationUnitsCallback)(
- void *cls,
- struct DONAUDB_DonationUnitKeyMetaData *info);
-
-/**
- * Signature of a function called with information about the donau's
* signing keys.
*
* @param cls closure with a `struct DH_KeyStateHandle *`
@@ -173,11 +125,22 @@ typedef void
/**
+ * Return donation units.
+ *
+ * @param cls closure
+ */
+typedef void
+(*DONAUDB_IterateDonationUnitsCallback)(
+ void *cls,
+ const struct DONAU_DonationUnitHashP h_donation_unit_pub,
+ const struct DONAU_DonationUnitPublicKey donation_unit_pub,
+ uint64_t validity_year,
+ struct TALER_Amount value);
+
+/**
* Return charities.
*
* @param cls closure
- * @param charity_url
- * @param charity_name
*/
typedef void
(*DONAUDB_GetCharitiesCallback)(
@@ -193,8 +156,6 @@ typedef void
* Return history.
*
* @param cls closure
- * @param charity_url
- * @param charity_name
*/
typedef void
(*DONAUDB_GetHistoryCallback)(
@@ -434,7 +395,7 @@ struct DONAUDB_Plugin
uint64_t current_year);
/**
- * Get keys.
+ * Iterate donation units.
*
* @param cls closure
* @param cb callback to invoke on each match
@@ -442,9 +403,9 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_keys)(
+ (*iterate_donation_units)(
void *cls,
- DONAUDB_GetDonationUnitsCallback cb,
+ DONAUDB_IterateDonationUnitsCallback cb,
void *cb_cls);
/**
@@ -477,32 +438,19 @@ struct DONAUDB_Plugin
const uint64_t donation_year);
/**
- * Get donation_unit_key.
+ * Insert donation_unit.
*
* @param cls closure
* @param donation_unit_pub
- * @param meta
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*add_donation_unit_key)(
+ (*insert_donation_unit)(
void *cls,
const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta);
-
- /**
- * Lookup information about current donation unit key.
- *
- * @param cls closure
- * @param h_donation_unit_pub hash of the donation_unit public key
- * @param[out] meta set to various meta data about the key
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*lookup_donation_unit)(
- void *cls,
const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
- struct DONAUDB_DonationUnitKeyMetaData *meta);
+ struct TALER_Amount value,
+ uint64_t validity_year);
/**
* Insert history entry of a charity