aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-28 22:47:03 +0100
committerChristian Grothoff <christian@grothoff.org>2015-01-28 22:47:03 +0100
commitb162d2e45829469df5327ea25b2bab1ba1ebaab9 (patch)
treec815fd6a78faab0d4934048427d35e80a2c30cb7
parentfb124841605dabe843f4d5713e58a516ddc84d48 (diff)
downloadexchange-b162d2e45829469df5327ea25b2bab1ba1ebaab9.tar.gz
exchange-b162d2e45829469df5327ea25b2bab1ba1ebaab9.zip
rollback should just return void
-rw-r--r--src/mint/mint_db.c68
-rw-r--r--src/mint/mint_db.h6
-rw-r--r--src/mint/taler-mint-httpd_db.c67
-rw-r--r--src/mint/taler-mint-httpd_responses.c17
-rw-r--r--src/mint/taler-mint-httpd_responses.h11
5 files changed, 90 insertions, 79 deletions
diff --git a/src/mint/mint_db.c b/src/mint/mint_db.c
index b23a5b65f..5da2a5d46 100644
--- a/src/mint/mint_db.c
+++ b/src/mint/mint_db.c
@@ -1572,6 +1572,7 @@ static void
1572db_conn_destroy (void *cls) 1572db_conn_destroy (void *cls)
1573{ 1573{
1574 PGconn *db_conn = cls; 1574 PGconn *db_conn = cls;
1575
1575 if (NULL != db_conn) 1576 if (NULL != db_conn)
1576 PQfinish (db_conn); 1577 PQfinish (db_conn);
1577} 1578}
@@ -1589,8 +1590,7 @@ TALER_MINT_DB_init (const char *connection_cfg)
1589 if (0 != pthread_key_create (&db_conn_threadlocal, 1590 if (0 != pthread_key_create (&db_conn_threadlocal,
1590 &db_conn_destroy)) 1591 &db_conn_destroy))
1591 { 1592 {
1592 fprintf (stderr, 1593 LOG_ERROR ("Cannnot create pthread key.\n");
1593 "Can't create pthread key.\n");
1594 return GNUNET_SYSERR; 1594 return GNUNET_SYSERR;
1595 } 1595 }
1596 TALER_MINT_db_connection_cfg_str = GNUNET_strdup (connection_cfg); 1596 TALER_MINT_db_connection_cfg_str = GNUNET_strdup (connection_cfg);
@@ -1614,16 +1614,17 @@ TALER_MINT_DB_get_connection (void)
1614 1614
1615 db_conn = PQconnectdb (TALER_MINT_db_connection_cfg_str); 1615 db_conn = PQconnectdb (TALER_MINT_db_connection_cfg_str);
1616 1616
1617 if (CONNECTION_OK != PQstatus (db_conn)) 1617 if (CONNECTION_OK !=
1618 PQstatus (db_conn))
1618 { 1619 {
1619 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1620 LOG_ERROR ("Database connection failed: %s\n",
1620 "db connection failed: %s\n", 1621 PQerrorMessage (db_conn));
1621 PQerrorMessage (db_conn));
1622 GNUNET_break (0); 1622 GNUNET_break (0);
1623 return NULL; 1623 return NULL;
1624 } 1624 }
1625 1625
1626 if (GNUNET_OK != TALER_MINT_DB_prepare (db_conn)) 1626 if (GNUNET_OK !=
1627 TALER_MINT_DB_prepare (db_conn))
1627 { 1628 {
1628 GNUNET_break (0); 1629 GNUNET_break (0);
1629 return NULL; 1630 return NULL;
@@ -1649,14 +1650,15 @@ TALER_MINT_DB_transaction (PGconn *db_conn)
1649{ 1650{
1650 PGresult *result; 1651 PGresult *result;
1651 1652
1652 result = PQexec(db_conn, "BEGIN"); 1653 result = PQexec (db_conn,
1653 if (PGRES_COMMAND_OK != PQresultStatus (result)) 1654 "BEGIN");
1655 if (PGRES_COMMAND_OK !=
1656 PQresultStatus (result))
1654 { 1657 {
1655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1658 LOG_ERROR ("Failed to start transaction: %s\n",
1656 "Can't start transaction: %s\n", 1659 PQresultErrorMessage (result));
1657 PQresultErrorMessage (result));
1658 PQclear (result);
1659 GNUNET_break (0); 1660 GNUNET_break (0);
1661 PQclear (result);
1660 return GNUNET_SYSERR; 1662 return GNUNET_SYSERR;
1661 } 1663 }
1662 1664
@@ -1671,22 +1673,16 @@ TALER_MINT_DB_transaction (PGconn *db_conn)
1671 * @param db_conn the database connection 1673 * @param db_conn the database connection
1672 * @return #GNUNET_OK on success 1674 * @return #GNUNET_OK on success
1673 */ 1675 */
1674int 1676void
1675TALER_MINT_DB_rollback (PGconn *db_conn) 1677TALER_MINT_DB_rollback (PGconn *db_conn)
1676{ 1678{
1677 PGresult *result; 1679 PGresult *result;
1678 1680
1679 result = PQexec(db_conn, 1681 result = PQexec (db_conn,
1680 "ROLLBACK"); 1682 "ROLLBACK");
1681 if (PGRES_COMMAND_OK != PQresultStatus (result)) 1683 GNUNET_break (PGRES_COMMAND_OK ==
1682 { 1684 PQresultStatus (result));
1683 PQclear (result);
1684 GNUNET_break (0);
1685 return GNUNET_SYSERR;
1686 }
1687
1688 PQclear (result); 1685 PQclear (result);
1689 return GNUNET_OK;
1690} 1686}
1691 1687
1692 1688
@@ -1701,12 +1697,13 @@ TALER_MINT_DB_commit (PGconn *db_conn)
1701{ 1697{
1702 PGresult *result; 1698 PGresult *result;
1703 1699
1704 result = PQexec(db_conn, 1700 result = PQexec (db_conn,
1705 "COMMIT"); 1701 "COMMIT");
1706 if (PGRES_COMMAND_OK != PQresultStatus (result)) 1702 if (PGRES_COMMAND_OK !=
1703 PQresultStatus (result))
1707 { 1704 {
1708 PQclear (result);
1709 GNUNET_break (0); 1705 GNUNET_break (0);
1706 PQclear (result);
1710 return GNUNET_SYSERR; 1707 return GNUNET_SYSERR;
1711 } 1708 }
1712 1709
@@ -1744,7 +1741,8 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
1744 "get_collectable_blindcoins", 1741 "get_collectable_blindcoins",
1745 params); 1742 params);
1746 1743
1747 if (PGRES_TUPLES_OK != PQresultStatus (result)) 1744 if (PGRES_TUPLES_OK !=
1745 PQresultStatus (result))
1748 { 1746 {
1749 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1747 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1750 "Query failed: %s\n", 1748 "Query failed: %s\n",
@@ -2038,4 +2036,16 @@ TALER_MINT_DB_get_coin_transactions (PGconn *db_conn,
2038} 2036}
2039 2037
2040 2038
2039/**
2040 * Free linked list of transactions.
2041 *
2042 * @param list list to free
2043 */
2044void
2045TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list)
2046{
2047 GNUNET_break (0);
2048}
2049
2050
2041/* end of mint_db.c */ 2051/* end of mint_db.c */
diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h
index 01fd737bd..ff14ba1e4 100644
--- a/src/mint/mint_db.h
+++ b/src/mint/mint_db.h
@@ -302,6 +302,7 @@ TALER_MINT_DB_get_connection (void);
302/** 302/**
303 * Start a transaction. 303 * Start a transaction.
304 * 304 *
305 * @param db_conn connection to use
305 * @return #GNUNET_OK on success 306 * @return #GNUNET_OK on success
306 */ 307 */
307int 308int
@@ -311,6 +312,7 @@ TALER_MINT_DB_transaction (PGconn *db_conn);
311/** 312/**
312 * Commit a transaction. 313 * Commit a transaction.
313 * 314 *
315 * @param db_conn connection to use
314 * @return #GNUNET_OK on success 316 * @return #GNUNET_OK on success
315 */ 317 */
316int 318int
@@ -320,9 +322,9 @@ TALER_MINT_DB_commit (PGconn *db_conn);
320/** 322/**
321 * Abort/rollback a transaction. 323 * Abort/rollback a transaction.
322 * 324 *
323 * @return #GNUNET_OK on success 325 * @param db_conn connection to use
324 */ 326 */
325int 327void
326TALER_MINT_DB_rollback (PGconn *db_conn); 328TALER_MINT_DB_rollback (PGconn *db_conn);
327 329
328 330
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index 7e9dde849..c6f0fe2cb 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -89,60 +89,31 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
89 // FIXME: in the future, check if there's enough credits 89 // FIXME: in the future, check if there's enough credits
90 // left on the coin. For now: refuse 90 // left on the coin. For now: refuse
91 // FIXME: return more information here 91 // FIXME: return more information here
92 TALER_MINT_DB_rollback (db_conn);
92 return TALER_MINT_reply_json_pack (connection, 93 return TALER_MINT_reply_json_pack (connection,
93 MHD_HTTP_FORBIDDEN, 94 MHD_HTTP_FORBIDDEN,
94 "{s:s}", 95 "{s:s}",
95 "error", 96 "error", "insufficient funds");
96 "double spending");
97 } 97 }
98 98
99 99
100 { 100 TALER_MINT_DB_free_coin_transaction_list (tl);
101 struct KnownCoin known_coin;
102 int res;
103 struct TALER_CoinPublicInfo coin_info;
104
105 res = TALER_MINT_DB_get_known_coin (db_conn,
106 &coin_info.coin_pub,
107 &known_coin);
108 if (GNUNET_YES == res)
109 {
110 // coin must have been refreshed
111 // FIXME: check
112 // FIXME: return more information here
113 return TALER_MINT_reply_json_pack (connection,
114 MHD_HTTP_FORBIDDEN,
115 "{s:s}",
116 "error", "coin was refreshed");
117 }
118 if (GNUNET_SYSERR == res)
119 {
120 GNUNET_break (0);
121 /* FIXME: return error message to client via MHD! */
122 return MHD_NO;
123 }
124
125 /* coin valid but not known => insert into DB */
126 known_coin.is_refreshed = GNUNET_NO;
127 known_coin.expended_balance = deposit->amount;
128 known_coin.public_info = coin_info;
129 101
130 if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin)) 102 if (GNUNET_OK !=
131 { 103 TALER_MINT_DB_insert_deposit (db_conn,
132 GNUNET_break (0); 104 deposit))
133 /* FIXME: return error message to client via MHD! */ 105 {
134 return MHD_NO; 106 LOG_WARNING ("Failed to store /deposit information in database\n");
135 } 107 TALER_MINT_DB_rollback (db_conn);
108 return TALER_MINT_reply_internal_db_error (connection);
136 } 109 }
137 110
138 if (GNUNET_OK != TALER_MINT_DB_insert_deposit (db_conn, deposit)) 111 if (GNUNET_OK !=
112 TALER_MINT_DB_commit (db_conn))
139 { 113 {
140 GNUNET_break (0); 114 LOG_WARNING ("/deposit transaction commit failed\n");
141 /* FIXME: return error message to client via MHD! */ 115 return TALER_MINT_reply_commit_error (connection);
142 return MHD_NO;
143 } 116 }
144 // FIXME: check commit return value!
145 TALER_MINT_DB_commit (db_conn);
146 return TALER_MINT_reply_deposit_success (connection, 117 return TALER_MINT_reply_deposit_success (connection,
147 &deposit->coin.coin_pub, 118 &deposit->coin.coin_pub,
148 &deposit->h_wire, 119 &deposit->h_wire,
@@ -673,7 +644,7 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
673 &melt_balance))) 644 &melt_balance)))
674 { 645 {
675 TALER_MINT_key_state_release (key_state); 646 TALER_MINT_key_state_release (key_state);
676 GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); 647 TALER_MINT_DB_rollback (db_conn);
677 return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; 648 return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
678 } 649 }
679 650
@@ -686,7 +657,7 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
686 // FIXME: also, consider fees? 657 // FIXME: also, consider fees?
687 if (TALER_amount_cmp (melt_balance, requested_cost) < 0) 658 if (TALER_amount_cmp (melt_balance, requested_cost) < 0)
688 { 659 {
689 GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); 660 TALER_MINT_DB_rollback (db_conn);
690 661
691 return TALER_MINT_reply_json_pack (connection, 662 return TALER_MINT_reply_json_pack (connection,
692 MHD_HTTP_FORBIDDEN, 663 MHD_HTTP_FORBIDDEN,
@@ -772,7 +743,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
772 { 743 {
773 // FIXME: return 'internal error'? 744 // FIXME: return 'internal error'?
774 GNUNET_break (0); 745 GNUNET_break (0);
775 GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); 746 TALER_MINT_DB_rollback (db_conn);
776 return MHD_NO; 747 return MHD_NO;
777 } 748 }
778 749
@@ -785,7 +756,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
785 { 756 {
786 // FIXME: return 'internal error'? 757 // FIXME: return 'internal error'?
787 GNUNET_break (0); 758 GNUNET_break (0);
788 GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); 759 TALER_MINT_DB_rollback (db_conn);
789 return MHD_NO; 760 return MHD_NO;
790 } 761 }
791 } 762 }
@@ -829,7 +800,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
829 { 800 {
830 // FIXME: return 'internal error'? 801 // FIXME: return 'internal error'?
831 GNUNET_break (GNUNET_SYSERR != res); 802 GNUNET_break (GNUNET_SYSERR != res);
832 GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); 803 TALER_MINT_DB_rollback (db_conn);
833 return MHD_NO; 804 return MHD_NO;
834 } 805 }
835 806
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index 92bba9e21..307e6ec17 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -178,6 +178,23 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
178 178
179 179
180/** 180/**
181 * Send a response indicating an error committing a
182 * transaction (concurrent interference).
183 *
184 * @param connection the MHD connection to use
185 * @return a MHD result code
186 */
187int
188TALER_MINT_reply_commit_error (struct MHD_Connection *connection)
189{
190 return TALER_MINT_reply_json_pack (connection,
191 MHD_HTTP_BAD_REQUEST,
192 "{s:s}",
193 "error", "commit failure");
194}
195
196
197/**
181 * Send a response indicating a failure to talk to the Mint's 198 * Send a response indicating a failure to talk to the Mint's
182 * database. 199 * database.
183 * 200 *
diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h
index 421113eed..f8a671e18 100644
--- a/src/mint/taler-mint-httpd_responses.h
+++ b/src/mint/taler-mint-httpd_responses.h
@@ -113,6 +113,17 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
113 113
114 114
115/** 115/**
116 * Send a response indicating an error committing a
117 * transaction (concurrent interference).
118 *
119 * @param connection the MHD connection to use
120 * @return a MHD result code
121 */
122int
123TALER_MINT_reply_commit_error (struct MHD_Connection *connection);
124
125
126/**
116 * Send a response indicating a failure to talk to the Mint's 127 * Send a response indicating a failure to talk to the Mint's
117 * database. 128 * database.
118 * 129 *