aboutsummaryrefslogtreecommitdiff
path: root/src/mint/mint_db.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/mint_db.c')
-rw-r--r--src/mint/mint_db.c228
1 files changed, 102 insertions, 126 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c
index 5da2a5d46..0e448bf09 100644
--- a/src/mint/mint_db.c
+++ b/src/mint/mint_db.c
@@ -103,128 +103,6 @@ TALER_TALER_DB_extract_amount (PGresult *result,
103} 103}
104 104
105 105
106
107int
108TALER_MINT_DB_get_reserve (PGconn *db_conn,
109 const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub,
110 struct Reserve *reserve)
111{
112 PGresult *result;
113 int res;
114 struct TALER_DB_QueryParam params[] = {
115 TALER_DB_QUERY_PARAM_PTR (reserve_pub),
116 TALER_DB_QUERY_PARAM_END
117 };
118
119 result = TALER_DB_exec_prepared (db_conn, "get_reserve", params);
120
121 if (PGRES_TUPLES_OK != PQresultStatus (result))
122 {
123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed: %s\n", PQresultErrorMessage (result));
124 PQclear (result);
125 return GNUNET_SYSERR;
126 }
127
128 if (0 == PQntuples (result))
129 {
130 PQclear (result);
131 return GNUNET_NO;
132 }
133
134 reserve->reserve_pub = *reserve_pub;
135
136 struct TALER_DB_ResultSpec rs[] = {
137 TALER_DB_RESULT_SPEC("status_sig", &reserve->status_sig),
138 TALER_DB_RESULT_SPEC("status_sign_pub", &reserve->status_sign_pub),
139 TALER_DB_RESULT_SPEC_END
140 };
141
142 res = TALER_DB_extract_result (result, rs, 0);
143 if (GNUNET_SYSERR == res)
144 {
145 GNUNET_break (0);
146 PQclear (result);
147 return GNUNET_SYSERR;
148 }
149
150 {
151 int fnums[] = {
152 PQfnumber (result, "balance_value"),
153 PQfnumber (result, "balance_fraction"),
154 PQfnumber (result, "balance_currency"),
155 };
156 if (GNUNET_OK != TALER_TALER_DB_extract_amount_nbo (result, 0, fnums, &reserve->balance))
157 {
158 GNUNET_break (0);
159 PQclear (result);
160 return GNUNET_SYSERR;
161 }
162 }
163
164 /* FIXME: Add expiration?? */
165
166 PQclear (result);
167 return GNUNET_OK;
168}
169
170
171/* If fresh is GNUNET_YES, set some fields to NULL as they are not actually valid */
172int
173TALER_MINT_DB_update_reserve (PGconn *db_conn,
174 const struct Reserve *reserve,
175 int fresh)
176{
177 PGresult *result;
178 uint64_t stamp_sec;
179
180 stamp_sec = GNUNET_ntohll (GNUNET_TIME_absolute_ntoh (reserve->expiration).abs_value_us / 1000000);
181
182 struct TALER_DB_QueryParam params[] = {
183 TALER_DB_QUERY_PARAM_PTR (&reserve->reserve_pub),
184 TALER_DB_QUERY_PARAM_PTR (&reserve->balance.value),
185 TALER_DB_QUERY_PARAM_PTR (&reserve->balance.fraction),
186 TALER_DB_QUERY_PARAM_PTR_SIZED (&reserve->balance.currency,
187 strlen (reserve->balance.currency)),
188 TALER_DB_QUERY_PARAM_PTR (&reserve->status_sig),
189 TALER_DB_QUERY_PARAM_PTR (&reserve->status_sign_pub),
190 TALER_DB_QUERY_PARAM_PTR (&stamp_sec),
191 TALER_DB_QUERY_PARAM_END
192 };
193
194 /* set some fields to NULL if they are not actually valid */
195
196 if (GNUNET_YES == fresh)
197 {
198 unsigned i;
199 for (i = 4; i <= 7; i += 1)
200 {
201 params[i].data = NULL;
202 params[i].size = 0;
203 }
204 }
205
206 result = TALER_DB_exec_prepared (db_conn, "update_reserve", params);
207
208 if (PGRES_COMMAND_OK != PQresultStatus (result))
209 {
210 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Query failed: %s\n", PQresultErrorMessage (result));
211 PQclear (result);
212 return GNUNET_SYSERR;
213 }
214
215 if (0 != strcmp ("1", PQcmdTuples (result)))
216 {
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Update failed (updated '%s' tupes instead of '1')\n",
218 PQcmdTuples (result));
219 return GNUNET_SYSERR;
220 }
221
222 PQclear (result);
223 return GNUNET_OK;
224}
225
226
227
228int 106int
229TALER_MINT_DB_prepare (PGconn *db_conn) 107TALER_MINT_DB_prepare (PGconn *db_conn)
230{ 108{
@@ -1560,9 +1438,6 @@ TALER_db_get_transfer (PGconn *db_conn,
1560 1438
1561 1439
1562 1440
1563
1564
1565
1566/** 1441/**
1567 * Close thread-local database connection when a thread is destroyed. 1442 * Close thread-local database connection when a thread is destroyed.
1568 * 1443 *
@@ -1712,6 +1587,10 @@ TALER_MINT_DB_commit (PGconn *db_conn)
1712} 1587}
1713 1588
1714 1589
1590
1591
1592
1593
1715/** 1594/**
1716 * Locate the response for a /withdraw request under the 1595 * Locate the response for a /withdraw request under the
1717 * key of the hash of the blinded message. 1596 * key of the hash of the blinded message.
@@ -1729,6 +1608,7 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
1729 const struct GNUNET_HashCode *h_blind, 1608 const struct GNUNET_HashCode *h_blind,
1730 struct CollectableBlindcoin *collectable) 1609 struct CollectableBlindcoin *collectable)
1731{ 1610{
1611 // FIXME: check logic!
1732 PGresult *result; 1612 PGresult *result;
1733 struct TALER_DB_QueryParam params[] = { 1613 struct TALER_DB_QueryParam params[] = {
1734 TALER_DB_QUERY_PARAM_PTR (h_blind), 1614 TALER_DB_QUERY_PARAM_PTR (h_blind),
@@ -1792,6 +1672,7 @@ TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn,
1792 const struct GNUNET_HashCode *h_blind, 1672 const struct GNUNET_HashCode *h_blind,
1793 const struct CollectableBlindcoin *collectable) 1673 const struct CollectableBlindcoin *collectable)
1794{ 1674{
1675 // FIXME: check logic!
1795 PGresult *result; 1676 PGresult *result;
1796 char *sig_buf; 1677 char *sig_buf;
1797 size_t sig_buf_size; 1678 size_t sig_buf_size;
@@ -1835,6 +1716,95 @@ TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn,
1835 1716
1836 1717
1837/** 1718/**
1719 * Get all of the transaction history associated with the specified
1720 * reserve.
1721 *
1722 * @param db_conn connection to use
1723 * @param reserve_pub public key of the reserve
1724 * @return known transaction history (NULL if reserve is unknown)
1725 */
1726struct ReserveHistory *
1727TALER_MINT_DB_get_reserve_history (PGconn *db_conn,
1728 const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub)
1729{
1730 // FIXME: implement logic!
1731 PGresult *result;
1732 // int res;
1733 struct TALER_DB_QueryParam params[] = {
1734 TALER_DB_QUERY_PARAM_PTR (reserve_pub),
1735 TALER_DB_QUERY_PARAM_END
1736 };
1737
1738 result = TALER_DB_exec_prepared (db_conn, "get_reserve", params);
1739
1740 if (PGRES_TUPLES_OK != PQresultStatus (result))
1741 {
1742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1743 "Query failed: %s\n",
1744 PQresultErrorMessage (result));
1745 PQclear (result);
1746 return NULL;
1747 }
1748
1749 if (0 == PQntuples (result))
1750 {
1751 PQclear (result);
1752 return NULL;
1753 }
1754#if 0
1755 reserve->reserve_pub = *reserve_pub;
1756
1757 struct TALER_DB_ResultSpec rs[] = {
1758 TALER_DB_RESULT_SPEC("status_sig", &reserve->status_sig),
1759 TALER_DB_RESULT_SPEC("status_sign_pub", &reserve->status_sign_pub),
1760 TALER_DB_RESULT_SPEC_END
1761 };
1762
1763 res = TALER_DB_extract_result (result, rs, 0);
1764 if (GNUNET_SYSERR == res)
1765 {
1766 GNUNET_break (0);
1767 PQclear (result);
1768 return GNUNET_SYSERR;
1769 }
1770
1771 {
1772 int fnums[] = {
1773 PQfnumber (result, "balance_value"),
1774 PQfnumber (result, "balance_fraction"),
1775 PQfnumber (result, "balance_currency"),
1776 };
1777 if (GNUNET_OK != TALER_TALER_DB_extract_amount_nbo (result, 0, fnums, &reserve->balance))
1778 {
1779 GNUNET_break (0);
1780 PQclear (result);
1781 return GNUNET_SYSERR;
1782 }
1783 }
1784
1785 /* FIXME: Add expiration?? */
1786
1787 PQclear (result);
1788 return GNUNET_OK;
1789#endif
1790 return NULL;
1791}
1792
1793
1794/**
1795 * Free memory associated with the given reserve history.
1796 *
1797 * @param rh history to free.
1798 */
1799void
1800TALER_MINT_DB_free_reserve_history (struct ReserveHistory *rh)
1801{
1802 // FIXME: implement
1803 GNUNET_assert (0);
1804}
1805
1806
1807/**
1838 * Check if we have the specified deposit already in the database. 1808 * Check if we have the specified deposit already in the database.
1839 * 1809 *
1840 * @param db_conn database connection 1810 * @param db_conn database connection
@@ -1846,6 +1816,7 @@ int
1846TALER_MINT_DB_have_deposit (PGconn *db_conn, 1816TALER_MINT_DB_have_deposit (PGconn *db_conn,
1847 const struct Deposit *deposit) 1817 const struct Deposit *deposit)
1848{ 1818{
1819 // FIXME: check logic!
1849 struct TALER_DB_QueryParam params[] = { 1820 struct TALER_DB_QueryParam params[] = {
1850 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.coin_pub), // FIXME 1821 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.coin_pub), // FIXME
1851 TALER_DB_QUERY_PARAM_END 1822 TALER_DB_QUERY_PARAM_END
@@ -1884,6 +1855,7 @@ int
1884TALER_MINT_DB_insert_deposit (PGconn *db_conn, 1855TALER_MINT_DB_insert_deposit (PGconn *db_conn,
1885 const struct Deposit *deposit) 1856 const struct Deposit *deposit)
1886{ 1857{
1858 // FIXME: check logic!
1887 struct TALER_DB_QueryParam params[]= { 1859 struct TALER_DB_QueryParam params[]= {
1888 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.coin_pub), 1860 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.coin_pub),
1889 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.denom_pub), // FIXME! 1861 TALER_DB_QUERY_PARAM_PTR (&deposit->coin.denom_pub), // FIXME!
@@ -1928,6 +1900,7 @@ int
1928TALER_MINT_DB_have_refresh_melt (PGconn *db_conn, 1900TALER_MINT_DB_have_refresh_melt (PGconn *db_conn,
1929 const struct RefreshMelt *melt) 1901 const struct RefreshMelt *melt)
1930{ 1902{
1903 // FIXME: check logic!
1931 uint16_t oldcoin_index_nbo = htons (melt->oldcoin_index); 1904 uint16_t oldcoin_index_nbo = htons (melt->oldcoin_index);
1932 struct TALER_DB_QueryParam params[] = { 1905 struct TALER_DB_QueryParam params[] = {
1933 TALER_DB_QUERY_PARAM_PTR(&melt->session_pub), 1906 TALER_DB_QUERY_PARAM_PTR(&melt->session_pub),
@@ -1956,7 +1929,6 @@ TALER_MINT_DB_have_refresh_melt (PGconn *db_conn,
1956} 1929}
1957 1930
1958 1931
1959
1960/** 1932/**
1961 * Store the given /refresh/melt request in the database. 1933 * Store the given /refresh/melt request in the database.
1962 * 1934 *
@@ -1969,6 +1941,7 @@ int
1969TALER_MINT_DB_insert_refresh_melt (PGconn *db_conn, 1941TALER_MINT_DB_insert_refresh_melt (PGconn *db_conn,
1970 const struct RefreshMelt *melt) 1942 const struct RefreshMelt *melt)
1971{ 1943{
1944 // FIXME: check logic!
1972 uint16_t oldcoin_index_nbo = htons (melt->oldcoin_index); 1945 uint16_t oldcoin_index_nbo = htons (melt->oldcoin_index);
1973 char *buf; 1946 char *buf;
1974 size_t buf_size; 1947 size_t buf_size;
@@ -2014,6 +1987,7 @@ TALER_MINT_DB_get_refresh_melt (PGconn *db_conn,
2014 uint16_t oldcoin_index, 1987 uint16_t oldcoin_index,
2015 struct RefreshMelt *melt) 1988 struct RefreshMelt *melt)
2016{ 1989{
1990 // FIXME: check logic!
2017 GNUNET_break (0); 1991 GNUNET_break (0);
2018 return GNUNET_SYSERR; 1992 return GNUNET_SYSERR;
2019} 1993}
@@ -2031,6 +2005,7 @@ struct TALER_MINT_DB_TransactionList *
2031TALER_MINT_DB_get_coin_transactions (PGconn *db_conn, 2005TALER_MINT_DB_get_coin_transactions (PGconn *db_conn,
2032 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub) 2006 const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub)
2033{ 2007{
2008 // FIXME: check logic!
2034 GNUNET_break (0); // FIXME: implement! 2009 GNUNET_break (0); // FIXME: implement!
2035 return NULL; 2010 return NULL;
2036} 2011}
@@ -2044,6 +2019,7 @@ TALER_MINT_DB_get_coin_transactions (PGconn *db_conn,
2044void 2019void
2045TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list) 2020TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list)
2046{ 2021{
2022 // FIXME: check logic!
2047 GNUNET_break (0); 2023 GNUNET_break (0);
2048} 2024}
2049 2025