summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-10-28 11:38:45 +0100
committerChristian Grothoff <christian@grothoff.org>2018-10-28 11:38:45 +0100
commitbe9ff317dd47d12a9a9c31a0c867b51fa27ebb1b (patch)
tree6b1d2a820aba86f8765b8e1a7f97b660f650868d /src/exchangedb
parentbd40aad7dc22c9f5d723f82384c5d57204205b7a (diff)
downloadexchange-be9ff317dd47d12a9a9c31a0c867b51fa27ebb1b.tar.gz
exchange-be9ff317dd47d12a9a9c31a0c867b51fa27ebb1b.tar.bz2
exchange-be9ff317dd47d12a9a9c31a0c867b51fa27ebb1b.zip
add operation to count number of known coins per denomination to exchangedb
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index b2731366a..3cd467c01 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -289,6 +289,8 @@ postgres_create_tables (void *cls)
",denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE"
",denom_sig BYTEA NOT NULL"
");"),
+ GNUNET_PQ_make_try_execute ("CREATE INDEX known_coins_by_denomination ON "
+ "known_coins (denom_pub_hash)"),
/* Table with the commitments made when melting a coin. */
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS refresh_commitments "
@@ -797,6 +799,13 @@ postgres_prepare (PGconn *db_conn)
" ORDER BY reserve_out_serial_id ASC;",
1),
+ /* Used in #postgres_count_known_coins() */
+ GNUNET_PQ_make_prepare ("count_known_coins",
+ "SELECT"
+ " COUNT(*) AS count"
+ " FROM known_coins"
+ " WHERE denom_pub_hash=$1;",
+ 1),
/* Used in #postgres_get_known_coin() to fetch
the denomination public key and signature for
a coin known to the exchange. */
@@ -3197,6 +3206,41 @@ insert_known_coin (void *cls,
/**
+ * Count the number of known coins by denomination.
+ *
+ * @param cls database connection plugin state
+ * @param session database session
+ * @param denom_pub_hash denomination to count by
+ * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus`
+ */
+static long long
+postgres_count_known_coins (void *cls,
+ struct TALER_EXCHANGEDB_Session *session,
+ const struct GNUNET_HashCode *denom_pub_hash)
+{
+ uint64_t count;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("count",
+ &count),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+ "count_known_coins",
+ params,
+ rs);
+ if (0 > qs)
+ return (long long) qs;
+ return (long long) count;
+}
+
+
+/**
* Make sure the given @a coin is known to the database.
*
* @param cls database connection plugin state
@@ -7064,6 +7108,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->insert_withdraw_info = &postgres_insert_withdraw_info;
plugin->get_reserve_history = &postgres_get_reserve_history;
plugin->free_reserve_history = &common_free_reserve_history;
+ plugin->count_known_coins = &postgres_count_known_coins;
plugin->ensure_coin_known = &postgres_ensure_coin_known;
plugin->have_deposit = &postgres_have_deposit;
plugin->mark_deposit_tiny = &postgres_mark_deposit_tiny;