diff options
author | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-05 16:31:33 +0100 |
---|---|---|
committer | Sree Harsha Totakura <sreeharsha@totakura.in> | 2015-03-06 10:31:57 +0100 |
commit | 39c538311dd13bf5691700e698528c8562e7d726 (patch) | |
tree | a0ab7b0d1457bd32a54758b265cbab7f971bc1bf | |
parent | 363773698ae164bcdbf822a75b692b15940d27b1 (diff) | |
download | exchange-39c538311dd13bf5691700e698528c8562e7d726.tar.gz exchange-39c538311dd13bf5691700e698528c8562e7d726.zip |
db: Use a reserve structure
-rw-r--r-- | src/mint/mint_db.c | 24 | ||||
-rw-r--r-- | src/mint/mint_db.h | 32 |
2 files changed, 39 insertions, 17 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c index b9f30ac3f..e029d0567 100644 --- a/src/mint/mint_db.c +++ b/src/mint/mint_db.c | |||
@@ -852,25 +852,27 @@ TALER_MINT_DB_commit (PGconn *db_conn) | |||
852 | * Get the summary of a reserve. | 852 | * Get the summary of a reserve. |
853 | * | 853 | * |
854 | * @param db the database connection handle | 854 | * @param db the database connection handle |
855 | * @param reserve_pub the public key identifying the reserve | 855 | * @param reserve the reserve data. The public key of the reserve should be set |
856 | * @param balance the amount existing in the reserve (will be filled) | 856 | * in this structure; it is used to query the database. The balance |
857 | * @param expiry expiration of the reserve (will be filled) | 857 | * and expiration are then filled accordingly. |
858 | * @return #GNUNET_OK upon success; #GNUNET_NO when the given reserve is not | 858 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
859 | * found; #GNUNET_SYSERR upon failure | ||
860 | */ | 859 | */ |
861 | int | 860 | int |
862 | TALER_MINT_DB_reserve_get (PGconn *db, | 861 | TALER_MINT_DB_reserve_get (PGconn *db, |
863 | struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, | 862 | struct Reserve *reserve) |
864 | struct TALER_Amount *balance, | ||
865 | struct GNUNET_TIME_Absolute *expiry) | ||
866 | { | 863 | { |
867 | PGresult *result; | 864 | PGresult *result; |
868 | uint64_t expiration_date_nbo; | 865 | uint64_t expiration_date_nbo; |
869 | struct TALER_DB_QueryParam params[] = { | 866 | struct TALER_DB_QueryParam params[] = { |
870 | TALER_DB_QUERY_PARAM_PTR(reserve_pub), | 867 | TALER_DB_QUERY_PARAM_PTR(reserve->pub), |
871 | TALER_DB_QUERY_PARAM_END | 868 | TALER_DB_QUERY_PARAM_END |
872 | }; | 869 | }; |
873 | 870 | ||
871 | if (NULL == reserve->pub) | ||
872 | { | ||
873 | GNUNET_break (0); | ||
874 | return GNUNET_SYSERR; | ||
875 | } | ||
874 | result = TALER_DB_exec_prepared (db, | 876 | result = TALER_DB_exec_prepared (db, |
875 | "get_reserve", | 877 | "get_reserve", |
876 | params); | 878 | params); |
@@ -897,8 +899,8 @@ TALER_MINT_DB_reserve_get (PGconn *db, | |||
897 | "current_balance_value", | 899 | "current_balance_value", |
898 | "current_balance_fraction", | 900 | "current_balance_fraction", |
899 | "current_balance_currency", | 901 | "current_balance_currency", |
900 | balance)); | 902 | &reserve->balance)); |
901 | expiry->abs_value_us = GNUNET_ntohll (expiration_date_nbo); | 903 | reserve->expiry.abs_value_us = GNUNET_ntohll (expiration_date_nbo); |
902 | PQclear (result); | 904 | PQclear (result); |
903 | return GNUNET_OK; | 905 | return GNUNET_OK; |
904 | 906 | ||
diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h index b80f750b0..b26c70b26 100644 --- a/src/mint/mint_db.h +++ b/src/mint/mint_db.h | |||
@@ -137,6 +137,27 @@ struct BankTransfer | |||
137 | /* FIXME: add functions to add bank transfers to our DB | 137 | /* FIXME: add functions to add bank transfers to our DB |
138 | (and to test if we already did add one) (#3633) */ | 138 | (and to test if we already did add one) (#3633) */ |
139 | 139 | ||
140 | /** | ||
141 | * A summary of a Reserve | ||
142 | */ | ||
143 | struct Reserve | ||
144 | { | ||
145 | /** | ||
146 | * The reserve's public key. This uniquely identifies the reserve | ||
147 | */ | ||
148 | struct GNUNET_CRYPTO_EddsaPublicKey *pub; | ||
149 | |||
150 | /** | ||
151 | * The balance amount existing in the reserve | ||
152 | */ | ||
153 | struct TALER_Amount balance; | ||
154 | |||
155 | /** | ||
156 | * The expiration date of this reserve | ||
157 | */ | ||
158 | struct GNUNET_TIME_Absolute expiry; | ||
159 | }; | ||
160 | |||
140 | 161 | ||
141 | /** | 162 | /** |
142 | * Information we keep for a withdrawn coin to reproduce | 163 | * Information we keep for a withdrawn coin to reproduce |
@@ -173,16 +194,15 @@ struct CollectableBlindcoin | |||
173 | * Get the summary of a reserve. | 194 | * Get the summary of a reserve. |
174 | * | 195 | * |
175 | * @param db the database connection handle | 196 | * @param db the database connection handle |
176 | * @param reserve_pub the public key identifying the reserve | 197 | * @param reserve the reserve data. The public key of the reserve should be set |
177 | * @param balance the amount existing in the reserve (will be filled) | 198 | * in this structure; it is used to query the database. The balance |
178 | * @param expiry expiration of the reserve (will be filled) | 199 | * and expiration are then filled accordingly. |
179 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 200 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
180 | */ | 201 | */ |
181 | int | 202 | int |
182 | TALER_MINT_DB_reserve_get (PGconn *db, | 203 | TALER_MINT_DB_reserve_get (PGconn *db, |
183 | struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, | 204 | struct Reserve *reserve); |
184 | struct TALER_Amount *balance, | 205 | |
185 | struct GNUNET_TIME_Absolute *expiry); | ||
186 | 206 | ||
187 | 207 | ||
188 | /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ | 208 | /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ |