From 363773698ae164bcdbf822a75b692b15940d27b1 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Thu, 5 Mar 2015 16:16:38 +0100 Subject: [PATCH] db: Add DB_reserve_get() to get a summary of the reserve --- src/mint/mint_db.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/mint/mint_db.h | 16 +++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index 268b22a00..b9f30ac3f 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c @@ -848,6 +848,66 @@ TALER_MINT_DB_commit (PGconn *db_conn) } +/** + * Get the summary of a reserve. + * + * @param db the database connection handle + * @param reserve_pub the public key identifying the reserve + * @param balance the amount existing in the reserve (will be filled) + * @param expiry expiration of the reserve (will be filled) + * @return #GNUNET_OK upon success; #GNUNET_NO when the given reserve is not + * found; #GNUNET_SYSERR upon failure + */ +int +TALER_MINT_DB_reserve_get (PGconn *db, + struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, + struct TALER_Amount *balance, + struct GNUNET_TIME_Absolute *expiry) +{ + PGresult *result; + uint64_t expiration_date_nbo; + struct TALER_DB_QueryParam params[] = { + TALER_DB_QUERY_PARAM_PTR(reserve_pub), + TALER_DB_QUERY_PARAM_END + }; + + result = TALER_DB_exec_prepared (db, + "get_reserve", + params); + if (PGRES_TUPLES_OK != PQresultStatus (result)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Query failed: %s\n", + PQresultErrorMessage (result)); + PQclear (result); + return GNUNET_SYSERR; + } + if (0 == PQntuples (result)) + { + PQclear (result); + return GNUNET_NO; + } + struct TALER_DB_ResultSpec rs[] = { + TALER_DB_RESULT_SPEC("expiration_date", &expiration_date_nbo), + TALER_DB_RESULT_SPEC_END + }; + EXITIF (GNUNET_OK != TALER_DB_extract_result (result, rs, 0)); + EXITIF (GNUNET_OK != + TALER_DB_extract_amount (result, 0, + "current_balance_value", + "current_balance_fraction", + "current_balance_currency", + balance)); + expiry->abs_value_us = GNUNET_ntohll (expiration_date_nbo); + PQclear (result); + return GNUNET_OK; + + EXITIF_exit: + PQclear (result); + return GNUNET_SYSERR; +} + + diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h index b36823803..b80f750b0 100644 --- a/src/mint/mint_db.h +++ b/src/mint/mint_db.h @@ -169,6 +169,22 @@ struct CollectableBlindcoin }; +/** + * Get the summary of a reserve. + * + * @param db the database connection handle + * @param reserve_pub the public key identifying the reserve + * @param balance the amount existing in the reserve (will be filled) + * @param expiry expiration of the reserve (will be filled) + * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure + */ +int +TALER_MINT_DB_reserve_get (PGconn *db, + struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, + struct TALER_Amount *balance, + struct GNUNET_TIME_Absolute *expiry); + + /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */