diff options
author | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-05 16:16:38 +0100 |
---|---|---|
committer | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-05 16:16:38 +0100 |
commit | 2ac21b63293a3e40ea5903fc2eed158353068611 (patch) | |
tree | e71fd803a077f8497d6f87e20e4538ad23785e61 | |
parent | 4494cf7b61a6cea7b6db667836259ab70d75637d (diff) | |
download | exchange-2ac21b63293a3e40ea5903fc2eed158353068611.tar.gz exchange-2ac21b63293a3e40ea5903fc2eed158353068611.zip |
Add DB_reserve_get() to get a summary of the reserve
-rw-r--r-- | src/mint/mint_db.c | 60 | ||||
-rw-r--r-- | src/mint/mint_db.h | 16 |
2 files changed, 76 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 | ||
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 | |||
169 | }; | 169 | }; |
170 | 170 | ||
171 | 171 | ||
172 | /** | ||
173 | * Get the summary of a reserve. | ||
174 | * | ||
175 | * @param db the database connection handle | ||
176 | * @param reserve_pub the public key identifying the reserve | ||
177 | * @param balance the amount existing in the reserve (will be filled) | ||
178 | * @param expiry expiration of the reserve (will be filled) | ||
179 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | ||
180 | */ | ||
181 | int | ||
182 | TALER_MINT_DB_reserve_get (PGconn *db, | ||
183 | struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, | ||
184 | struct TALER_Amount *balance, | ||
185 | struct GNUNET_TIME_Absolute *expiry); | ||
186 | |||
187 | |||
172 | /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ | 188 | /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ |
173 | 189 | ||
174 | 190 | ||