move refresh fee check to earlier

This commit is contained in:
Christian Grothoff 2015-03-22 16:17:22 +01:00
parent 4ec78fba4e
commit 3fe9a76098
2 changed files with 17 additions and 20 deletions

View File

@ -510,8 +510,6 @@ refresh_accept_melts (struct MHD_Connection *connection,
{ {
struct TALER_MINT_DenomKeyIssue *dki; struct TALER_MINT_DenomKeyIssue *dki;
struct TALER_MINT_DB_TransactionList *tl; struct TALER_MINT_DB_TransactionList *tl;
struct TALER_Amount fee_deposit;
struct TALER_Amount fee_refresh;
struct TALER_Amount coin_value; struct TALER_Amount coin_value;
struct TALER_Amount coin_residual; struct TALER_Amount coin_residual;
struct TALER_Amount spent; struct TALER_Amount spent;
@ -530,22 +528,10 @@ refresh_accept_melts (struct MHD_Connection *connection,
"denom not found")) "denom not found"))
? GNUNET_NO : GNUNET_SYSERR; ? GNUNET_NO : GNUNET_SYSERR;
TALER_amount_ntoh (&fee_deposit,
&dki->fee_deposit);
TALER_amount_ntoh (&fee_refresh,
&dki->fee_refresh);
TALER_amount_ntoh (&coin_value, TALER_amount_ntoh (&coin_value,
&dki->value); &dki->value);
/* fee for THIS transaction; the melt amount includes the fee! */ /* fee for THIS transaction; the melt amount includes the fee! */
spent = coin_details->melt_amount_with_fee; spent = coin_details->melt_amount_with_fee;
if (TALER_amount_cmp (&fee_refresh,
&spent) < 0)
{
return (MHD_YES ==
TALER_MINT_reply_external_error (connection,
"melt amount smaller than melting fee"))
? GNUNET_NO : GNUNET_SYSERR;
}
/* add historic transaction costs of this coin */ /* add historic transaction costs of this coin */
tl = plugin->get_coin_transactions (plugin->cls, tl = plugin->get_coin_transactions (plugin->cls,
session, session,
@ -560,8 +546,8 @@ refresh_accept_melts (struct MHD_Connection *connection,
tl); tl);
return TALER_MINT_reply_internal_db_error (connection); return TALER_MINT_reply_internal_db_error (connection);
} }
/* Refuse to refresh when the coin does not have enough money left to /* Refuse to refresh when the coin's value is insufficient
* pay the refreshing fees of the coin. */ for the cost of all transactions. */
if (TALER_amount_cmp (&coin_value, if (TALER_amount_cmp (&coin_value,
&spent) < 0) &spent) < 0)
{ {

View File

@ -282,9 +282,8 @@ verify_coin_public_info (struct MHD_Connection *connection,
struct RefreshMeltCoinSignature body; struct RefreshMeltCoinSignature body;
struct MintKeyState *key_state; struct MintKeyState *key_state;
struct TALER_MINT_DenomKeyIssuePriv *dki; struct TALER_MINT_DenomKeyIssuePriv *dki;
struct TALER_Amount fee_refresh;
/* FIXME: include amount of coin value to be melted here (#3636!) and
in what we return!? */
body.purpose.size = htonl (sizeof (struct RefreshMeltCoinSignature)); body.purpose.size = htonl (sizeof (struct RefreshMeltCoinSignature));
body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_COIN); body.purpose.purpose = htonl (TALER_SIGNATURE_REFRESH_MELT_COIN);
body.melt_hash = *melt_hash; body.melt_hash = *melt_hash;
@ -308,8 +307,6 @@ verify_coin_public_info (struct MHD_Connection *connection,
key_state = TALER_MINT_key_state_acquire (); key_state = TALER_MINT_key_state_acquire ();
dki = TALER_MINT_get_denom_key (key_state, dki = TALER_MINT_get_denom_key (key_state,
r_public_info->denom_pub); r_public_info->denom_pub);
/* FIXME: need to check if denomination key is still
valid for issuing! (#3634) */
if (NULL == dki) if (NULL == dki)
{ {
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
@ -317,6 +314,20 @@ verify_coin_public_info (struct MHD_Connection *connection,
return TALER_MINT_reply_arg_invalid (connection, return TALER_MINT_reply_arg_invalid (connection,
"denom_pub"); "denom_pub");
} }
/* FIXME: need to check if denomination key is still
valid for issuing! (#3634) */
TALER_amount_ntoh (&fee_refresh,
&dki->issue.fee_refresh);
if (TALER_amount_cmp (&fee_refresh,
&r_melt_detail->melt_amount_with_fee) < 0)
{
TALER_MINT_key_state_release (key_state);
return (MHD_YES ==
TALER_MINT_reply_external_error (connection,
"melt amount smaller than melting fee"))
? GNUNET_NO : GNUNET_SYSERR;
}
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
return GNUNET_OK; return GNUNET_OK;
} }