aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/auditor/taler-auditor.c77
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c180
-rw-r--r--src/auditordb/test_auditordb.c137
-rw-r--r--src/include/taler_auditordb_plugin.h86
4 files changed, 172 insertions, 308 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c
index 85839e5fe..e70615c64 100644
--- a/src/auditor/taler-auditor.c
+++ b/src/auditor/taler-auditor.c
@@ -78,32 +78,7 @@ static struct TALER_MasterPublicKeyP master_pub;
/**
* Last reserve_in serial ID seen.
*/
-static uint64_t reserve_in_serial_id;
-
-/**
- * Last reserve_out serial ID seen.
- */
-static uint64_t reserve_out_serial_id;
-
-/**
- * Last deposit serial ID seen.
- */
-static uint64_t deposit_serial_id;
-
-/**
- * Last melt serial ID seen.
- */
-static uint64_t melt_serial_id;
-
-/**
- * Last deposit refund ID seen.
- */
-static uint64_t refund_serial_id;
-
-/**
- * Last prewire serial ID seen.
- */
-static uint64_t prewire_serial_id;
+static struct TALER_AUDITORDB_ProgressPoint pp;
/* ***************************** Report logic **************************** */
@@ -486,8 +461,8 @@ handle_reserve_in (void *cls,
struct ReserveSummary *rs;
struct GNUNET_TIME_Absolute expiry;
- GNUNET_assert (rowid >= reserve_in_serial_id); /* should be monotonically increasing */
- reserve_in_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= pp.last_reserve_in_serial_id); /* should be monotonically increasing */
+ pp.last_reserve_in_serial_id = rowid + 1;
GNUNET_CRYPTO_hash (reserve_pub,
sizeof (*reserve_pub),
&key);
@@ -570,8 +545,8 @@ handle_reserve_out (void *cls,
int ret;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= reserve_out_serial_id);
- reserve_out_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= pp.last_reserve_out_serial_id);
+ pp.last_reserve_out_serial_id = rowid + 1;
/* lookup denomination pub data (make sure denom_pub is valid, establish fees) */
ret = get_denomination_info (denom_pub,
@@ -872,7 +847,7 @@ analyze_reserves (void *cls)
if (GNUNET_OK !=
edb->select_reserves_in_above_serial_id (edb->cls,
esession,
- reserve_in_serial_id,
+ pp.last_reserve_in_serial_id,
&handle_reserve_in,
&rc))
{
@@ -882,7 +857,7 @@ analyze_reserves (void *cls)
if (GNUNET_OK !=
edb->select_reserves_out_above_serial_id (edb->cls,
esession,
- reserve_out_serial_id,
+ pp.last_reserve_out_serial_id,
&handle_reserve_out,
&rc))
{
@@ -1147,12 +1122,7 @@ incremental_processing (Analysis analysis,
ret = adb->get_auditor_progress (adb->cls,
asession,
&master_pub,
- &reserve_in_serial_id,
- &reserve_out_serial_id,
- &deposit_serial_id,
- &melt_serial_id,
- &refund_serial_id,
- &prewire_serial_id);
+ &pp);
if (GNUNET_SYSERR == ret)
{
GNUNET_break (0);
@@ -1167,12 +1137,12 @@ incremental_processing (Analysis analysis,
{
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
_("Resuming audit at %llu/%llu/%llu/%llu/%llu/%llu\n\n"),
- (unsigned long long) reserve_in_serial_id,
- (unsigned long long) reserve_out_serial_id,
- (unsigned long long) deposit_serial_id,
- (unsigned long long) melt_serial_id,
- (unsigned long long) refund_serial_id,
- (unsigned long long) prewire_serial_id);
+ (unsigned long long) pp.last_reserve_in_serial_id,
+ (unsigned long long) pp.last_reserve_out_serial_id,
+ (unsigned long long) pp.last_deposit_serial_id,
+ (unsigned long long) pp.last_melt_serial_id,
+ (unsigned long long) pp.last_refund_serial_id,
+ (unsigned long long) pp.last_prewire_serial_id);
}
ret = analysis (analysis_cls);
if (GNUNET_OK != ret)
@@ -1184,12 +1154,7 @@ incremental_processing (Analysis analysis,
ret = adb->update_auditor_progress (adb->cls,
asession,
&master_pub,
- reserve_in_serial_id,
- reserve_out_serial_id,
- deposit_serial_id,
- melt_serial_id,
- refund_serial_id,
- prewire_serial_id);
+ &pp);
if (GNUNET_OK != ret)
{
GNUNET_break (0);
@@ -1197,12 +1162,12 @@ incremental_processing (Analysis analysis,
}
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
_("Resuming audit at %llu/%llu/%llu/%llu/%llu/%llu\n\n"),
- (unsigned long long) reserve_in_serial_id,
- (unsigned long long) reserve_out_serial_id,
- (unsigned long long) deposit_serial_id,
- (unsigned long long) melt_serial_id,
- (unsigned long long) refund_serial_id,
- (unsigned long long) prewire_serial_id);
+ (unsigned long long) pp.last_reserve_in_serial_id,
+ (unsigned long long) pp.last_reserve_out_serial_id,
+ (unsigned long long) pp.last_deposit_serial_id,
+ (unsigned long long) pp.last_melt_serial_id,
+ (unsigned long long) pp.last_refund_serial_id,
+ (unsigned long long) pp.last_prewire_serial_id);
return GNUNET_OK;
}
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 65da0bf18..989e54aea 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -1199,18 +1199,15 @@ postgres_insert_denomination_info (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&issue->denom_hash),
GNUNET_PQ_query_param_auto_from_type (&issue->master),
-
GNUNET_PQ_query_param_auto_from_type (&issue->start),
GNUNET_PQ_query_param_auto_from_type (&issue->expire_withdraw),
GNUNET_PQ_query_param_auto_from_type (&issue->expire_deposit),
GNUNET_PQ_query_param_auto_from_type (&issue->expire_legal),
-
TALER_PQ_query_param_amount_nbo (&issue->value),
TALER_PQ_query_param_amount_nbo (&issue->fee_withdraw),
TALER_PQ_query_param_amount_nbo (&issue->fee_deposit),
TALER_PQ_query_param_amount_nbo (&issue->fee_refresh),
TALER_PQ_query_param_amount_nbo (&issue->fee_refund),
-
GNUNET_PQ_query_param_end
};
@@ -1264,7 +1261,6 @@ postgres_select_denomination_info (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
@@ -1294,18 +1290,15 @@ postgres_select_denomination_info (void *cls,
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &issue.denom_hash),
-
GNUNET_PQ_result_spec_auto_from_type ("valid_from", &issue.start),
GNUNET_PQ_result_spec_auto_from_type ("expire_withdraw", &issue.expire_withdraw),
GNUNET_PQ_result_spec_auto_from_type ("expire_deposit", &issue.expire_deposit),
GNUNET_PQ_result_spec_auto_from_type ("expire_legal", &issue.expire_legal),
-
TALER_PQ_result_spec_amount_nbo ("coin", &issue.value),
TALER_PQ_result_spec_amount_nbo ("fee_withdraw", &issue.fee_withdraw),
TALER_PQ_result_spec_amount_nbo ("fee_deposit", &issue.fee_deposit),
TALER_PQ_result_spec_amount_nbo ("fee_refresh", &issue.fee_refresh),
TALER_PQ_result_spec_amount_nbo ("fee_refund", &issue.fee_refund),
-
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
@@ -1338,39 +1331,27 @@ postgres_select_denomination_info (void *cls,
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param pp where is the auditor in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
postgres_insert_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t last_reserve_in_serial_id,
- uint64_t last_reserve_out_serial_id,
- uint64_t last_deposit_serial_id,
- uint64_t last_melt_serial_id,
- uint64_t last_refund_serial_id,
- uint64_t last_prewire_serial_id)
+ const struct TALER_AUDITORDB_ProgressPoint *pp)
{
PGresult *result;
- int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
- GNUNET_PQ_query_param_uint64 (&last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_prewire_serial_id),
-
+ GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_reserve_out_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_deposit_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_melt_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_refund_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_prewire_serial_id),
GNUNET_PQ_query_param_end
};
+ int ret;
result = GNUNET_PQ_exec_prepared (session->conn,
"auditor_progress_insert",
@@ -1396,39 +1377,27 @@ postgres_insert_auditor_progress (void *cls,
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param pp where is the auditor in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
postgres_update_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t last_reserve_in_serial_id,
- uint64_t last_reserve_out_serial_id,
- uint64_t last_deposit_serial_id,
- uint64_t last_melt_serial_id,
- uint64_t last_refund_serial_id,
- uint64_t last_prewire_serial_id)
+ const struct TALER_AUDITORDB_ProgressPoint *pp)
{
PGresult *result;
- int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&last_prewire_serial_id),
-
+ GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_reserve_out_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_deposit_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_melt_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_refund_serial_id),
+ GNUNET_PQ_query_param_uint64 (&pp->last_prewire_serial_id),
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
+ int ret;
result = GNUNET_PQ_exec_prepared (session->conn,
"auditor_progress_update",
@@ -1453,11 +1422,7 @@ postgres_update_auditor_progress (void *cls,
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param[out] last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param[out] last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param[out] last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param[out] last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param[out] last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param[out] pp set to where the auditor is in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure;
* #GNUNET_NO if we have no records for the @a master_pub
*/
@@ -1465,19 +1430,23 @@ int
postgres_get_auditor_progress (void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t *last_reserve_in_serial_id,
- uint64_t *last_reserve_out_serial_id,
- uint64_t *last_deposit_serial_id,
- uint64_t *last_melt_serial_id,
- uint64_t *last_refund_serial_id,
- uint64_t *last_prewire_serial_id)
+ struct TALER_AUDITORDB_ProgressPoint *pp)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("last_reserve_in_serial_id", &pp->last_reserve_in_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id", &pp->last_reserve_out_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id", &pp->last_deposit_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("last_melt_serial_id", &pp->last_melt_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("last_refund_serial_id", &pp->last_refund_serial_id),
+ GNUNET_PQ_result_spec_uint64 ("last_prewire_serial_id", &pp->last_prewire_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
result = GNUNET_PQ_exec_prepared (session->conn,
"auditor_progress_select",
params);
@@ -1499,18 +1468,10 @@ postgres_get_auditor_progress (void *cls,
}
GNUNET_assert (1 == nrows);
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_reserve_in_serial_id", last_reserve_in_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id", last_reserve_out_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id", last_deposit_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_melt_serial_id", last_melt_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_refund_serial_id", last_refund_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_prewire_serial_id", last_prewire_serial_id),
-
- GNUNET_PQ_result_spec_end
- };
if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result,
+ rs,
+ 0))
{
GNUNET_break (0);
PQclear (result);
@@ -1552,19 +1513,14 @@ postgres_insert_reserve_info (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
TALER_PQ_query_param_amount (reserve_balance),
TALER_PQ_query_param_amount (withdraw_fee_balance),
-
GNUNET_PQ_query_param_auto_from_type (&expiration_date),
-
GNUNET_PQ_query_param_uint64 (&last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
-
GNUNET_PQ_query_param_end
};
@@ -1620,19 +1576,14 @@ postgres_update_reserve_info (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (reserve_balance),
TALER_PQ_query_param_amount (withdraw_fee_balance),
-
GNUNET_PQ_query_param_auto_from_type (&expiration_date),
-
GNUNET_PQ_query_param_uint64 (&last_reserve_in_serial_id),
GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
-
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
@@ -1730,7 +1681,6 @@ postgres_get_reserve_info (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserve_pub),
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
@@ -1799,13 +1749,10 @@ postgres_insert_reserve_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
TALER_PQ_query_param_amount (reserve_balance),
TALER_PQ_query_param_amount (withdraw_fee_balance),
-
GNUNET_PQ_query_param_end
};
@@ -1851,13 +1798,10 @@ postgres_update_reserve_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (reserve_balance),
TALER_PQ_query_param_amount (withdraw_fee_balance),
-
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
@@ -1899,7 +1843,6 @@ postgres_get_reserve_summary (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
@@ -1978,20 +1921,16 @@ postgres_insert_denomination_balance (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
-
TALER_PQ_query_param_amount (denom_balance),
TALER_PQ_query_param_amount (deposit_fee_balance),
TALER_PQ_query_param_amount (melt_fee_balance),
TALER_PQ_query_param_amount (refund_fee_balance),
-
GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id),
GNUNET_PQ_query_param_uint64 (&last_melt_serial_id),
GNUNET_PQ_query_param_uint64 (&last_refund_serial_id),
-
GNUNET_PQ_query_param_end
};
@@ -2060,20 +1999,16 @@ postgres_update_denomination_balance (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (denom_balance),
TALER_PQ_query_param_amount (deposit_fee_balance),
TALER_PQ_query_param_amount (melt_fee_balance),
TALER_PQ_query_param_amount (refund_fee_balance),
-
GNUNET_PQ_query_param_uint64 (&last_reserve_out_serial_id),
GNUNET_PQ_query_param_uint64 (&last_deposit_serial_id),
GNUNET_PQ_query_param_uint64 (&last_melt_serial_id),
GNUNET_PQ_query_param_uint64 (&last_refund_serial_id),
-
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
-
GNUNET_PQ_query_param_end
};
@@ -2129,10 +2064,10 @@ postgres_get_denomination_balance (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"denomination_pending_select",
params);
@@ -2203,15 +2138,12 @@ postgres_insert_denomination_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
TALER_PQ_query_param_amount (denom_balance),
TALER_PQ_query_param_amount (deposit_fee_balance),
TALER_PQ_query_param_amount (melt_fee_balance),
TALER_PQ_query_param_amount (refund_fee_balance),
-
GNUNET_PQ_query_param_end
};
@@ -2268,15 +2200,12 @@ postgres_update_denomination_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (denom_balance),
TALER_PQ_query_param_amount (deposit_fee_balance),
TALER_PQ_query_param_amount (melt_fee_balance),
TALER_PQ_query_param_amount (refund_fee_balance),
-
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
@@ -2321,10 +2250,10 @@ postgres_get_denomination_summary (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"total_liabilities_select",
params);
@@ -2384,12 +2313,9 @@ postgres_insert_risk_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
TALER_PQ_query_param_amount (risk),
-
GNUNET_PQ_query_param_end
};
@@ -2428,12 +2354,9 @@ postgres_update_risk_summary (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (risk),
-
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
@@ -2472,10 +2395,10 @@ postgres_get_risk_summary (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"total_risk_select",
params);
@@ -2544,18 +2467,14 @@ postgres_insert_historic_denom_revenue (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
-
GNUNET_PQ_query_param_auto_from_type (&revenue_timestamp),
-
TALER_PQ_query_param_amount (revenue_balance),
TALER_PQ_query_param_amount (deposit_fee_balance),
TALER_PQ_query_param_amount (melt_fee_balance),
TALER_PQ_query_param_amount (refund_fee_balance),
-
GNUNET_PQ_query_param_end
};
@@ -2608,10 +2527,10 @@ postgres_select_historic_denom_revenue (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"historic_denomination_revenue_select",
params);
@@ -2640,19 +2559,16 @@ postgres_select_historic_denom_revenue (void *cls,
struct TALER_Amount deposit_fee_balance;
struct TALER_Amount melt_fee_balance;
struct TALER_Amount refund_fee_balance;
-
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", &denom_pub_hash),
-
GNUNET_PQ_result_spec_auto_from_type ("revenue_timestamp", &revenue_timestamp),
-
TALER_PQ_result_spec_amount ("revenue_balance", &revenue_balance),
TALER_PQ_result_spec_amount ("deposit_fee_balance", &deposit_fee_balance),
TALER_PQ_result_spec_amount ("melt_fee_balance", &melt_fee_balance),
TALER_PQ_result_spec_amount ("refund_fee_balance", &refund_fee_balance),
-
GNUNET_PQ_result_spec_end
};
+
if (GNUNET_OK !=
GNUNET_PQ_extract_result (result, rs, 0))
{
@@ -2707,15 +2623,11 @@ postgres_insert_historic_losses (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
-
GNUNET_PQ_query_param_auto_from_type (&loss_timestamp),
-
TALER_PQ_query_param_amount (loss_balance),
-
GNUNET_PQ_query_param_end
};
@@ -2756,10 +2668,10 @@ postgres_select_historic_losses (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"historic_losses_select",
params);
@@ -2841,15 +2753,11 @@ postgres_insert_historic_reserve_revenue (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_auto_from_type (&start_time),
GNUNET_PQ_query_param_auto_from_type (&end_time),
-
TALER_PQ_query_param_amount (reserve_profits),
-
GNUNET_PQ_query_param_end
};
@@ -2889,10 +2797,10 @@ postgres_select_historic_reserve_revenue (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"historic_reserve_summary_select",
params);
@@ -2922,9 +2830,7 @@ postgres_select_historic_reserve_revenue (void *cls,
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("start_date", &start_date),
GNUNET_PQ_result_spec_auto_from_type ("end_date", &end_date),
-
TALER_PQ_result_spec_amount ("reserve_profits", &reserve_profits),
-
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
@@ -2970,11 +2876,9 @@ postgres_insert_predicted_result (void *cls,
{
PGresult *result;
int ret;
-
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
TALER_PQ_query_param_amount (balance),
-
GNUNET_PQ_query_param_end
};
@@ -3017,7 +2921,6 @@ postgres_update_predicted_result (void *cls,
struct GNUNET_PQ_QueryParam params[] = {
TALER_PQ_query_param_amount (balance),
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
@@ -3056,10 +2959,10 @@ postgres_get_predicted_balance (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (master_pub),
-
GNUNET_PQ_query_param_end
};
PGresult *result;
+
result = GNUNET_PQ_exec_prepared (session->conn,
"predicted_result_select",
params);
@@ -3113,7 +3016,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
const char *ec;
pg = GNUNET_new (struct PostgresClosure);
-
if (0 != pthread_key_create (&pg->db_conn_threadlocal,
&db_conn_destroy))
{
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
index 93c279384..5f110865d 100644
--- a/src/auditordb/test_auditordb.c
+++ b/src/auditordb/test_auditordb.c
@@ -201,52 +201,43 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_auditor_progress\n");
- uint64_t
- last_reserve_in_serial_id = 1234,
- last_reserve_out_serial_id = 5678,
- last_deposit_serial_id = 123,
- last_melt_serial_id = 456,
- last_refund_serial_id = 789,
- last_prewire_serial_id = 555,
-
- last_reserve_in_serial_id2 = 0,
- last_reserve_out_serial_id2 = 0,
- last_deposit_serial_id2 = 0,
- last_melt_serial_id2 = 0,
- last_refund_serial_id2 = 0,
- last_prewire_serial_id2 = 0;
+ struct TALER_AUDITORDB_ProgressPoint pp = {
+ .last_reserve_in_serial_id = 1234,
+ .last_reserve_out_serial_id = 5678,
+ .last_deposit_serial_id = 123,
+ .last_melt_serial_id = 456,
+ .last_refund_serial_id = 789,
+ .last_prewire_serial_id = 555
+ };
+ struct TALER_AUDITORDB_ProgressPoint pp2 = {
+ .last_reserve_in_serial_id = 0,
+ .last_reserve_out_serial_id = 0,
+ .last_deposit_serial_id = 0,
+ .last_melt_serial_id = 0,
+ .last_refund_serial_id = 0,
+ .last_prewire_serial_id = 0
+ };
FAILIF (GNUNET_OK !=
plugin->insert_auditor_progress (plugin->cls,
session,
&master_pub,
- last_reserve_in_serial_id,
- last_reserve_out_serial_id,
- last_deposit_serial_id,
- last_melt_serial_id,
- last_refund_serial_id,
- last_prewire_serial_id));
-
+ &pp));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_auditor_progress\n");
- last_reserve_in_serial_id++;
- last_reserve_out_serial_id++;
- last_deposit_serial_id2++;
- last_melt_serial_id2++;
- last_refund_serial_id2++;
- last_prewire_serial_id2++;
+ pp.last_reserve_in_serial_id++;
+ pp.last_reserve_out_serial_id++;
+ pp.last_deposit_serial_id++;
+ pp.last_melt_serial_id++;
+ pp.last_refund_serial_id++;
+ pp.last_prewire_serial_id++;
FAILIF (GNUNET_OK !=
plugin->update_auditor_progress (plugin->cls,
session,
&master_pub,
- last_reserve_in_serial_id,
- last_reserve_out_serial_id,
- last_deposit_serial_id,
- last_melt_serial_id,
- last_refund_serial_id,
- last_prewire_serial_id));
+ &pp));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_auditor_progress\n");
@@ -255,19 +246,13 @@ run (void *cls)
plugin->get_auditor_progress (plugin->cls,
session,
&master_pub,
- &last_reserve_in_serial_id2,
- &last_reserve_out_serial_id2,
- &last_deposit_serial_id2,
- &last_melt_serial_id2,
- &last_refund_serial_id2,
- &last_prewire_serial_id2));
-
- FAILIF (last_reserve_in_serial_id2 != last_reserve_in_serial_id
- || last_reserve_out_serial_id2 != last_reserve_out_serial_id
- || last_deposit_serial_id2 != last_deposit_serial_id
- || last_melt_serial_id2 != last_melt_serial_id
- || last_refund_serial_id2 != last_refund_serial_id
- || last_prewire_serial_id2 != last_prewire_serial_id);
+ &pp2));
+ FAILIF ( (pp.last_reserve_in_serial_id != pp2.last_reserve_in_serial_id) ||
+ (pp.last_reserve_out_serial_id != pp2.last_reserve_out_serial_id) ||
+ (pp.last_deposit_serial_id != pp2.last_deposit_serial_id) ||
+ (pp.last_melt_serial_id != pp2.last_melt_serial_id) ||
+ (pp.last_refund_serial_id != pp2.last_refund_serial_id) ||
+ (pp.last_prewire_serial_id != pp2.last_prewire_serial_id) );
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_reserve_info\n");
@@ -290,14 +275,14 @@ run (void *cls)
&reserve_balance,
&withdraw_fee_balance,
past,
- last_reserve_in_serial_id,
- last_reserve_out_serial_id));
+ pp.last_reserve_in_serial_id,
+ pp.last_reserve_out_serial_id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_reserve_info\n");
- last_reserve_in_serial_id++;
- last_reserve_out_serial_id++;
+ pp.last_reserve_in_serial_id++;
+ pp.last_reserve_out_serial_id++;
FAILIF (GNUNET_OK !=
plugin->update_reserve_info (plugin->cls,
@@ -307,8 +292,8 @@ run (void *cls)
&reserve_balance,
&withdraw_fee_balance,
future,
- last_reserve_in_serial_id,
- last_reserve_out_serial_id));
+ pp.last_reserve_in_serial_id,
+ pp.last_reserve_out_serial_id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_reserve_info\n");
@@ -321,14 +306,14 @@ run (void *cls)
&reserve_balance2,
&withdraw_fee_balance2,
&date,
- &last_reserve_in_serial_id2,
- &last_reserve_out_serial_id2));
+ &pp2.last_reserve_in_serial_id,
+ &pp2.last_reserve_out_serial_id));
FAILIF (0 != memcmp (&date, &future, sizeof (future))
|| 0 != memcmp (&reserve_balance2, &reserve_balance, sizeof (reserve_balance))
|| 0 != memcmp (&withdraw_fee_balance2, &withdraw_fee_balance, sizeof (withdraw_fee_balance))
- || last_reserve_in_serial_id2 != last_reserve_in_serial_id
- || last_reserve_out_serial_id2 != last_reserve_out_serial_id);
+ || pp2.last_reserve_in_serial_id != pp.last_reserve_in_serial_id
+ || pp2.last_reserve_out_serial_id != pp.last_reserve_out_serial_id);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_reserve_summary\n");
@@ -393,18 +378,18 @@ run (void *cls)
&melt_fee_balance,
&deposit_fee_balance,
&denom_balance,
- last_reserve_out_serial_id,
- last_deposit_serial_id,
- last_melt_serial_id,
- last_refund_serial_id));
+ pp.last_reserve_out_serial_id,
+ pp.last_deposit_serial_id,
+ pp.last_melt_serial_id,
+ pp.last_refund_serial_id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: update_denomination_balance\n");
- last_reserve_out_serial_id++;
- last_deposit_serial_id++;
- last_melt_serial_id++;
- last_refund_serial_id++;
+ pp.last_reserve_out_serial_id++;
+ pp.last_deposit_serial_id++;
+ pp.last_melt_serial_id++;
+ pp.last_refund_serial_id++;
FAILIF (GNUNET_OK !=
plugin->update_denomination_balance (plugin->cls,
@@ -414,10 +399,10 @@ run (void *cls)
&deposit_fee_balance,
&melt_fee_balance,
&refund_fee_balance,
- last_reserve_out_serial_id,
- last_deposit_serial_id,
- last_melt_serial_id,
- last_refund_serial_id));
+ pp.last_reserve_out_serial_id,
+ pp.last_deposit_serial_id,
+ pp.last_melt_serial_id,
+ pp.last_refund_serial_id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: get_denomination_balance\n");
@@ -430,19 +415,19 @@ run (void *cls)
&deposit_fee_balance2,
&melt_fee_balance2,
&refund_fee_balance2,
- &last_reserve_out_serial_id2,
- &last_deposit_serial_id2,
- &last_melt_serial_id2,
- &last_refund_serial_id2));
+ &pp2.last_reserve_out_serial_id,
+ &pp2.last_deposit_serial_id,
+ &pp2.last_melt_serial_id,
+ &pp2.last_refund_serial_id));
FAILIF (0 != memcmp (&denom_balance2, &denom_balance, sizeof (denom_balance))
|| 0 != memcmp (&deposit_fee_balance2, &deposit_fee_balance, sizeof (deposit_fee_balance))
|| 0 != memcmp (&melt_fee_balance2, &melt_fee_balance, sizeof (melt_fee_balance))
|| 0 != memcmp (&refund_fee_balance2, &refund_fee_balance, sizeof (refund_fee_balance))
- || last_reserve_out_serial_id2 != last_reserve_out_serial_id
- || last_deposit_serial_id2 != last_deposit_serial_id
- || last_melt_serial_id2 != last_melt_serial_id
- || last_refund_serial_id2 != last_refund_serial_id);
+ || pp2.last_reserve_out_serial_id != pp.last_reserve_out_serial_id
+ || pp2.last_deposit_serial_id != pp.last_deposit_serial_id
+ || pp2.last_melt_serial_id != pp.last_melt_serial_id
+ || pp2.last_refund_serial_id != pp.last_refund_serial_id);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_denomination_summary\n");
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index fa5f9e816..dfec1c76e 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -113,6 +113,49 @@ typedef int
/**
+ * Structure for remembering the auditor's progress over the
+ * various tables and (auditor) transactions.
+ */
+struct TALER_AUDITORDB_ProgressPoint
+{
+ /**
+ * last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
+ */
+ uint64_t last_reserve_in_serial_id;
+
+ /**
+ * last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
+ */
+ uint64_t last_reserve_out_serial_id;
+
+ /**
+ * last_deposit_serial_id serial ID of the last deposit the auditor processed
+ */
+ uint64_t last_deposit_serial_id;
+
+ /**
+ * last_melt_serial_id serial ID of the last refresh the auditor processed
+ */
+ uint64_t last_melt_serial_id;
+
+ /**
+ * last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ */
+ uint64_t last_refund_serial_id;
+
+ /**
+ * last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ */
+ uint64_t last_prewire_serial_id;
+
+ // FIXME: the above does not quite work, as independent transactions
+ // touch certain tables (i.e. reserves_out), so we need some of
+ // these counters more than once!
+
+};
+
+
+/**
* Handle for one session with the database.
*/
struct TALER_AUDITORDB_Session;
@@ -252,10 +295,6 @@ struct TALER_AUDITORDB_Plugin
void *cb_cls);
- // FIXME: this does not quite work, as independent transactions
- // touch certain tables (i.e. reserves_out), so we need some of
- // these counters more than once!
- // ALSO: put all of these counters into a struct, this is very ugly...
/**
* Insert information about the auditor's progress with an exchange's
* data.
@@ -263,23 +302,14 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param pp where is the auditor in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
(*insert_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t last_reserve_in_serial_id,
- uint64_t last_reserve_out_serial_id,
- uint64_t last_deposit_serial_id,
- uint64_t last_melt_serial_id,
- uint64_t last_refund_serial_id,
- uint64_t last_prewire_serial_id);
+ const struct TALER_AUDITORDB_ProgressPoint *pp);
/**
@@ -289,23 +319,14 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param pp where is the auditor in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure
*/
int
(*update_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t last_reserve_in_serial_id,
- uint64_t last_reserve_out_serial_id,
- uint64_t last_deposit_serial_id,
- uint64_t last_melt_serial_id,
- uint64_t last_refund_serial_id,
- uint64_t last_prewire_serial_id);
+ const struct TALER_AUDITORDB_ProgressPoint *pp);
/**
@@ -314,11 +335,7 @@ struct TALER_AUDITORDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use
* @param master_pub master key of the exchange
- * @param[out] last_reserve_in_serial_id serial ID of the last reserve_in transfer the auditor processed
- * @param[out] last_reserve_out_serial_id serial ID of the last withdraw the auditor processed
- * @param[out] last_deposit_serial_id serial ID of the last deposit the auditor processed
- * @param[out] last_melt_serial_id serial ID of the last refresh the auditor processed
- * @param[out] last_prewire_serial_id serial ID of the last prewire transfer the auditor processed
+ * @param[out] pp set to where the auditor is in processing
* @return #GNUNET_OK on success; #GNUNET_SYSERR on failure;
* #GNUNET_NO if we have no records for the @a master_pub
*/
@@ -326,12 +343,7 @@ struct TALER_AUDITORDB_Plugin
(*get_auditor_progress)(void *cls,
struct TALER_AUDITORDB_Session *session,
const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t *last_reserve_in_serial_id,
- uint64_t *last_reserve_out_serial_id,
- uint64_t *last_deposit_serial_id,
- uint64_t *last_melt_serial_id,
- uint64_t *last_refund_serial_id,
- uint64_t *last_prewire_serial_id);
+ struct TALER_AUDITORDB_ProgressPoint *pp);
/**