move deposit fee check to earlier

This commit is contained in:
Christian Grothoff 2015-03-22 16:20:03 +01:00
parent 3fe9a76098
commit 41478aea76
2 changed files with 14 additions and 11 deletions

View File

@ -105,7 +105,6 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
struct TALER_MINT_DB_TransactionList *tl; struct TALER_MINT_DB_TransactionList *tl;
struct TALER_Amount spent; struct TALER_Amount spent;
struct TALER_Amount value; struct TALER_Amount value;
struct TALER_Amount fee_deposit;
struct MintKeyState *mks; struct MintKeyState *mks;
struct TALER_MINT_DenomKeyIssuePriv *dki; struct TALER_MINT_DenomKeyIssuePriv *dki;
int ret; int ret;
@ -134,8 +133,6 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
deposit->coin.denom_pub); deposit->coin.denom_pub);
TALER_amount_ntoh (&value, TALER_amount_ntoh (&value,
&dki->issue.value); &dki->issue.value);
TALER_amount_ntoh (&fee_deposit,
&dki->issue.fee_deposit);
TALER_MINT_key_state_release (mks); TALER_MINT_key_state_release (mks);
if (GNUNET_OK != if (GNUNET_OK !=
@ -147,14 +144,6 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
} }
/* fee for THIS transaction */ /* fee for THIS transaction */
spent = deposit->amount_with_fee; spent = deposit->amount_with_fee;
if (TALER_amount_cmp (&fee_deposit,
&spent) < 0)
{
return (MHD_YES ==
TALER_MINT_reply_external_error (connection,
"deposited amount smaller than depositing fee"))
? GNUNET_NO : GNUNET_SYSERR;
}
/* add cost of all previous transactions */ /* add cost of all previous transactions */
tl = plugin->get_coin_transactions (plugin->cls, tl = plugin->get_coin_transactions (plugin->cls,
session, session,
@ -168,6 +157,8 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
tl); tl);
return TALER_MINT_reply_internal_db_error (connection); return TALER_MINT_reply_internal_db_error (connection);
} }
/* Check that cost of all transactions is smaller than
the value of the coin. */
if (0 < TALER_amount_cmp (&spent, if (0 < TALER_amount_cmp (&spent,
&value)) &value))
{ {

View File

@ -59,6 +59,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
struct MintKeyState *key_state; struct MintKeyState *key_state;
struct TALER_DepositRequest dr; struct TALER_DepositRequest dr;
struct TALER_MINT_DenomKeyIssuePriv *dki; struct TALER_MINT_DenomKeyIssuePriv *dki;
struct TALER_Amount fee_deposit;
dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_DEPOSIT); dr.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_DEPOSIT);
dr.purpose.size = htonl (sizeof (struct TALER_DepositRequest)); dr.purpose.size = htonl (sizeof (struct TALER_DepositRequest));
@ -97,6 +98,17 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
return TALER_MINT_reply_coin_invalid (connection); return TALER_MINT_reply_coin_invalid (connection);
} }
TALER_amount_ntoh (&fee_deposit,
&dki->issue.fee_deposit);
if (TALER_amount_cmp (&fee_deposit,
&deposit->amount_with_fee) < 0)
{
TALER_MINT_key_state_release (key_state);
return (MHD_YES ==
TALER_MINT_reply_external_error (connection,
"deposited amount smaller than depositing fee"))
? GNUNET_NO : GNUNET_SYSERR;
}
TALER_MINT_key_state_release (key_state); TALER_MINT_key_state_release (key_state);
return TALER_MINT_db_execute_deposit (connection, return TALER_MINT_db_execute_deposit (connection,