eliminating obsolete KnownCoin APIs

This commit is contained in:
Christian Grothoff 2015-01-29 20:41:11 +01:00
parent f35d358552
commit d751c9c6de
3 changed files with 21 additions and 301 deletions

View File

@ -580,98 +580,6 @@ TALER_MINT_DB_insert_refresh_order (PGconn *db_conn,
}
int
TALER_MINT_DB_get_known_coin (PGconn *db_conn,
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub,
struct KnownCoin *known_coin)
{
int res;
struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR(coin_pub),
TALER_DB_QUERY_PARAM_END
};
PGresult *result = TALER_DB_exec_prepared (db_conn, "get_known_coin", params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Query failed: %s\n",
PQresultErrorMessage (result));
PQclear (result);
return GNUNET_SYSERR;
}
if (0 == PQntuples (result))
return GNUNET_NO;
GNUNET_assert (1 == PQntuples (result));
/* extract basic information about the known coin */
{
struct TALER_DB_ResultSpec rs[] = {
TALER_DB_RESULT_SPEC("coin_pub", &known_coin->public_info.coin_pub),
TALER_DB_RESULT_SPEC("denom_pub", &known_coin->public_info.denom_pub),
TALER_DB_RESULT_SPEC("denom_sig", &known_coin->public_info.denom_sig),
TALER_DB_RESULT_SPEC_END
};
if (GNUNET_OK != (res = TALER_DB_extract_result (result, rs, 0)))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
}
/* extract the expended amount of the coin */
if (GNUNET_OK !=
TALER_DB_extract_amount (result,
0,
"expended_value",
"expended_fraction",
"expended_currency",
&known_coin->expended_balance))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
/* extract the refresh session of the coin or mark it as missing */
{
struct TALER_DB_ResultSpec rs[] = {
TALER_DB_RESULT_SPEC("refresh_session_pub", &known_coin->refresh_session_pub),
TALER_DB_RESULT_SPEC_END
};
if (GNUNET_SYSERR == (res = TALER_DB_extract_result (result, rs, 0)))
{
GNUNET_break (0);
PQclear (result);
return GNUNET_SYSERR;
}
if (GNUNET_NO == res)
{
known_coin->is_refreshed = GNUNET_NO;
memset (&known_coin->refresh_session_pub,
0,
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
}
else
{
known_coin->is_refreshed = GNUNET_YES;
}
}
PQclear (result);
return GNUNET_YES;
}
int
TALER_MINT_DB_set_commit_signature (PGconn *db_conn,
const struct GNUNET_CRYPTO_EddsaPublicKey *session_pub,
@ -711,112 +619,6 @@ TALER_MINT_DB_set_reveal_ok (PGconn *db_conn,
}
int
TALER_MINT_DB_update_known_coin (PGconn *db_conn,
const struct KnownCoin *known_coin)
{
struct TALER_AmountNBO expended_nbo = TALER_amount_hton (known_coin->expended_balance);
struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.coin_pub),
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.denom_pub),
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.denom_sig),
TALER_DB_QUERY_PARAM_PTR(&expended_nbo.value),
TALER_DB_QUERY_PARAM_PTR(&expended_nbo.fraction),
TALER_DB_QUERY_PARAM_PTR_SIZED(expended_nbo.currency, strlen (expended_nbo.currency)),
TALER_DB_QUERY_PARAM_PTR(&known_coin->refresh_session_pub),
TALER_DB_QUERY_PARAM_END
};
if (GNUNET_NO == known_coin->is_refreshed)
{
// Mind the magic index!
params[6].data = NULL;
params[6].size = 0;
}
PGresult *result = TALER_DB_exec_prepared (db_conn, "update_known_coin", params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
break_db_err (result);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
PQclear (result);
// return 'no' here (don't fail) so that we can
// insert if update fails (=> "upsert")
return GNUNET_NO;
}
PQclear (result);
return GNUNET_YES;
}
int
TALER_MINT_DB_insert_known_coin (PGconn *db_conn,
const struct KnownCoin *known_coin)
{
struct TALER_AmountNBO expended_nbo = TALER_amount_hton (known_coin->expended_balance);
struct TALER_DB_QueryParam params[] = {
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.coin_pub),
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.denom_pub),
TALER_DB_QUERY_PARAM_PTR(&known_coin->public_info.denom_sig),
TALER_DB_QUERY_PARAM_PTR(&expended_nbo.value),
TALER_DB_QUERY_PARAM_PTR(&expended_nbo.fraction),
TALER_DB_QUERY_PARAM_PTR_SIZED(&expended_nbo.currency, strlen (expended_nbo.currency)),
TALER_DB_QUERY_PARAM_PTR(&known_coin->refresh_session_pub),
TALER_DB_QUERY_PARAM_END
};
if (GNUNET_NO == known_coin->is_refreshed)
{
// Mind the magic index!
params[6].data = NULL;
params[6].size = 0;
}
PGresult *result = TALER_DB_exec_prepared (db_conn, "insert_known_coin", params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
break_db_err (result);
PQclear (result);
return GNUNET_SYSERR;
}
if (0 != strcmp ("1", PQcmdTuples (result)))
{
PQclear (result);
// return 'no' here (don't fail) so that we can
// update if insert fails (=> "upsert")
return GNUNET_NO;
}
PQclear (result);
return GNUNET_YES;
}
int
TALER_MINT_DB_upsert_known_coin (PGconn *db_conn,
struct KnownCoin *known_coin)
{
int ret;
ret = TALER_MINT_DB_update_known_coin (db_conn, known_coin);
if (GNUNET_SYSERR == ret)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
if (GNUNET_YES == ret)
return GNUNET_YES;
return TALER_MINT_DB_insert_known_coin (db_conn, known_coin);
}
struct GNUNET_CRYPTO_rsa_PublicKey *
TALER_MINT_DB_get_refresh_order (PGconn *db_conn,
uint16_t newcoin_index,

View File

@ -44,50 +44,6 @@ TALER_MINT_DB_insert_refresh_order (PGconn *db_conn,
/**
* FIXME
*/
struct KnownCoin
{
struct TALER_CoinPublicInfo public_info;
/**
* Refreshing session, only valid if
* is_refreshed==1.
*/
struct GNUNET_CRYPTO_EddsaPublicKey refresh_session_pub;
struct TALER_Amount expended_balance;
int is_refreshed;
};
int
TALER_MINT_DB_get_known_coin (PGconn *db_conn,
const struct GNUNET_CRYPTO_EcdsaPublicKey *coin_pub,
struct KnownCoin *known_coin);
// FIXME: what does 'upsert' even mean!?
int
TALER_MINT_DB_upsert_known_coin (PGconn *db_conn,
struct KnownCoin *known_coin);
int
TALER_MINT_DB_insert_known_coin (PGconn *db_conn,
const struct KnownCoin *known_coin);
struct GNUNET_CRYPTO_rsa_PublicKey *
TALER_MINT_DB_get_refresh_order (PGconn *db_conn,
uint16_t newcoin_index,

View File

@ -33,10 +33,9 @@
* + check for leaks
* + check low-level API
* - /refresh/link:
* + properly check all conditions and handle errors
* + properly check transaction logic
* + check for leaks
* + check low-level API
* + separate DB logic from response generation
* + check for leaks
*/
#include "platform.h"
#include <pthread.h>
@ -475,7 +474,7 @@ refresh_accept_denoms (struct MHD_Connection *connection,
* @param session_pub the refresh session's public key
* @param coin_count number of coins in @a coin_public_infos to melt
* @param coin_public_infos the coins to melt
* @param r_melt_balance FIXME
* @param r_melt_balance[OUT] FIXME (#3636: check earlier, pass expected value IN, not OUT!)
* @return #GNUNET_OK on success,
* #GNUNET_NO if an error message was generated,
* #GNUNET_SYSERR on internal errors (no response generated)
@ -490,68 +489,34 @@ refresh_accept_melts (struct MHD_Connection *connection,
struct TALER_Amount *r_melt_balance)
{
size_t i;
int res;
memset (r_melt_balance, 0, sizeof (struct TALER_Amount));
for (i = 0; i < coin_count; i++)
{
struct TALER_MINT_DenomKeyIssue *dki;
struct KnownCoin known_coin;
struct TALER_MINT_DB_TransactionList *tl;
// money the customer gets by melting the current coin
struct TALER_Amount coin_gain;
struct RefreshMelt melt;
dki = &(TALER_MINT_get_denom_key (key_state,
coin_public_infos[i].denom_pub)->issue);
dki = &TALER_MINT_get_denom_key (key_state,
coin_public_infos[i].denom_pub)->issue;
if (NULL == dki)
return (MHD_YES ==
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND,
"{s:s}",
"error", "denom not found"))
"error",
"denom not found"))
? GNUNET_NO : GNUNET_SYSERR;
res = TALER_MINT_DB_get_known_coin (db_conn,
&coin_public_infos[i].coin_pub,
&known_coin);
if (GNUNET_SYSERR == res)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
if (GNUNET_YES == res)
{
if (GNUNET_YES == known_coin.is_refreshed)
return (MHD_YES ==
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND,
"{s:s}",
"error",
"coin already refreshed"))
? GNUNET_NO : GNUNET_SYSERR;
}
else
{
known_coin.expended_balance = mint_amount_native_zero ();
known_coin.public_info = coin_public_infos[i];
}
known_coin.is_refreshed = GNUNET_YES;
known_coin.refresh_session_pub = *session_pub;
if (GNUNET_OK != TALER_MINT_DB_upsert_known_coin (db_conn, &known_coin))
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
// FIXME: test first if coin was already melted
// in this session, etc.
coin_gain = TALER_amount_ntoh (dki->value);
tl = TALER_MINT_DB_get_coin_transactions (db_conn,
&coin_public_infos[i].coin_pub);
/* FIXME: compute how much value is left with this coin! */
TALER_MINT_DB_free_coin_transaction_list (tl);
melt.coin = coin_public_infos[i];
melt.session_pub = *session_pub;
@ -566,22 +531,22 @@ refresh_accept_melts (struct MHD_Connection *connection,
return GNUNET_SYSERR;
}
coin_gain = TALER_amount_ntoh (dki->value);
coin_gain = TALER_amount_subtract (coin_gain, known_coin.expended_balance);
/* Refuse to refresh when the coin does not have enough money left to
* pay the refreshing fees of the coin. */
if (TALER_amount_cmp (coin_gain, TALER_amount_ntoh (dki->fee_refresh)) < 0)
if (TALER_amount_cmp (coin_gain,
TALER_amount_ntoh (dki->fee_refresh)) < 0)
return (MHD_YES ==
TALER_MINT_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND,
"{s:s}",
"error", "depleted")) ? GNUNET_NO : GNUNET_SYSERR;
coin_gain = TALER_amount_subtract (coin_gain, TALER_amount_ntoh (dki->fee_refresh));
*r_melt_balance = TALER_amount_add (*r_melt_balance, coin_gain);
coin_gain = TALER_amount_subtract (coin_gain,
TALER_amount_ntoh (dki->fee_refresh));
*r_melt_balance = TALER_amount_add (*r_melt_balance,
coin_gain);
}
return GNUNET_OK;
}
@ -647,8 +612,6 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
return TALER_MINT_reply_internal_db_error (connection);
}
session.melt_sig = *client_signature;
session.num_oldcoins = coin_count;
session.num_newcoins = num_new_denoms;
@ -1284,8 +1247,7 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
if (GNUNET_SYSERR == res)
{
GNUNET_break (0);
// FIXME: return error code!
return MHD_NO;
return TALER_MINT_reply_internal_db_error (connection);
}
if (GNUNET_NO == res)
{
@ -1308,7 +1270,7 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
if (GNUNET_SYSERR == res)
{
GNUNET_break (0);
// FIXME: return error code!
// FIXME: return error code!
return MHD_NO;
}
if (GNUNET_NO == res)