Use Config for fees in TransactionEngine.

This commit is contained in:
Arthur Britto
2012-05-17 20:35:26 -07:00
parent b8333f8d92
commit 0ead1d02ec
2 changed files with 38 additions and 23 deletions

View File

@@ -1,4 +1,6 @@
#include "TransactionEngine.h" #include "TransactionEngine.h"
#include "Config.h"
#include "TransactionFormats.h" #include "TransactionFormats.h"
#include <boost/format.hpp> #include <boost/format.hpp>
@@ -33,16 +35,22 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
return tenINVALID; return tenINVALID;
} }
bool bPrepaid = false; uint64 uFee = theConfig.FEE_DEFAULT;
// Customize behavoir based on transaction type. // Customize behavoir based on transaction type.
switch(txn.getTxnType()) switch(txn.getTxnType())
{ {
case ttCLAIM: case ttCLAIM:
bPrepaid = true; uFee = 0;
break; break;
case ttPAYMENT: case ttPAYMENT:
if (txn.getFlags() & tfCreateAccount)
{
uFee = theConfig.FEE_CREATE;
}
break;
case ttINVOICE: case ttINVOICE:
case ttEXCHANGE_OFFER: case ttEXCHANGE_OFFER:
result = terSUCCESS; result = terSUCCESS;
@@ -65,16 +73,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
uint64 txnFee = txn.getTransactionFee(); uint64 txnFee = txn.getTransactionFee();
if ( (params & tepNO_CHECK_FEE) != tepNONE) if ( (params & tepNO_CHECK_FEE) != tepNONE)
{ {
if (bPrepaid) if (uFee)
{
if (txnFee)
{
// Transaction is malformed.
std::cerr << "applyTransaction: fee not allowed" << std::endl;
return tenINSUF_FEE_P;
}
}
else
{ {
// WRITEME: Check if fee is adequate // WRITEME: Check if fee is adequate
if (txnFee == 0) if (txnFee == 0)
@@ -83,6 +82,15 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
return tenINSUF_FEE_P; return tenINSUF_FEE_P;
} }
} }
else
{
if (txnFee)
{
// Transaction is malformed.
std::cerr << "applyTransaction: fee not allowed" << std::endl;
return tenINSUF_FEE_P;
}
}
} }
// Get source account ID. // Get source account ID.
@@ -123,15 +131,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
// Validate sequence // Validate sequence
uint32 t_seq = txn.getSequence(); uint32 t_seq = txn.getSequence();
if (bPrepaid) if (uFee)
{
if (t_seq)
{
std::cerr << "applyTransaction: bad sequence for pre-paid transaction" << std::endl;
return terPAST_SEQ;
}
}
else
{ {
uint32 a_seq = src->getIFieldU32(sfSequence); uint32 a_seq = src->getIFieldU32(sfSequence);
@@ -154,6 +154,14 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
} }
else src->setIFieldU32(sfSequence, t_seq); else src->setIFieldU32(sfSequence, t_seq);
} }
else
{
if (t_seq)
{
std::cerr << "applyTransaction: bad sequence for pre-paid transaction" << std::endl;
return terPAST_SEQ;
}
}
std::vector<AffectedAccount> accounts; std::vector<AffectedAccount> accounts;
accounts.push_back(std::make_pair(taaMODIFY, src)); accounts.push_back(std::make_pair(taaMODIFY, src));
@@ -326,12 +334,18 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
return tenINVALID; return tenINVALID;
} }
bool bCreate = !(txFlags & tfCreateAccount); bool bCreate = !!(txFlags & tfCreateAccount);
uint160 currency; uint160 currency;
if (txn.getITFieldPresent(sfCurrency)) if (txn.getITFieldPresent(sfCurrency))
{
currency = txn.getITFieldH160(sfCurrency); currency = txn.getITFieldH160(sfCurrency);
// XXX No XNC don't allow currency. if (!currency)
{
std::cerr << "doPayment: Invalid transaction: XNC explicitly specified." << std::endl;
return tenEXPLICITXNC;
}
}
LedgerStateParms qry = lepNONE; LedgerStateParms qry = lepNONE;

View File

@@ -17,6 +17,7 @@ enum TransactionEngineResult
// Malformed // Malformed
tenGEN_IN_USE = -300, // Generator already in use. tenGEN_IN_USE = -300, // Generator already in use.
tenCREATEXNC, // Can not specify non XNC for Create. tenCREATEXNC, // Can not specify non XNC for Create.
tenEXPLICITXNC, // XNC is used by default, don't specify it.
// Not possible due to ledger database. // Not possible due to ledger database.
tenCREATED = -200, // Can not create a previously created account. tenCREATED = -200, // Can not create a previously created account.