Use a reserve structure

This commit is contained in:
Sree Harsha Totakura 2015-03-05 16:31:33 +01:00
parent 2ac21b6329
commit 494e71b9a6
2 changed files with 39 additions and 17 deletions

View File

@ -852,25 +852,27 @@ TALER_MINT_DB_commit (PGconn *db_conn)
* Get the summary of a reserve. * Get the summary of a reserve.
* *
* @param db the database connection handle * @param db the database connection handle
* @param reserve_pub the public key identifying the reserve * @param reserve the reserve data. The public key of the reserve should be set
* @param balance the amount existing in the reserve (will be filled) * in this structure; it is used to query the database. The balance
* @param expiry expiration of the reserve (will be filled) * and expiration are then filled accordingly.
* @return #GNUNET_OK upon success; #GNUNET_NO when the given reserve is not * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
* found; #GNUNET_SYSERR upon failure
*/ */
int int
TALER_MINT_DB_reserve_get (PGconn *db, TALER_MINT_DB_reserve_get (PGconn *db,
struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, struct Reserve *reserve)
struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute *expiry)
{ {
PGresult *result; PGresult *result;
uint64_t expiration_date_nbo; uint64_t expiration_date_nbo;
struct TALER_DB_QueryParam params[] = { struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR(reserve_pub), TALER_DB_QUERY_PARAM_PTR(reserve->pub),
TALER_DB_QUERY_PARAM_END TALER_DB_QUERY_PARAM_END
}; };
if (NULL == reserve->pub)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
result = TALER_DB_exec_prepared (db, result = TALER_DB_exec_prepared (db,
"get_reserve", "get_reserve",
params); params);
@ -897,8 +899,8 @@ TALER_MINT_DB_reserve_get (PGconn *db,
"current_balance_value", "current_balance_value",
"current_balance_fraction", "current_balance_fraction",
"current_balance_currency", "current_balance_currency",
balance)); &reserve->balance));
expiry->abs_value_us = GNUNET_ntohll (expiration_date_nbo); reserve->expiry.abs_value_us = GNUNET_ntohll (expiration_date_nbo);
PQclear (result); PQclear (result);
return GNUNET_OK; return GNUNET_OK;

View File

@ -137,6 +137,27 @@ struct BankTransfer
/* FIXME: add functions to add bank transfers to our DB /* FIXME: add functions to add bank transfers to our DB
(and to test if we already did add one) (#3633) */ (and to test if we already did add one) (#3633) */
/**
* A summary of a Reserve
*/
struct Reserve
{
/**
* The reserve's public key. This uniquely identifies the reserve
*/
struct GNUNET_CRYPTO_EddsaPublicKey *pub;
/**
* The balance amount existing in the reserve
*/
struct TALER_Amount balance;
/**
* The expiration date of this reserve
*/
struct GNUNET_TIME_Absolute expiry;
};
/** /**
* Information we keep for a withdrawn coin to reproduce * Information we keep for a withdrawn coin to reproduce
@ -173,16 +194,15 @@ struct CollectableBlindcoin
* Get the summary of a reserve. * Get the summary of a reserve.
* *
* @param db the database connection handle * @param db the database connection handle
* @param reserve_pub the public key identifying the reserve * @param reserve the reserve data. The public key of the reserve should be set
* @param balance the amount existing in the reserve (will be filled) * in this structure; it is used to query the database. The balance
* @param expiry expiration of the reserve (will be filled) * and expiration are then filled accordingly.
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/ */
int int
TALER_MINT_DB_reserve_get (PGconn *db, TALER_MINT_DB_reserve_get (PGconn *db,
struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, struct Reserve *reserve);
struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute *expiry);
/* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */