From 1a542148a6c16a3ff074287239c24259fece2aba Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 16 Feb 2019 21:38:12 +0100 Subject: implement iterate_denomination_info() call --- src/exchangedb/plugin_exchangedb_postgres.c | 120 ++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index c399aeeb5..506d34b0a 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015, 2016, 2017, 2018 GNUnet e.V. + Copyright (C) 2014--2019 GNUnet e.V. 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 @@ -547,6 +547,33 @@ postgres_prepare (PGconn *db_conn) " $11, $12, $13, $14, $15, $16, $17, $18," " $19, $20, $21, $22, $23);", 23), + /* Used in #postgres_iterate_denomination_info() */ + GNUNET_PQ_make_prepare ("denomination_iterate", + "SELECT" + " master_pub" + ",master_sig" + ",valid_from" + ",expire_withdraw" + ",expire_deposit" + ",expire_legal" + ",coin_val" /* value of this denom */ + ",coin_frac" /* fractional value of this denom */ + ",coin_curr" /* assuming same currency for fees */ + ",fee_withdraw_val" + ",fee_withdraw_frac" + ",fee_withdraw_curr" /* must match coin_curr */ + ",fee_deposit_val" + ",fee_deposit_frac" + ",fee_deposit_curr" /* must match coin_curr */ + ",fee_refresh_val" + ",fee_refresh_frac" + ",fee_refresh_curr" /* must match coin_curr */ + ",fee_refund_val" + ",fee_refund_frac" + ",fee_refund_curr" /* must match coin_curr */ + ",denom_pub" + " FROM denominations;", + 0), /* Used in #postgres_get_denomination_info() */ GNUNET_PQ_make_prepare ("denomination_get", "SELECT" @@ -1980,6 +2007,82 @@ postgres_get_denomination_info (void *cls, } +struct DenomIteratorContext +{ + TALER_EXCHANGEDB_DenominationInfoIterator cb; + void *cb_cls; +}; + + +/** + * Helper function for #postgres_iterate_denomination_info(). + * Calls the callback with each denomination key. + * + * @param cls a `struct DenomIteratorContext` + * @param result db results + * @param num_results number of results in @a result + */ +static void +domination_cb_helper (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct DenomIteratorContext *dic = cls; + + for (unsigned int i=0;icb (dic->cb_cls, + &denom_pub, + &issue); + GNUNET_CRYPTO_rsa_public_key_free (denom_pub.rsa_public_key); + } +} + + /** * Fetch information about all known denomination keys. * @@ -1993,15 +2096,20 @@ postgres_iterate_denomination_info (void *cls, TALER_EXCHANGEDB_DenominationInfoIterator cb, void *cb_cls) { -#if 0 - enum GNUNET_DB_QueryStatus qs; + struct PostgresClosure *pc = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_end }; -#endif + struct DenomIteratorContext dic = { + .cb = cb, + .cb_cls = cb_cls + }; - GNUNET_break (0); // not implemented! #5536 - return GNUNET_DB_STATUS_HARD_ERROR; + return GNUNET_PQ_eval_prepared_multi_select (postgres_get_session (pc)->conn, + "denomination_iterate", + params, + &domination_cb_helper, + &dic); } -- cgit v1.2.3