diff options
Diffstat (limited to 'src/mint/mint_db.c')
-rw-r--r-- | src/mint/mint_db.c | 60 |
1 files changed, 60 insertions, 0 deletions
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) | |||
848 | } | 848 | } |
849 | 849 | ||
850 | 850 | ||
851 | /** | ||
852 | * Get the summary of a reserve. | ||
853 | * | ||
854 | * @param db the database connection handle | ||
855 | * @param reserve_pub the public key identifying the reserve | ||
856 | * @param balance the amount existing in the reserve (will be filled) | ||
857 | * @param expiry expiration of the reserve (will be filled) | ||
858 | * @return #GNUNET_OK upon success; #GNUNET_NO when the given reserve is not | ||
859 | * found; #GNUNET_SYSERR upon failure | ||
860 | */ | ||
861 | int | ||
862 | TALER_MINT_DB_reserve_get (PGconn *db, | ||
863 | struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, | ||
864 | struct TALER_Amount *balance, | ||
865 | struct GNUNET_TIME_Absolute *expiry) | ||
866 | { | ||
867 | PGresult *result; | ||
868 | uint64_t expiration_date_nbo; | ||
869 | struct TALER_DB_QueryParam params[] = { | ||
870 | TALER_DB_QUERY_PARAM_PTR(reserve_pub), | ||
871 | TALER_DB_QUERY_PARAM_END | ||
872 | }; | ||
873 | |||
874 | result = TALER_DB_exec_prepared (db, | ||
875 | "get_reserve", | ||
876 | params); | ||
877 | if (PGRES_TUPLES_OK != PQresultStatus (result)) | ||
878 | { | ||
879 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
880 | "Query failed: %s\n", | ||
881 | PQresultErrorMessage (result)); | ||
882 | PQclear (result); | ||
883 | return GNUNET_SYSERR; | ||
884 | } | ||
885 | if (0 == PQntuples (result)) | ||
886 | { | ||
887 | PQclear (result); | ||
888 | return GNUNET_NO; | ||
889 | } | ||
890 | struct TALER_DB_ResultSpec rs[] = { | ||
891 | TALER_DB_RESULT_SPEC("expiration_date", &expiration_date_nbo), | ||
892 | TALER_DB_RESULT_SPEC_END | ||
893 | }; | ||
894 | EXITIF (GNUNET_OK != TALER_DB_extract_result (result, rs, 0)); | ||
895 | EXITIF (GNUNET_OK != | ||
896 | TALER_DB_extract_amount (result, 0, | ||
897 | "current_balance_value", | ||
898 | "current_balance_fraction", | ||
899 | "current_balance_currency", | ||
900 | balance)); | ||
901 | expiry->abs_value_us = GNUNET_ntohll (expiration_date_nbo); | ||
902 | PQclear (result); | ||
903 | return GNUNET_OK; | ||
904 | |||
905 | EXITIF_exit: | ||
906 | PQclear (result); | ||
907 | return GNUNET_SYSERR; | ||
908 | } | ||
909 | |||
910 | |||
851 | 911 | ||
852 | 912 | ||
853 | 913 | ||