rollback should just return void
This commit is contained in:
parent
fb12484160
commit
b162d2e458
@ -1572,6 +1572,7 @@ static void
|
||||
db_conn_destroy (void *cls)
|
||||
{
|
||||
PGconn *db_conn = cls;
|
||||
|
||||
if (NULL != db_conn)
|
||||
PQfinish (db_conn);
|
||||
}
|
||||
@ -1589,8 +1590,7 @@ TALER_MINT_DB_init (const char *connection_cfg)
|
||||
if (0 != pthread_key_create (&db_conn_threadlocal,
|
||||
&db_conn_destroy))
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Can't create pthread key.\n");
|
||||
LOG_ERROR ("Cannnot create pthread key.\n");
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
TALER_MINT_db_connection_cfg_str = GNUNET_strdup (connection_cfg);
|
||||
@ -1614,16 +1614,17 @@ TALER_MINT_DB_get_connection (void)
|
||||
|
||||
db_conn = PQconnectdb (TALER_MINT_db_connection_cfg_str);
|
||||
|
||||
if (CONNECTION_OK != PQstatus (db_conn))
|
||||
if (CONNECTION_OK !=
|
||||
PQstatus (db_conn))
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"db connection failed: %s\n",
|
||||
PQerrorMessage (db_conn));
|
||||
LOG_ERROR ("Database connection failed: %s\n",
|
||||
PQerrorMessage (db_conn));
|
||||
GNUNET_break (0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (GNUNET_OK != TALER_MINT_DB_prepare (db_conn))
|
||||
if (GNUNET_OK !=
|
||||
TALER_MINT_DB_prepare (db_conn))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return NULL;
|
||||
@ -1649,14 +1650,15 @@ TALER_MINT_DB_transaction (PGconn *db_conn)
|
||||
{
|
||||
PGresult *result;
|
||||
|
||||
result = PQexec(db_conn, "BEGIN");
|
||||
if (PGRES_COMMAND_OK != PQresultStatus (result))
|
||||
result = PQexec (db_conn,
|
||||
"BEGIN");
|
||||
if (PGRES_COMMAND_OK !=
|
||||
PQresultStatus (result))
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"Can't start transaction: %s\n",
|
||||
PQresultErrorMessage (result));
|
||||
PQclear (result);
|
||||
LOG_ERROR ("Failed to start transaction: %s\n",
|
||||
PQresultErrorMessage (result));
|
||||
GNUNET_break (0);
|
||||
PQclear (result);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
@ -1671,22 +1673,16 @@ TALER_MINT_DB_transaction (PGconn *db_conn)
|
||||
* @param db_conn the database connection
|
||||
* @return #GNUNET_OK on success
|
||||
*/
|
||||
int
|
||||
void
|
||||
TALER_MINT_DB_rollback (PGconn *db_conn)
|
||||
{
|
||||
PGresult *result;
|
||||
|
||||
result = PQexec(db_conn,
|
||||
"ROLLBACK");
|
||||
if (PGRES_COMMAND_OK != PQresultStatus (result))
|
||||
{
|
||||
PQclear (result);
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
result = PQexec (db_conn,
|
||||
"ROLLBACK");
|
||||
GNUNET_break (PGRES_COMMAND_OK ==
|
||||
PQresultStatus (result));
|
||||
PQclear (result);
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -1701,12 +1697,13 @@ TALER_MINT_DB_commit (PGconn *db_conn)
|
||||
{
|
||||
PGresult *result;
|
||||
|
||||
result = PQexec(db_conn,
|
||||
"COMMIT");
|
||||
if (PGRES_COMMAND_OK != PQresultStatus (result))
|
||||
result = PQexec (db_conn,
|
||||
"COMMIT");
|
||||
if (PGRES_COMMAND_OK !=
|
||||
PQresultStatus (result))
|
||||
{
|
||||
PQclear (result);
|
||||
GNUNET_break (0);
|
||||
PQclear (result);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
@ -1744,7 +1741,8 @@ TALER_MINT_DB_get_collectable_blindcoin (PGconn *db_conn,
|
||||
"get_collectable_blindcoins",
|
||||
params);
|
||||
|
||||
if (PGRES_TUPLES_OK != PQresultStatus (result))
|
||||
if (PGRES_TUPLES_OK !=
|
||||
PQresultStatus (result))
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"Query failed: %s\n",
|
||||
@ -2038,4 +2036,16 @@ TALER_MINT_DB_get_coin_transactions (PGconn *db_conn,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free linked list of transactions.
|
||||
*
|
||||
* @param list list to free
|
||||
*/
|
||||
void
|
||||
TALER_MINT_DB_free_coin_transaction_list (struct TALER_MINT_DB_TransactionList *list)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
}
|
||||
|
||||
|
||||
/* end of mint_db.c */
|
||||
|
@ -302,6 +302,7 @@ TALER_MINT_DB_get_connection (void);
|
||||
/**
|
||||
* Start a transaction.
|
||||
*
|
||||
* @param db_conn connection to use
|
||||
* @return #GNUNET_OK on success
|
||||
*/
|
||||
int
|
||||
@ -311,6 +312,7 @@ TALER_MINT_DB_transaction (PGconn *db_conn);
|
||||
/**
|
||||
* Commit a transaction.
|
||||
*
|
||||
* @param db_conn connection to use
|
||||
* @return #GNUNET_OK on success
|
||||
*/
|
||||
int
|
||||
@ -320,9 +322,9 @@ TALER_MINT_DB_commit (PGconn *db_conn);
|
||||
/**
|
||||
* Abort/rollback a transaction.
|
||||
*
|
||||
* @return #GNUNET_OK on success
|
||||
* @param db_conn connection to use
|
||||
*/
|
||||
int
|
||||
void
|
||||
TALER_MINT_DB_rollback (PGconn *db_conn);
|
||||
|
||||
|
||||
|
@ -89,60 +89,31 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
|
||||
// FIXME: in the future, check if there's enough credits
|
||||
// left on the coin. For now: refuse
|
||||
// FIXME: return more information here
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return TALER_MINT_reply_json_pack (connection,
|
||||
MHD_HTTP_FORBIDDEN,
|
||||
"{s:s}",
|
||||
"error",
|
||||
"double spending");
|
||||
"error", "insufficient funds");
|
||||
}
|
||||
|
||||
|
||||
TALER_MINT_DB_free_coin_transaction_list (tl);
|
||||
|
||||
if (GNUNET_OK !=
|
||||
TALER_MINT_DB_insert_deposit (db_conn,
|
||||
deposit))
|
||||
{
|
||||
struct KnownCoin known_coin;
|
||||
int res;
|
||||
struct TALER_CoinPublicInfo coin_info;
|
||||
|
||||
res = TALER_MINT_DB_get_known_coin (db_conn,
|
||||
&coin_info.coin_pub,
|
||||
&known_coin);
|
||||
if (GNUNET_YES == res)
|
||||
{
|
||||
// coin must have been refreshed
|
||||
// FIXME: check
|
||||
// FIXME: return more information here
|
||||
return TALER_MINT_reply_json_pack (connection,
|
||||
MHD_HTTP_FORBIDDEN,
|
||||
"{s:s}",
|
||||
"error", "coin was refreshed");
|
||||
}
|
||||
if (GNUNET_SYSERR == res)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
/* FIXME: return error message to client via MHD! */
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
/* coin valid but not known => insert into DB */
|
||||
known_coin.is_refreshed = GNUNET_NO;
|
||||
known_coin.expended_balance = deposit->amount;
|
||||
known_coin.public_info = coin_info;
|
||||
|
||||
if (GNUNET_OK != TALER_MINT_DB_insert_known_coin (db_conn, &known_coin))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
/* FIXME: return error message to client via MHD! */
|
||||
return MHD_NO;
|
||||
}
|
||||
LOG_WARNING ("Failed to store /deposit information in database\n");
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return TALER_MINT_reply_internal_db_error (connection);
|
||||
}
|
||||
|
||||
if (GNUNET_OK != TALER_MINT_DB_insert_deposit (db_conn, deposit))
|
||||
if (GNUNET_OK !=
|
||||
TALER_MINT_DB_commit (db_conn))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
/* FIXME: return error message to client via MHD! */
|
||||
return MHD_NO;
|
||||
LOG_WARNING ("/deposit transaction commit failed\n");
|
||||
return TALER_MINT_reply_commit_error (connection);
|
||||
}
|
||||
// FIXME: check commit return value!
|
||||
TALER_MINT_DB_commit (db_conn);
|
||||
return TALER_MINT_reply_deposit_success (connection,
|
||||
&deposit->coin.coin_pub,
|
||||
&deposit->h_wire,
|
||||
@ -673,7 +644,7 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
|
||||
&melt_balance)))
|
||||
{
|
||||
TALER_MINT_key_state_release (key_state);
|
||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
|
||||
}
|
||||
|
||||
@ -686,7 +657,7 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
|
||||
// FIXME: also, consider fees?
|
||||
if (TALER_amount_cmp (melt_balance, requested_cost) < 0)
|
||||
{
|
||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
|
||||
return TALER_MINT_reply_json_pack (connection,
|
||||
MHD_HTTP_FORBIDDEN,
|
||||
@ -772,7 +743,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
|
||||
{
|
||||
// FIXME: return 'internal error'?
|
||||
GNUNET_break (0);
|
||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
@ -785,7 +756,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
|
||||
{
|
||||
// FIXME: return 'internal error'?
|
||||
GNUNET_break (0);
|
||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return MHD_NO;
|
||||
}
|
||||
}
|
||||
@ -829,7 +800,7 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
|
||||
{
|
||||
// FIXME: return 'internal error'?
|
||||
GNUNET_break (GNUNET_SYSERR != res);
|
||||
GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn));
|
||||
TALER_MINT_DB_rollback (db_conn);
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
|
@ -177,6 +177,23 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a response indicating an error committing a
|
||||
* transaction (concurrent interference).
|
||||
*
|
||||
* @param connection the MHD connection to use
|
||||
* @return a MHD result code
|
||||
*/
|
||||
int
|
||||
TALER_MINT_reply_commit_error (struct MHD_Connection *connection)
|
||||
{
|
||||
return TALER_MINT_reply_json_pack (connection,
|
||||
MHD_HTTP_BAD_REQUEST,
|
||||
"{s:s}",
|
||||
"error", "commit failure");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a response indicating a failure to talk to the Mint's
|
||||
* database.
|
||||
|
@ -112,6 +112,17 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
|
||||
const char *hint);
|
||||
|
||||
|
||||
/**
|
||||
* Send a response indicating an error committing a
|
||||
* transaction (concurrent interference).
|
||||
*
|
||||
* @param connection the MHD connection to use
|
||||
* @return a MHD result code
|
||||
*/
|
||||
int
|
||||
TALER_MINT_reply_commit_error (struct MHD_Connection *connection);
|
||||
|
||||
|
||||
/**
|
||||
* Send a response indicating a failure to talk to the Mint's
|
||||
* database.
|
||||
|
Loading…
Reference in New Issue
Block a user