aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-06-11 02:12:56 +0200
committerChristian Grothoff <christian@grothoff.org>2017-06-11 02:12:56 +0200
commita57cf67f31e89aab59a39daf3cca35509c5dc8b8 (patch)
treea6db5f3f48ba2504c046d2a356305b25c916b976
parentcad64767d9fda2c18106f25ef101c2eb5fce15a1 (diff)
a bit more work on #5010
-rw-r--r--src/auditor/taler-auditor.c10
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c86
-rw-r--r--src/exchangedb/test_exchangedb.c2
-rw-r--r--src/include/taler_exchangedb_plugin.h4
4 files changed, 42 insertions, 60 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c
index 42a167d06..0d7d0b01a 100644
--- a/src/auditor/taler-auditor.c
+++ b/src/auditor/taler-auditor.c
@@ -1085,15 +1085,17 @@ verify_reserve_balance (void *cls,
struct ReserveSummary *rs = value;
struct TALER_EXCHANGEDB_Reserve reserve;
struct TALER_Amount balance;
+ enum GNUNET_DB_QueryStatus qs;
int ret;
ret = GNUNET_OK;
reserve.pub = rs->reserve_pub;
- if (GNUNET_OK !=
- edb->reserve_get (edb->cls,
- esession,
- &reserve))
+ qs = edb->reserve_get (edb->cls,
+ esession,
+ &reserve);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
+ /* FIXME: may we have to deal with soft errors here? */
char *diag;
GNUNET_asprintf (&diag,
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 2df4630b9..929d982f8 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1967,53 +1967,27 @@ postgres_get_denomination_info (void *cls,
* @param[in,out] reserve the reserve data. The public key of the reserve should be
* set in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly.
- * @return #GNUNET_OK upon success;
- * #GNUNET_NO if there were no results (but no hard failure)
- * #GNUNET_SYSERR upon failure
+ * @return transaction status
*/
-static int
+static enum GNUNET_DB_QueryStatus
postgres_reserve_get (void *cls,
struct TALER_EXCHANGEDB_Session *session,
struct TALER_EXCHANGEDB_Reserve *reserve)
{
- PGresult *result;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type(&reserve->pub),
GNUNET_PQ_query_param_end
};
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
+ GNUNET_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
+ GNUNET_PQ_result_spec_end
+ };
- result = GNUNET_PQ_exec_prepared (session->conn,
- "reserve_get",
- params);
- if (PGRES_TUPLES_OK != PQresultStatus (result))
- {
- QUERY_ERR (result, session->conn);
- PQclear (result);
- return GNUNET_SYSERR;
- }
- if (0 == PQntuples (result))
- {
- PQclear (result);
- return GNUNET_NO;
- }
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
- GNUNET_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
- GNUNET_PQ_result_spec_end
- };
-
- EXITIF (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- 0));
- }
- PQclear (result);
- return GNUNET_OK;
-
- EXITIF_exit:
- PQclear (result);
- return GNUNET_SYSERR;
+ return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+ "reserve_get",
+ params,
+ rs);
}
@@ -2075,7 +2049,7 @@ postgres_reserves_in_insert (void *cls,
{
struct PostgresClosure *pg = cls;
PGresult *result;
- int reserve_exists;
+ enum GNUNET_DB_QueryStatus reserve_exists;
struct TALER_EXCHANGEDB_Reserve reserve;
struct GNUNET_TIME_Absolute expiry;
@@ -2090,7 +2064,7 @@ postgres_reserves_in_insert (void *cls,
reserve_exists = postgres_reserve_get (cls,
session,
&reserve);
- if (GNUNET_SYSERR == reserve_exists)
+ if (0 > reserve_exists)
{
GNUNET_break (0);
goto rollback;
@@ -2115,7 +2089,7 @@ postgres_reserves_in_insert (void *cls,
expiry = GNUNET_TIME_absolute_add (execution_time,
pg->idle_reserve_expiration_time);
- if (GNUNET_NO == reserve_exists)
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == reserve_exists)
{
/* New reserve, create balance for the first time; we do this
before adding the actual transaction to "reserves_in", as
@@ -2188,7 +2162,7 @@ postgres_reserves_in_insert (void *cls,
}
PQclear (result);
- if (GNUNET_YES == reserve_exists)
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == reserve_exists)
{
/* If the reserve already existed, we need to still update the
balance; we do this after checking for duplication, as
@@ -2423,10 +2397,12 @@ postgres_insert_withdraw_info (void *cls,
/* update reserve balance */
reserve.pub = collectable->reserve_pub;
- if (GNUNET_OK != postgres_reserve_get (cls,
- session,
- &reserve))
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ postgres_reserve_get (cls,
+ session,
+ &reserve))
{
+ /* FIXME: #5010 */
/* Should have been checked before we got here... */
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -5011,6 +4987,7 @@ postgres_insert_reserve_closed (void *cls,
GNUNET_PQ_query_param_end
};
int ret;
+ enum GNUNET_DB_QueryStatus qs;
ret = execute_prepared_non_select (session,
"reserves_close_insert",
@@ -5020,14 +4997,15 @@ postgres_insert_reserve_closed (void *cls,
/* update reserve balance */
reserve.pub = *reserve_pub;
- if (GNUNET_OK !=
- (ret = postgres_reserve_get (cls,
- session,
- &reserve)))
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ (qs = postgres_reserve_get (cls,
+ session,
+ &reserve)))
{
+ /* FIXME: #5010 */
/* Existence should have been checked before we got here... */
- GNUNET_break (GNUNET_NO == ret);
- return ret;
+ GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
+ return (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ? GNUNET_NO : GNUNET_SYSERR;
}
ret = TALER_amount_subtract (&reserve.balance,
&reserve.balance,
@@ -6239,10 +6217,12 @@ postgres_insert_payback_request (void *cls,
/* Update reserve balance */
reserve.pub = *reserve_pub;
- if (GNUNET_OK != postgres_reserve_get (cls,
- session,
- &reserve))
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ postgres_reserve_get (cls,
+ session,
+ &reserve))
{
+ /* FIXME: #5010 */
/* Should have been checked before we got here... */
GNUNET_break (0);
return GNUNET_SYSERR;
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 98a095b61..fb52ddf92 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -163,7 +163,7 @@ check_reserve (struct TALER_EXCHANGEDB_Session *session,
reserve.pub = *pub;
- FAILIF (GNUNET_OK !=
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserve_get (plugin->cls,
session,
&reserve));
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 810b66f06..03020f2cc 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1168,9 +1168,9 @@ struct TALER_EXCHANGEDB_Plugin
* @param[in,out] reserve the reserve data. The public key of the reserve should be set
* in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly.
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ * @return transaction status
*/
- int
+ enum GNUNET_DB_QueryStatus
(*reserve_get) (void *cls,
struct TALER_EXCHANGEDB_Session *db,
struct TALER_EXCHANGEDB_Reserve *reserve);