fixing misc auditor issues
This commit is contained in:
parent
7115eda899
commit
a38fa32484
File diff suppressed because it is too large
Load Diff
@ -26,13 +26,17 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <libpq-fe.h>
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a query error.
|
* Log a query error.
|
||||||
*
|
*
|
||||||
* @param result PQ result object of the query that failed
|
* @param result PQ result object of the query that failed
|
||||||
*/
|
*/
|
||||||
#define QUERY_ERR(result) \
|
#define QUERY_ERR(result) \
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed at %s:%u: %s (%s)\n", __FILE__, __LINE__, PQresultErrorMessage (result), PQresStatus (PQresultStatus (result)))
|
LOG (GNUNET_ERROR_TYPE_ERROR, "Query failed at %s:%u: %s (%s)\n", __FILE__, __LINE__, PQresultErrorMessage (result), PQresStatus (PQresultStatus (result)))
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +46,7 @@
|
|||||||
*/
|
*/
|
||||||
#define BREAK_DB_ERR(result) do { \
|
#define BREAK_DB_ERR(result) do { \
|
||||||
GNUNET_break (0); \
|
GNUNET_break (0); \
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Database failure: %s (%s)\n", PQresultErrorMessage (result), PQresStatus (PQresultStatus (result))); \
|
LOG (GNUNET_ERROR_TYPE_ERROR, "Database failure: %s (%s)\n", PQresultErrorMessage (result), PQresStatus (PQresultStatus (result))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@ -152,10 +156,9 @@ static void
|
|||||||
pq_notice_processor_cb (void *arg,
|
pq_notice_processor_cb (void *arg,
|
||||||
const char *message)
|
const char *message)
|
||||||
{
|
{
|
||||||
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
|
LOG (GNUNET_ERROR_TYPE_INFO,
|
||||||
"pq",
|
"%s",
|
||||||
"%s",
|
message);
|
||||||
message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -205,10 +208,30 @@ postgres_drop_tables (void *cls)
|
|||||||
conn = connect_to_postgres (pc);
|
conn = connect_to_postgres (pc);
|
||||||
if (NULL == conn)
|
if (NULL == conn)
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
LOG (GNUNET_ERROR_TYPE_INFO,
|
||||||
"Dropping ALL tables\n");
|
"Dropping ALL tables\n");
|
||||||
|
/* TODO: we probably need a bit more fine-grained control
|
||||||
|
over drops for the '-r' option of taler-auditor; also,
|
||||||
|
for the testcase, we currently fail to drop the
|
||||||
|
auditor_denominations table... */
|
||||||
SQLEXEC_ (conn,
|
SQLEXEC_ (conn,
|
||||||
"DROP TABLE IF EXISTS test;");
|
"DROP TABLE IF EXISTS predicted_result;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS historic_ledger;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS historic_losses;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS historic_denomination_revenue;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS balance_summary;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS denomination_pending;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS auditor_reserve_balance;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS auditor_reserves;");
|
||||||
|
SQLEXEC_ (conn,
|
||||||
|
"DROP TABLE IF EXISTS auditor_progress;");
|
||||||
PQfinish (conn);
|
PQfinish (conn);
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
SQLEXEC_fail:
|
SQLEXEC_fail:
|
||||||
@ -944,7 +967,7 @@ postgres_start (void *cls,
|
|||||||
PQresultStatus (result))
|
PQresultStatus (result))
|
||||||
{
|
{
|
||||||
TALER_LOG_ERROR ("Failed to start transaction: %s\n",
|
TALER_LOG_ERROR ("Failed to start transaction: %s\n",
|
||||||
PQresultErrorMessage (result));
|
PQresultErrorMessage (result));
|
||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
@ -1016,9 +1039,9 @@ postgres_commit (void *cls,
|
|||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
LOG (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Database commit failure: %s\n",
|
"Database commit failure: %s\n",
|
||||||
sqlstate);
|
sqlstate);
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
@ -1175,8 +1198,8 @@ postgres_select_denomination_info (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_select_denomination_info() returned 0 matching rows\n");
|
"postgres_select_denomination_info() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -1357,8 +1380,8 @@ postgres_get_auditor_progress (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_auditor_progress() returned 0 matching rows\n");
|
"postgres_get_auditor_progress() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -1574,8 +1597,8 @@ postgres_get_reserve_info (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_reserve_info() returned 0 matching rows\n");
|
"postgres_get_reserve_info() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -1732,8 +1755,8 @@ postgres_get_reserve_summary (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_reserve_summary() returned 0 matching rows\n");
|
"postgres_get_reserve_summary() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -1882,8 +1905,8 @@ postgres_get_denomination_balance (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_denomination_balance() returned 0 matching rows\n");
|
"postgres_get_denomination_balance() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -2068,8 +2091,8 @@ postgres_get_balance_summary (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_balance_summary() returned 0 matching rows\n");
|
"postgres_get_balance_summary() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -2183,8 +2206,8 @@ postgres_select_historic_denom_revenue (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_select_historic_denom_revenue() returned 0 matching rows\n");
|
"postgres_select_historic_denom_revenue() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -2315,8 +2338,8 @@ postgres_select_historic_losses (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_select_historic_losses() returned 0 matching rows\n");
|
"postgres_select_historic_losses() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -2444,8 +2467,8 @@ postgres_select_historic_reserve_revenue (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_select_historic_reserve_revenue() returned 0 matching rows\n");
|
"postgres_select_historic_reserve_revenue() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
@ -2605,8 +2628,8 @@ postgres_get_predicted_balance (void *cls,
|
|||||||
int nrows = PQntuples (result);
|
int nrows = PQntuples (result);
|
||||||
if (0 == nrows)
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
LOG (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"postgres_get_predicted_balance() returned 0 matching rows\n");
|
"postgres_get_predicted_balance() returned 0 matching rows\n");
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
|
@ -297,6 +297,18 @@ TALER_amount_normalize (struct TALER_Amount *amount);
|
|||||||
char *
|
char *
|
||||||
TALER_amount_to_string (const struct TALER_Amount *amount);
|
TALER_amount_to_string (const struct TALER_Amount *amount);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert amount to string.
|
||||||
|
*
|
||||||
|
* @param amount amount to convert to string
|
||||||
|
* @return statically allocated buffer with string representation,
|
||||||
|
* NULL if the @a amount was invalid
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
TALER_amount2s (const struct TALER_Amount *amount);
|
||||||
|
|
||||||
|
|
||||||
#if 0 /* keep Emacsens' auto-indent happy */
|
#if 0 /* keep Emacsens' auto-indent happy */
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
@ -529,9 +529,9 @@ char *
|
|||||||
TALER_amount_to_string (const struct TALER_Amount *amount)
|
TALER_amount_to_string (const struct TALER_Amount *amount)
|
||||||
{
|
{
|
||||||
char *result;
|
char *result;
|
||||||
|
unsigned int i;
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||||
unsigned int i;
|
|
||||||
struct TALER_Amount norm;
|
struct TALER_Amount norm;
|
||||||
|
|
||||||
if (GNUNET_YES != TALER_amount_is_valid (amount))
|
if (GNUNET_YES != TALER_amount_is_valid (amount))
|
||||||
@ -564,6 +564,54 @@ TALER_amount_to_string (const struct TALER_Amount *amount)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert amount to string.
|
||||||
|
*
|
||||||
|
* @param amount amount to convert to string
|
||||||
|
* @return statically allocated buffer with string representation,
|
||||||
|
* NULL if the @a amount was invalid
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
TALER_amount2s (const struct TALER_Amount *amount)
|
||||||
|
{
|
||||||
|
static char result[TALER_AMOUNT_FRAC_LEN + TALER_CURRENCY_LEN + 3 + 12];
|
||||||
|
unsigned int i;
|
||||||
|
uint32_t n;
|
||||||
|
char tail[TALER_AMOUNT_FRAC_LEN + 1];
|
||||||
|
struct TALER_Amount norm;
|
||||||
|
|
||||||
|
if (GNUNET_YES != TALER_amount_is_valid (amount))
|
||||||
|
return NULL;
|
||||||
|
norm = *amount;
|
||||||
|
GNUNET_break (GNUNET_SYSERR !=
|
||||||
|
TALER_amount_normalize (&norm));
|
||||||
|
if (0 != (n = norm.fraction))
|
||||||
|
{
|
||||||
|
for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
|
||||||
|
{
|
||||||
|
tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
|
||||||
|
n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
|
||||||
|
}
|
||||||
|
tail[i] = '\0';
|
||||||
|
GNUNET_snprintf (result,
|
||||||
|
sizeof (result),
|
||||||
|
"%s:%llu.%s",
|
||||||
|
norm.currency,
|
||||||
|
(unsigned long long) norm.value,
|
||||||
|
tail);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GNUNET_snprintf (result,
|
||||||
|
sizeof (result),
|
||||||
|
"%s:%llu",
|
||||||
|
norm.currency,
|
||||||
|
(unsigned long long) norm.value);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Divide an amount by a float. Note that this function
|
* Divide an amount by a float. Note that this function
|
||||||
* may introduce a rounding error!
|
* may introduce a rounding error!
|
||||||
|
Loading…
Reference in New Issue
Block a user