a bit more work on #5010

This commit is contained in:
Christian Grothoff 2017-06-11 02:12:56 +02:00
parent cad64767d9
commit a57cf67f31
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 42 additions and 60 deletions

View File

@ -1085,15 +1085,17 @@ verify_reserve_balance (void *cls,
struct ReserveSummary *rs = value; struct ReserveSummary *rs = value;
struct TALER_EXCHANGEDB_Reserve reserve; struct TALER_EXCHANGEDB_Reserve reserve;
struct TALER_Amount balance; struct TALER_Amount balance;
enum GNUNET_DB_QueryStatus qs;
int ret; int ret;
ret = GNUNET_OK; ret = GNUNET_OK;
reserve.pub = rs->reserve_pub; reserve.pub = rs->reserve_pub;
if (GNUNET_OK != qs = edb->reserve_get (edb->cls,
edb->reserve_get (edb->cls, esession,
esession, &reserve);
&reserve)) if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{ {
/* FIXME: may we have to deal with soft errors here? */
char *diag; char *diag;
GNUNET_asprintf (&diag, GNUNET_asprintf (&diag,

View File

@ -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 * @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 * set in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly. * and expiration are then filled accordingly.
* @return #GNUNET_OK upon success; * @return transaction status
* #GNUNET_NO if there were no results (but no hard failure)
* #GNUNET_SYSERR upon failure
*/ */
static int static enum GNUNET_DB_QueryStatus
postgres_reserve_get (void *cls, postgres_reserve_get (void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
struct TALER_EXCHANGEDB_Reserve *reserve) struct TALER_EXCHANGEDB_Reserve *reserve)
{ {
PGresult *result;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type(&reserve->pub), GNUNET_PQ_query_param_auto_from_type(&reserve->pub),
GNUNET_PQ_query_param_end 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, return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
"reserve_get", "reserve_get",
params); params,
if (PGRES_TUPLES_OK != PQresultStatus (result)) rs);
{
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;
} }
@ -2075,7 +2049,7 @@ postgres_reserves_in_insert (void *cls,
{ {
struct PostgresClosure *pg = cls; struct PostgresClosure *pg = cls;
PGresult *result; PGresult *result;
int reserve_exists; enum GNUNET_DB_QueryStatus reserve_exists;
struct TALER_EXCHANGEDB_Reserve reserve; struct TALER_EXCHANGEDB_Reserve reserve;
struct GNUNET_TIME_Absolute expiry; struct GNUNET_TIME_Absolute expiry;
@ -2090,7 +2064,7 @@ postgres_reserves_in_insert (void *cls,
reserve_exists = postgres_reserve_get (cls, reserve_exists = postgres_reserve_get (cls,
session, session,
&reserve); &reserve);
if (GNUNET_SYSERR == reserve_exists) if (0 > reserve_exists)
{ {
GNUNET_break (0); GNUNET_break (0);
goto rollback; goto rollback;
@ -2115,7 +2089,7 @@ postgres_reserves_in_insert (void *cls,
expiry = GNUNET_TIME_absolute_add (execution_time, expiry = GNUNET_TIME_absolute_add (execution_time,
pg->idle_reserve_expiration_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 /* New reserve, create balance for the first time; we do this
before adding the actual transaction to "reserves_in", as before adding the actual transaction to "reserves_in", as
@ -2188,7 +2162,7 @@ postgres_reserves_in_insert (void *cls,
} }
PQclear (result); 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 /* If the reserve already existed, we need to still update the
balance; we do this after checking for duplication, as balance; we do this after checking for duplication, as
@ -2423,10 +2397,12 @@ postgres_insert_withdraw_info (void *cls,
/* update reserve balance */ /* update reserve balance */
reserve.pub = collectable->reserve_pub; reserve.pub = collectable->reserve_pub;
if (GNUNET_OK != postgres_reserve_get (cls, if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
session, postgres_reserve_get (cls,
&reserve)) session,
&reserve))
{ {
/* FIXME: #5010 */
/* Should have been checked before we got here... */ /* Should have been checked before we got here... */
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
@ -5011,6 +4987,7 @@ postgres_insert_reserve_closed (void *cls,
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
int ret; int ret;
enum GNUNET_DB_QueryStatus qs;
ret = execute_prepared_non_select (session, ret = execute_prepared_non_select (session,
"reserves_close_insert", "reserves_close_insert",
@ -5020,14 +4997,15 @@ postgres_insert_reserve_closed (void *cls,
/* update reserve balance */ /* update reserve balance */
reserve.pub = *reserve_pub; reserve.pub = *reserve_pub;
if (GNUNET_OK != if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
(ret = postgres_reserve_get (cls, (qs = postgres_reserve_get (cls,
session, session,
&reserve))) &reserve)))
{ {
/* FIXME: #5010 */
/* Existence should have been checked before we got here... */ /* Existence should have been checked before we got here... */
GNUNET_break (GNUNET_NO == ret); GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
return ret; return (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ? GNUNET_NO : GNUNET_SYSERR;
} }
ret = TALER_amount_subtract (&reserve.balance, ret = TALER_amount_subtract (&reserve.balance,
&reserve.balance, &reserve.balance,
@ -6239,10 +6217,12 @@ postgres_insert_payback_request (void *cls,
/* Update reserve balance */ /* Update reserve balance */
reserve.pub = *reserve_pub; reserve.pub = *reserve_pub;
if (GNUNET_OK != postgres_reserve_get (cls, if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
session, postgres_reserve_get (cls,
&reserve)) session,
&reserve))
{ {
/* FIXME: #5010 */
/* Should have been checked before we got here... */ /* Should have been checked before we got here... */
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;

View File

@ -163,7 +163,7 @@ check_reserve (struct TALER_EXCHANGEDB_Session *session,
reserve.pub = *pub; reserve.pub = *pub;
FAILIF (GNUNET_OK != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserve_get (plugin->cls, plugin->reserve_get (plugin->cls,
session, session,
&reserve)); &reserve));

View File

@ -1168,9 +1168,9 @@ struct TALER_EXCHANGEDB_Plugin
* @param[in,out] reserve the reserve data. The public key of the reserve should be set * @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 * in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly. * 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, (*reserve_get) (void *cls,
struct TALER_EXCHANGEDB_Session *db, struct TALER_EXCHANGEDB_Session *db,
struct TALER_EXCHANGEDB_Reserve *reserve); struct TALER_EXCHANGEDB_Reserve *reserve);