Transaction fee handling.

This commit is contained in:
JoelKatz
2012-04-22 16:27:55 -07:00
parent 585d800fb4
commit adf0313ab8

View File

@@ -15,7 +15,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
// check signature
if (!txn.checkSign(acctKey)) return terINVALID;
// WRITEME: Check fee
uint64 txnFee = txn.getTransactionFee();
if ( (params & tepNO_CHECK_FEE) != tepNONE)
{
// WRITEME: Check if fee is adequate
if (txnFee == 0) return terINSUF_FEE_P;
}
// get source account ID
uint160 srcAccount = txn.getSigningAccount();
@@ -28,6 +33,13 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
SerializedLedgerEntry::pointer src = mLedger->getAccountRoot(qry, srcAccount);
if (!src) return terNO_ACCOUNT;
// deduct the fee, so it's not available during the transaction
// we only write the account back if the transaction succeeds
uint64 balance = src->getIFieldU64(sfBalance);
if (balance < txnFee)
return terINSUF_FEE_B;
src->setIFieldU64(sfBalance, balance - txnFee);
// validate sequence
uint32 t_seq = txn.getSequence();
uint32 a_seq = src->getIFieldU32(sfSequence);
@@ -81,3 +93,39 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
return result;
}
TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction& txn, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doInvoice(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doOffer(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doTake(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doCancel(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doStore(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}
TransactionEngineResult TransactionEngine::doDelete(const SerializedTransaction&, SerializedLedgerEntry& source)
{
return terUNKNOWN;
}