summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/auditor/taler-auditor.c108
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c86
-rw-r--r--src/auditordb/test_auditordb.c12
-rw-r--r--src/include/taler_auditordb_plugin.h6
4 files changed, 102 insertions, 110 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c
index 186b29eb8..845858a17 100644
--- a/src/auditor/taler-auditor.c
+++ b/src/auditor/taler-auditor.c
@@ -26,16 +26,10 @@
*
* TODO:
* - FIXME: do proper transaction history check in #check_transaction_history()
- * - SANITY: rename functions/operations to better describe what they do!
* - OPTIMIZE/SIMPLIFY: modify auditordb to return DK when we inquire about deposit/refresh/refund,
* so we can avoid the costly #get_coin_summary with the transaction history building
* (at least during #analyze_coins); the logic may be partially useful in
* #analyze_merchants (but we won't need the cache!)
- * - MAJOR: check that aggregation records exist for deposits past payment deadline
- * (or that there was a full refund and thus there is no aggregation)
- * Conceptual issue: how do we deal with deposits that we already checked
- * in the past? => Need a very separate check / pass for this!
- * - BEAUTIFY: write reporting logic to output nice report beyond GNUNET_log()
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
@@ -1147,7 +1141,7 @@ init_denomination (const struct GNUNET_HashCode *denom_hash,
* @return NULL on error
*/
static struct DenominationSummary *
-get_denomination_summary (struct CoinContext *cc,
+get_balance_summary (struct CoinContext *cc,
const struct TALER_EXCHANGEDB_DenominationKeyInformationP *dki,
const struct GNUNET_HashCode *dh)
{
@@ -1446,7 +1440,7 @@ withdraw_cb (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- ds = get_denomination_summary (cc,
+ ds = get_balance_summary (cc,
dki,
&dh);
TALER_amount_ntoh (&value,
@@ -1625,7 +1619,7 @@ refresh_session_cb (void *cls,
struct DenominationSummary *dsi;
struct TALER_Amount value;
- dsi = get_denomination_summary (cc,
+ dsi = get_balance_summary (cc,
new_dki[i],
&new_dki[i]->properties.denom_hash);
TALER_amount_ntoh (&value,
@@ -1650,7 +1644,7 @@ refresh_session_cb (void *cls,
}
/* update old coin's denomination balance */
- dso = get_denomination_summary (cc,
+ dso = get_balance_summary (cc,
dki,
&dki->properties.denom_hash);
if (GNUNET_OK !=
@@ -1766,7 +1760,7 @@ deposit_cb (void *cls,
}
/* update old coin's denomination balance */
- ds = get_denomination_summary (cc,
+ ds = get_balance_summary (cc,
dki,
&dki->properties.denom_hash);
if (GNUNET_OK !=
@@ -1880,7 +1874,7 @@ refund_cb (void *cls,
}
/* update coin's denomination balance */
- ds = get_denomination_summary (cc,
+ ds = get_balance_summary (cc,
dki,
&dki->properties.denom_hash);
if (GNUNET_OK !=
@@ -1920,15 +1914,14 @@ analyze_coins (void *cls)
/* setup 'cc' */
cc.ret = GNUNET_OK;
- // SANITY: FIX misnomer "denomination_summary", as this is no longer exactly about denominations!
- dret = adb->get_denomination_summary (adb->cls,
- asession,
- &master_pub,
- &cc.denom_balance,
- &cc.deposit_fee_balance,
- &cc.melt_fee_balance,
- &cc.refund_fee_balance,
- &cc.risk);
+ dret = adb->get_balance_summary (adb->cls,
+ asession,
+ &master_pub,
+ &cc.denom_balance,
+ &cc.deposit_fee_balance,
+ &cc.melt_fee_balance,
+ &cc.refund_fee_balance,
+ &cc.risk);
if (GNUNET_SYSERR == dret)
{
GNUNET_break (0);
@@ -2016,25 +2009,24 @@ analyze_coins (void *cls)
&cc);
GNUNET_CONTAINER_multihashmap_destroy (cc.coins);
- // SANITY: FIX misnomer "denomination_summary", as this is no longer about denominations!
if (GNUNET_YES == dret)
- dret = adb->update_denomination_summary (adb->cls,
- asession,
- &master_pub,
- &cc.denom_balance,
- &cc.deposit_fee_balance,
- &cc.melt_fee_balance,
- &cc.refund_fee_balance,
- &cc.risk);
+ dret = adb->update_balance_summary (adb->cls,
+ asession,
+ &master_pub,
+ &cc.denom_balance,
+ &cc.deposit_fee_balance,
+ &cc.melt_fee_balance,
+ &cc.refund_fee_balance,
+ &cc.risk);
else
- dret = adb->insert_denomination_summary (adb->cls,
- asession,
- &master_pub,
- &cc.denom_balance,
- &cc.deposit_fee_balance,
- &cc.melt_fee_balance,
- &cc.refund_fee_balance,
- &cc.risk);
+ dret = adb->insert_balance_summary (adb->cls,
+ asession,
+ &master_pub,
+ &cc.denom_balance,
+ &cc.deposit_fee_balance,
+ &cc.melt_fee_balance,
+ &cc.refund_fee_balance,
+ &cc.risk);
if (GNUNET_OK != dret)
{
GNUNET_break (0);
@@ -2082,7 +2074,7 @@ struct WirePlugin
/**
* Closure for callbacks during #analyze_merchants().
*/
-struct MerchantContext
+struct AggregationContext
{
/**
@@ -2101,18 +2093,18 @@ struct MerchantContext
/**
* Find the relevant wire plugin.
*
- * @param mc context to search
+ * @param ac context to search
* @param type type of the wire plugin to load
* @return NULL on error
*/
static struct TALER_WIRE_Plugin *
-get_wire_plugin (struct MerchantContext *mc,
+get_wire_plugin (struct AggregationContext *ac,
const char *type)
{
struct WirePlugin *wp;
struct TALER_WIRE_Plugin *plugin;
- for (wp = mc->wire_head; NULL != wp; wp = wp->next)
+ for (wp = ac->wire_head; NULL != wp; wp = wp->next)
if (0 == strcmp (type,
wp->type))
return wp->plugin;
@@ -2128,8 +2120,8 @@ get_wire_plugin (struct MerchantContext *mc,
wp = GNUNET_new (struct WirePlugin);
wp->type = GNUNET_strdup (type);
wp->plugin = plugin;
- GNUNET_CONTAINER_DLL_insert (mc->wire_head,
- mc->wire_tail,
+ GNUNET_CONTAINER_DLL_insert (ac->wire_head,
+ ac->wire_tail,
wp);
return plugin;
}
@@ -2144,7 +2136,7 @@ struct WireCheckContext
/**
* Corresponding merchant context.
*/
- struct MerchantContext *mc;
+ struct AggregationContext *ac;
/**
* Total deposits claimed by all transactions that were aggregated
@@ -2467,7 +2459,7 @@ wire_transfer_information_cb (void *cls,
* Check that a wire transfer made by the exchange is valid
* (has matching deposits).
*
- * @param cls a `struct MerchantContext`
+ * @param cls a `struct AggregationContext`
* @param rowid identifier of the respective row in the database
* @param date timestamp of the wire transfer (roughly)
* @param wtid wire transfer subject
@@ -2482,12 +2474,12 @@ check_wire_out_cb (void *cls,
const json_t *wire,
const struct TALER_Amount *amount)
{
- struct MerchantContext *mc = cls;
+ struct AggregationContext *ac = cls;
struct WireCheckContext wcc;
json_t *method;
struct TALER_WIRE_Plugin *plugin;
- wcc.mc = mc;
+ wcc.ac = ac;
method = json_object_get (wire,
"type");
if ( (NULL == method) ||
@@ -2516,7 +2508,7 @@ check_wire_out_cb (void *cls,
rowid,
"audit of associated transactions failed");
}
- plugin = get_wire_plugin (mc,
+ plugin = get_wire_plugin (ac,
wcc.method);
if (NULL == plugin)
{
@@ -2552,29 +2544,29 @@ check_wire_out_cb (void *cls,
* @param int #GNUNET_OK on success, #GNUNET_SYSERR on hard errors
*/
static int
-analyze_merchants (void *cls)
+analyze_aggregations (void *cls)
{
- struct MerchantContext mc;
+ struct AggregationContext ac;
struct WirePlugin *wc;
int ret;
ret = GNUNET_OK;
- mc.wire_head = NULL;
- mc.wire_tail = NULL;
+ ac.wire_head = NULL;
+ ac.wire_tail = NULL;
if (GNUNET_SYSERR ==
edb->select_wire_out_above_serial_id (edb->cls,
esession,
pp.last_wire_out_serial_id,
&check_wire_out_cb,
- &mc))
+ &ac))
{
GNUNET_break (0);
ret = GNUNET_SYSERR;
}
- while (NULL != (wc = mc.wire_head))
+ while (NULL != (wc = ac.wire_head))
{
- GNUNET_CONTAINER_DLL_remove (mc.wire_head,
- mc.wire_tail,
+ GNUNET_CONTAINER_DLL_remove (ac.wire_head,
+ ac.wire_tail,
wc);
TALER_WIRE_plugin_unload (wc->plugin);
GNUNET_free (wc->type);
@@ -2760,7 +2752,7 @@ setup_sessions_and_run ()
NULL);
transact (&analyze_coins,
NULL);
- transact (&analyze_merchants,
+ transact (&analyze_aggregations,
NULL);
}
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index ddacca657..73ec92db2 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2016 GNUnet e.V.
+ Copyright (C) 2014-2017 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
@@ -336,10 +336,10 @@ postgres_create_tables (void *cls)
/* Table with the sum of the outstanding coins from
"denomination_pending" (denom_pubs must belong to the
respective's exchange's master public key); it represents the
- total_liabilities of the exchange at this point (modulo
+ balance_summary of the exchange at this point (modulo
unexpected historic_loss-style events where denomination keys are
compromised) */
- SQLEXEC ("CREATE TABLE IF NOT EXISTS total_liabilities"
+ SQLEXEC ("CREATE TABLE IF NOT EXISTS balance_summary"
"(master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)"
",denom_balance_val INT8 NOT NULL"
",denom_balance_frac INT4 NOT NULL"
@@ -697,9 +697,9 @@ postgres_prepare (PGconn *db_conn)
" WHERE denom_pub_hash=$1",
1, NULL);
- /* Used in #postgres_insert_denomination_summary() */
- PREPARE ("total_liabilities_insert",
- "INSERT INTO total_liabilities "
+ /* Used in #postgres_insert_balance_summary() */
+ PREPARE ("balance_summary_insert",
+ "INSERT INTO balance_summary "
"(master_pub"
",denom_balance_val"
",denom_balance_frac"
@@ -719,9 +719,9 @@ postgres_prepare (PGconn *db_conn)
") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);",
16, NULL);
- /* Used in #postgres_update_denomination_summary() */
- PREPARE ("total_liabilities_update",
- "UPDATE total_liabilities SET"
+ /* Used in #postgres_update_balance_summary() */
+ PREPARE ("balance_summary_update",
+ "UPDATE balance_summary SET"
" denom_balance_val=$1"
",denom_balance_frac=$2"
",denom_balance_curr=$3"
@@ -740,8 +740,8 @@ postgres_prepare (PGconn *db_conn)
" WHERE master_pub=$16;",
16, NULL);
- /* Used in #postgres_get_denomination_summary() */
- PREPARE ("total_liabilities_select",
+ /* Used in #postgres_get_balance_summary() */
+ PREPARE ("balance_summary_select",
"SELECT"
" denom_balance_val"
",denom_balance_frac"
@@ -758,7 +758,7 @@ postgres_prepare (PGconn *db_conn)
",risk_val"
",risk_frac"
",risk_curr"
- " FROM total_liabilities"
+ " FROM balance_summary"
" WHERE master_pub=$1;",
1, NULL);
@@ -1921,14 +1921,14 @@ postgres_get_denomination_balance (void *cls,
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
static int
-postgres_insert_denomination_summary (void *cls,
- struct TALER_AUDITORDB_Session *session,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk)
+postgres_insert_balance_summary (void *cls,
+ struct TALER_AUDITORDB_Session *session,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_Amount *denom_balance,
+ const struct TALER_Amount *deposit_fee_balance,
+ const struct TALER_Amount *melt_fee_balance,
+ const struct TALER_Amount *refund_fee_balance,
+ const struct TALER_Amount *risk)
{
PGresult *result;
int ret;
@@ -1955,7 +1955,7 @@ postgres_insert_denomination_summary (void *cls,
refund_fee_balance));
result = GNUNET_PQ_exec_prepared (session->conn,
- "total_liabilities_insert",
+ "balance_summary_insert",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
@@ -1986,14 +1986,14 @@ postgres_insert_denomination_summary (void *cls,
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
static int
-postgres_update_denomination_summary (void *cls,
- struct TALER_AUDITORDB_Session *session,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk)
+postgres_update_balance_summary (void *cls,
+ struct TALER_AUDITORDB_Session *session,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_Amount *denom_balance,
+ const struct TALER_Amount *deposit_fee_balance,
+ const struct TALER_Amount *melt_fee_balance,
+ const struct TALER_Amount *refund_fee_balance,
+ const struct TALER_Amount *risk)
{
PGresult *result;
int ret;
@@ -2008,7 +2008,7 @@ postgres_update_denomination_summary (void *cls,
};
result = GNUNET_PQ_exec_prepared (session->conn,
- "total_liabilities_update",
+ "balance_summary_update",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
@@ -2039,14 +2039,14 @@ postgres_update_denomination_summary (void *cls,
* for this @a master_pub; #GNUNET_SYSERR on failure
*/
static int
-postgres_get_denomination_summary (void *cls,
- struct TALER_AUDITORDB_Session *session,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *denom_balance,
- struct TALER_Amount *deposit_fee_balance,
- struct TALER_Amount *melt_fee_balance,
- struct TALER_Amount *refund_fee_balance,
- struct TALER_Amount *risk)
+postgres_get_balance_summary (void *cls,
+ struct TALER_AUDITORDB_Session *session,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ struct TALER_Amount *denom_balance,
+ struct TALER_Amount *deposit_fee_balance,
+ struct TALER_Amount *melt_fee_balance,
+ struct TALER_Amount *refund_fee_balance,
+ struct TALER_Amount *risk)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
@@ -2055,7 +2055,7 @@ postgres_get_denomination_summary (void *cls,
PGresult *result;
result = GNUNET_PQ_exec_prepared (session->conn,
- "total_liabilities_select",
+ "balance_summary_select",
params);
if (PGRES_TUPLES_OK !=
PQresultStatus (result))
@@ -2069,7 +2069,7 @@ postgres_get_denomination_summary (void *cls,
if (0 == nrows)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "postgres_get_denomination_summary() returned 0 matching rows\n");
+ "postgres_get_balance_summary() returned 0 matching rows\n");
PQclear (result);
return GNUNET_NO;
}
@@ -2701,9 +2701,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->update_denomination_balance = &postgres_update_denomination_balance;
plugin->insert_denomination_balance = &postgres_insert_denomination_balance;
- plugin->get_denomination_summary = &postgres_get_denomination_summary;
- plugin->update_denomination_summary = &postgres_update_denomination_summary;
- plugin->insert_denomination_summary = &postgres_insert_denomination_summary;
+ plugin->get_balance_summary = &postgres_get_balance_summary;
+ plugin->update_balance_summary = &postgres_update_balance_summary;
+ plugin->insert_balance_summary = &postgres_insert_balance_summary;
plugin->select_historic_denom_revenue = &postgres_select_historic_denom_revenue;
plugin->insert_historic_denom_revenue = &postgres_insert_historic_denom_revenue;
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
index 24184aee9..0e146e3a4 100644
--- a/src/auditordb/test_auditordb.c
+++ b/src/auditordb/test_auditordb.c
@@ -401,10 +401,10 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_denomination_summary\n");
+ "Test: insert_balance_summary\n");
FAILIF (GNUNET_OK !=
- plugin->insert_denomination_summary (plugin->cls,
+ plugin->insert_balance_summary (plugin->cls,
session,
&master_pub,
&refund_fee_balance,
@@ -414,10 +414,10 @@ run (void *cls)
&rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_denomination_summary\n");
+ "Test: update_balance_summary\n");
FAILIF (GNUNET_OK !=
- plugin->update_denomination_summary (plugin->cls,
+ plugin->update_balance_summary (plugin->cls,
session,
&master_pub,
&denom_balance,
@@ -427,7 +427,7 @@ run (void *cls)
&rbalance));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_denomination_summary\n");
+ "Test: get_balance_summary\n");
ZR_BLK (&denom_balance2);
ZR_BLK (&deposit_fee_balance2);
@@ -436,7 +436,7 @@ run (void *cls)
ZR_BLK (&rbalance2);
FAILIF (GNUNET_OK !=
- plugin->get_denomination_summary (plugin->cls,
+ plugin->get_balance_summary (plugin->cls,
session,
&master_pub,
&denom_balance2,
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index 4443ba5ff..1c6360feb 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -571,7 +571,7 @@ struct TALER_AUDITORDB_Plugin
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
- (*insert_denomination_summary)(void *cls,
+ (*insert_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance,
@@ -596,7 +596,7 @@ struct TALER_AUDITORDB_Plugin
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
- (*update_denomination_summary)(void *cls,
+ (*update_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_Amount *denom_balance,
@@ -621,7 +621,7 @@ struct TALER_AUDITORDB_Plugin
* for this @a master_pub; #GNUNET_SYSERR on failure
*/
int
- (*get_denomination_summary)(void *cls,
+ (*get_balance_summary)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
struct TALER_Amount *denom_balance,