mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Change over to STAmount.
This commit is contained in:
@@ -31,7 +31,7 @@ public:
|
||||
AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger
|
||||
|
||||
const NewcoinAddress& getAccountID() const { return mAccountID; }
|
||||
uint64 getBalance() const { return mLedgerEntry->getIFieldU64(sfBalance); }
|
||||
STAmount getBalance() const { return mLedgerEntry->getIValueFieldAmount(sfBalance); }
|
||||
uint32 getSeq() const { return mLedgerEntry->getIFieldU32(sfSequence); }
|
||||
|
||||
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
|
||||
|
||||
@@ -26,7 +26,7 @@ Ledger::Ledger(const NewcoinAddress& masterID, uint64 startAmount) : mTotCoins(s
|
||||
|
||||
// special case: put coins in root account
|
||||
AccountState::pointer startAccount = boost::make_shared<AccountState>(masterID);
|
||||
startAccount->peekSLE().setIFieldU64(sfBalance, startAmount);
|
||||
startAccount->peekSLE().setIFieldAmount(sfBalance, startAmount);
|
||||
startAccount->peekSLE().setIFieldU32(sfSequence, 1);
|
||||
writeBack(lepCREATE, startAccount->getSLE());
|
||||
#ifdef DEBUG
|
||||
@@ -55,7 +55,7 @@ Ledger::Ledger(Ledger::pointer prevLedger) : mParentHash(prevLedger->getHash()),
|
||||
mCloseTime = prevLedger->getNextLedgerClose();
|
||||
}
|
||||
|
||||
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mCloseTime(0),
|
||||
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mCloseTime(0),
|
||||
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
||||
{
|
||||
Serializer s(rawLedger);
|
||||
@@ -75,7 +75,7 @@ Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mClo
|
||||
}
|
||||
}
|
||||
|
||||
Ledger::Ledger(const std::string& rawLedger) : mTotCoins(0), mCloseTime(0),
|
||||
Ledger::Ledger(const std::string& rawLedger) : mCloseTime(0),
|
||||
mLedgerSeq(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(true)
|
||||
{
|
||||
Serializer s(rawLedger);
|
||||
@@ -154,11 +154,11 @@ bool Ledger::addTransaction(Transaction::pointer trans)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ledger::addTransaction(const uint256& txID, const Serializer& txn, uint64_t fee)
|
||||
bool Ledger::addTransaction(const uint256& txID, const Serializer& txn, STAmount saPaid)
|
||||
{ // low-level - just add to table
|
||||
SHAMapItem::pointer item = boost::make_shared<SHAMapItem>(txID, txn.peekData());
|
||||
if (!mTransactionMap->addGiveItem(item, true)) return false;
|
||||
mTotCoins -= fee;
|
||||
mTotCoins -= saPaid;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
16
src/Ledger.h
16
src/Ledger.h
@@ -54,12 +54,12 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
||||
uint64 mTotCoins;
|
||||
uint64 mCloseTime; // when this ledger closes
|
||||
uint32 mLedgerSeq;
|
||||
uint16 mLedgerInterval;
|
||||
bool mClosed, mValidHash, mAccepted, mImmutable;
|
||||
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
||||
uint64 mTotCoins;
|
||||
uint64 mCloseTime; // when this ledger closes
|
||||
uint32 mLedgerSeq;
|
||||
uint16 mLedgerInterval;
|
||||
bool mClosed, mValidHash, mAccepted, mImmutable;
|
||||
|
||||
SHAMap::pointer mTransactionMap, mAccountStateMap;
|
||||
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
protected:
|
||||
|
||||
bool addTransaction(Transaction::pointer);
|
||||
bool addTransaction(const uint256& id, const Serializer& txn, uint64_t fee);
|
||||
bool addTransaction(const uint256& id, const Serializer& txn, STAmount saPaid);
|
||||
|
||||
static Ledger::pointer getSQL(const std::string& sqlStatement);
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
const uint256& getParentHash() const { return mParentHash; }
|
||||
const uint256& getTransHash() const { return mTransHash; }
|
||||
const uint256& getAccountHash() const { return mAccountHash; }
|
||||
uint64 getTotalCoins() const { return mTotCoins; }
|
||||
STAmount getTotalCoins() const { return mTotCoins; }
|
||||
uint64 getCloseTimeNC() const { return mCloseTime; }
|
||||
uint32 getLedgerSeq() const { return mLedgerSeq; }
|
||||
uint16 getInterval() const { return mLedgerInterval; }
|
||||
|
||||
@@ -9,7 +9,7 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Balance), STI_UINT64, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(LastReceive), STI_UINT32, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(LastTxn), STI_UINT32, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(AuthorizedKey),STI_HASH160, SOE_IFFLAG, 1 },
|
||||
@@ -39,12 +39,11 @@ LedgerEntryFormat LedgerFormats[]=
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Borrower), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Lender), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(Limit), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 8 },
|
||||
{ S_FIELD(CurrentRate), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(RateLock), STI_UINT32, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(NextRate), STI_UINT32, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(NextRateLgr), STI_UINT32, SOE_IFFLAG, 8 },
|
||||
{ S_FIELD(NextRateExp), STI_UINT32, SOE_IFFLAG, 16 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x01000000 },
|
||||
|
||||
@@ -618,7 +618,7 @@ Json::Value RPCServer::doWalletClaim(Json::Value& params)
|
||||
naRegular0Public.getAccountPublic(),
|
||||
vucGeneratorSig);
|
||||
|
||||
(void) theApp->getOPs().processTransaction(trns);
|
||||
// (void) theApp->getOPs().processTransaction(trns);
|
||||
|
||||
Json::Value obj(Json::objectValue);
|
||||
|
||||
@@ -691,10 +691,11 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
||||
return "source account does not exist";
|
||||
}
|
||||
|
||||
uint64 uSrcBalance = sleSrc->getIFieldU64(sfBalance);
|
||||
uint64 uInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast<uint64>(params[3u].asString());
|
||||
STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
|
||||
STAmount saInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast<uint64>(params[3u].asString());
|
||||
|
||||
if (uSrcBalance < theConfig.FEE_CREATE + uInitialFunds)
|
||||
#if 0
|
||||
if (saSrcBalance < theConfig.FEE_CREATE + saInitialFunds)
|
||||
{
|
||||
return "insufficent funds";
|
||||
}
|
||||
@@ -702,7 +703,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
||||
{
|
||||
return "source account has not been claimed";
|
||||
}
|
||||
|
||||
#endif
|
||||
NewcoinAddress naRegularGenerator;
|
||||
NewcoinAddress naRegular0Public;
|
||||
NewcoinAddress naRegular0Private;
|
||||
@@ -765,7 +766,7 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params)
|
||||
theConfig.FEE_CREATE,
|
||||
0, // YYY No source tag
|
||||
naCreateID,
|
||||
uInitialFunds); // Initial funds in XNC.
|
||||
saInitialFunds); // Initial funds in XNC.
|
||||
|
||||
(void) theApp->getOPs().processTransaction(trans);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
{ return mObject.setValueFieldAccount(field, account); }
|
||||
void setIFieldAccount(SOE_Field field, const NewcoinAddress& account)
|
||||
{ return mObject.setValueFieldAccount(field, account); }
|
||||
void setIFeldAmount(SOE_Field field, const STAmount& amount)
|
||||
void setIFieldAmount(SOE_Field field, const STAmount& amount)
|
||||
{ return mObject.setValueFieldAmount(field, amount); }
|
||||
|
||||
bool getIFieldPresent(SOE_Field field) const { return mObject.isFieldPresent(field); }
|
||||
|
||||
@@ -160,18 +160,18 @@ void SerializedTransaction::setVersion(uint32 ver)
|
||||
v->setValue(ver);
|
||||
}
|
||||
|
||||
uint64 SerializedTransaction::getTransactionFee() const
|
||||
STAmount SerializedTransaction::getTransactionFee() const
|
||||
{
|
||||
const STUInt64* v = dynamic_cast<const STUInt64*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
||||
const STAmount* v = dynamic_cast<const STAmount*>(mMiddleTxn.peekAtPIndex(TransactionIFee));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
return v->getValue();
|
||||
}
|
||||
|
||||
void SerializedTransaction::setTransactionFee(uint64 fee)
|
||||
void SerializedTransaction::setTransactionFee(STAmount saFee)
|
||||
{
|
||||
STUInt64* v = dynamic_cast<STUInt64*>(mMiddleTxn.getPIndex(TransactionIFee));
|
||||
if (!v) throw std::runtime_error("corrupt transaction");
|
||||
v->setValue(fee);
|
||||
v->setValue(saFee);
|
||||
}
|
||||
|
||||
uint32 SerializedTransaction::getSequence() const
|
||||
|
||||
@@ -48,8 +48,8 @@ public:
|
||||
void setVersion(uint32);
|
||||
|
||||
TransactionType getTxnType() const { return mType; }
|
||||
uint64 getTransactionFee() const;
|
||||
void setTransactionFee(uint64);
|
||||
STAmount getTransactionFee() const;
|
||||
void setTransactionFee(STAmount saFee);
|
||||
|
||||
const NewcoinAddress& getSourceAccount() const { return mSourceAccount; }
|
||||
std::vector<unsigned char> getSigningPubKey() const;
|
||||
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
friend STAmount divide(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
||||
friend STAmount multiply(const STAmount& v1, const STAmount& v2, const uint160& currencyOut);
|
||||
|
||||
// Someone iis offering X for Y, what is the rate?
|
||||
// Someone is offering X for Y, what is the rate?
|
||||
friend uint64 getRate(const STAmount& offerOut, const STAmount& offerIn);
|
||||
|
||||
// Someone is offering X for Y, I try to pay Z, how much do I get?
|
||||
|
||||
@@ -56,7 +56,7 @@ Transaction::Transaction(
|
||||
const NewcoinAddress& naPublicKey,
|
||||
const NewcoinAddress& naSourceAccount,
|
||||
uint32 uSeq,
|
||||
uint64 uFee,
|
||||
STAmount saFee,
|
||||
uint32 uSourceTag) :
|
||||
mStatus(NEW)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ Transaction::Transaction(
|
||||
mTransaction->setSigningPubKey(mFromPubKey);
|
||||
mTransaction->setSourceAccount(mAccountFrom);
|
||||
mTransaction->setSequence(uSeq);
|
||||
mTransaction->setTransactionFee(uFee);
|
||||
mTransaction->setTransactionFee(saFee);
|
||||
|
||||
if (uSourceTag)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ Transaction::pointer Transaction::sharedClaim(
|
||||
Transaction::pointer Transaction::setCreate(
|
||||
const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naCreateAccountID,
|
||||
uint64 uFund)
|
||||
STAmount uFund)
|
||||
{
|
||||
mTransaction->setITFieldU32(sfFlags, tfCreateAccount);
|
||||
mTransaction->setITFieldAccount(sfDestination, naCreateAccountID);
|
||||
@@ -170,14 +170,14 @@ Transaction::pointer Transaction::sharedCreate(
|
||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naSourceAccount,
|
||||
uint32 uSeq,
|
||||
uint64 uFee,
|
||||
STAmount saFee,
|
||||
uint32 uSourceTag,
|
||||
const NewcoinAddress& naCreateAccountID,
|
||||
uint64 uFund)
|
||||
STAmount uFund)
|
||||
{
|
||||
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
||||
naPublicKey, naSourceAccount,
|
||||
uSeq, uFee, uSourceTag);
|
||||
uSeq, saFee, uSourceTag);
|
||||
|
||||
return tResult->setCreate(naPrivateKey, naCreateAccountID, uFund);
|
||||
}
|
||||
@@ -189,10 +189,10 @@ Transaction::pointer Transaction::sharedCreate(
|
||||
Transaction::pointer Transaction::setPayment(
|
||||
const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& toAccount,
|
||||
uint64 uAmount)
|
||||
STAmount saAmount)
|
||||
{
|
||||
mTransaction->setITFieldAccount(sfDestination, toAccount);
|
||||
mTransaction->setITFieldU64(sfAmount, uAmount);
|
||||
mTransaction->setITFieldU64(sfAmount, saAmount);
|
||||
|
||||
sign(naPrivateKey);
|
||||
|
||||
@@ -203,16 +203,16 @@ Transaction::pointer Transaction::sharedPayment(
|
||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naSourceAccount,
|
||||
uint32 uSeq,
|
||||
uint64 uFee,
|
||||
STAmount saFee,
|
||||
uint32 uSourceTag,
|
||||
const NewcoinAddress& toAccount,
|
||||
uint64 uAmount)
|
||||
STAmount saAmount)
|
||||
{
|
||||
pointer tResult = boost::make_shared<Transaction>(ttPAYMENT,
|
||||
naPublicKey, naSourceAccount,
|
||||
uSeq, uFee, uSourceTag);
|
||||
uSeq, saFee, uSourceTag);
|
||||
|
||||
return tResult->setPayment(naPrivateKey, toAccount, uAmount);
|
||||
return tResult->setPayment(naPrivateKey, toAccount, saAmount);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -56,12 +56,12 @@ private:
|
||||
Transaction::pointer setCreate(
|
||||
const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naCreateAccountID,
|
||||
uint64 uFund);
|
||||
STAmount uFund);
|
||||
|
||||
Transaction::pointer setPayment(
|
||||
const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& toAccount,
|
||||
uint64 uAmount);
|
||||
STAmount saAmount);
|
||||
|
||||
public:
|
||||
Transaction(const SerializedTransaction::pointer st, bool bValidate);
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
const NewcoinAddress& naPublicKey, // To prove transaction is consistent and authorized.
|
||||
const NewcoinAddress& naSourceAccount, // To identify the paying account.
|
||||
uint32 uSeq, // To order transactions.
|
||||
uint64 uFee, // Transaction fee.
|
||||
STAmount saFee, // Transaction fee.
|
||||
uint32 uSourceTag); // User call back value.
|
||||
|
||||
// Claim a wallet.
|
||||
@@ -90,26 +90,20 @@ public:
|
||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naSourceAccount,
|
||||
uint32 uSeq,
|
||||
uint64 uFee,
|
||||
STAmount saFee,
|
||||
uint32 uSourceTag,
|
||||
const NewcoinAddress& naCreateAccountID, // Account to create.
|
||||
uint64 uFund); // Initial funds in XNC.
|
||||
STAmount uFund); // Initial funds in XNC.
|
||||
|
||||
// Make a payment.
|
||||
static Transaction::pointer sharedPayment(
|
||||
const NewcoinAddress& naPublicKey, const NewcoinAddress& naPrivateKey,
|
||||
const NewcoinAddress& naSourceAccount,
|
||||
uint32 uSeq,
|
||||
uint64 uFee,
|
||||
STAmount saFee,
|
||||
uint32 uSourceTag,
|
||||
const NewcoinAddress& toAccount,
|
||||
uint64 uAmount);
|
||||
|
||||
#if 0
|
||||
Transaction(const NewcoinAddress& fromID, const NewcoinAddress& toID,
|
||||
CKey::pointer pubKey, uint64 uAmount, uint64 fee, uint32 fromSeq, uint32 fromLedger,
|
||||
uint32 ident, const std::vector<unsigned char>& signature, uint32 ledgerSeq, TransStatus st);
|
||||
#endif
|
||||
STAmount saAmount);
|
||||
|
||||
bool sign(const NewcoinAddress& naAccountPrivate);
|
||||
bool checkSign() const;
|
||||
@@ -119,8 +113,8 @@ public:
|
||||
|
||||
const uint256& getID() const { return mTransactionID; }
|
||||
const NewcoinAddress& getFromAccount() const { return mAccountFrom; }
|
||||
uint64 getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
||||
uint64 getFee() const { return mTransaction->getTransactionFee(); }
|
||||
STAmount getAmount() const { return mTransaction->getITFieldU64(sfAmount); }
|
||||
STAmount getFee() const { return mTransaction->getTransactionFee(); }
|
||||
uint32 getFromAccountSeq() const { return mTransaction->getSequence(); }
|
||||
uint32 getSourceLedger() const { return mTransaction->getITFieldU32(sfTargetLedger); }
|
||||
uint32 getIdent() const { return mTransaction->getITFieldU32(sfSourceTag); }
|
||||
@@ -155,11 +149,6 @@ public:
|
||||
|
||||
protected:
|
||||
static Transaction::pointer transactionFromSQL(const std::string& statement);
|
||||
#if 0
|
||||
Transaction(const uint256& transactionID, const NewcoinAddress& accountFrom, const NewcoinAddress& accountTo,
|
||||
CKey::pointer key, uint64 uAmount, uint64 fee, uint32 fromAccountSeq, uint32 sourceLedger,
|
||||
uint32 ident, const std::vector<unsigned char>& signature, uint32 inLedger, TransStatus status);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,19 +35,19 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
return tenINVALID;
|
||||
}
|
||||
|
||||
uint64 uFee = theConfig.FEE_DEFAULT;
|
||||
STAmount saCost = theConfig.FEE_DEFAULT;
|
||||
|
||||
// Customize behavoir based on transaction type.
|
||||
switch(txn.getTxnType())
|
||||
{
|
||||
case ttCLAIM:
|
||||
uFee = 0;
|
||||
saCost = 0;
|
||||
break;
|
||||
|
||||
case ttPAYMENT:
|
||||
if (txn.getFlags() & tfCreateAccount)
|
||||
{
|
||||
uFee = theConfig.FEE_CREATE;
|
||||
saCost = theConfig.FEE_CREATE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -70,13 +70,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
if (terSUCCESS != result)
|
||||
return result;
|
||||
|
||||
uint64 txnFee = txn.getTransactionFee();
|
||||
STAmount saPaid = txn.getTransactionFee();
|
||||
if ( (params & tepNO_CHECK_FEE) != tepNONE)
|
||||
{
|
||||
if (uFee)
|
||||
if (saCost)
|
||||
{
|
||||
// WRITEME: Check if fee is adequate
|
||||
if (txnFee == 0)
|
||||
if (saPaid < saCost)
|
||||
{
|
||||
std::cerr << "applyTransaction: insufficient fee" << std::endl;
|
||||
return tenINSUF_FEE_P;
|
||||
@@ -84,7 +83,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
}
|
||||
else
|
||||
{
|
||||
if (txnFee)
|
||||
if (!saPaid.isZero())
|
||||
{
|
||||
// Transaction is malformed.
|
||||
std::cerr << "applyTransaction: fee not allowed" << std::endl;
|
||||
@@ -105,9 +104,9 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
|
||||
// find source account
|
||||
// If we are only verifying some transactions, this would be probablistic.
|
||||
LedgerStateParms qry = lepNONE;
|
||||
SerializedLedgerEntry::pointer src = mLedger->getAccountRoot(qry, srcAccountID);
|
||||
if (!src)
|
||||
LedgerStateParms qry = lepNONE;
|
||||
SerializedLedgerEntry::pointer sleSrc = mLedger->getAccountRoot(qry, srcAccountID);
|
||||
if (!sleSrc)
|
||||
{
|
||||
std::cerr << str(boost::format("applyTransaction: Delay transaction: source account does not exisit: %s") % txn.getSourceAccount().humanAccountID()) << std::endl;
|
||||
return terNO_ACCOUNT;
|
||||
@@ -115,25 +114,25 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
|
||||
// deduct the fee, so it's not available during the transaction
|
||||
// we only write the account back if the transaction succeeds
|
||||
if (txnFee)
|
||||
if (!saCost.isZero())
|
||||
{
|
||||
uint64 uSrcBalance = src->getIFieldU64(sfBalance);
|
||||
STAmount saSrcBalance = sleSrc->getIValueFieldAmount(sfBalance);
|
||||
|
||||
if (uSrcBalance < txnFee)
|
||||
if (saSrcBalance < saPaid)
|
||||
{
|
||||
std::cerr << "applyTransaction: Delay transaction: insufficent balance" << std::endl;
|
||||
return terINSUF_FEE_B;
|
||||
}
|
||||
|
||||
src->setIFieldU64(sfBalance, uSrcBalance - txnFee);
|
||||
sleSrc->setIFieldAmount(sfBalance, saSrcBalance - saPaid);
|
||||
}
|
||||
|
||||
// Validate sequence
|
||||
uint32 t_seq = txn.getSequence();
|
||||
|
||||
if (uFee)
|
||||
if (saCost)
|
||||
{
|
||||
uint32 a_seq = src->getIFieldU32(sfSequence);
|
||||
uint32 a_seq = sleSrc->getIFieldU32(sfSequence);
|
||||
|
||||
if (t_seq != a_seq)
|
||||
{
|
||||
@@ -152,7 +151,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
std::cerr << "applyTransaction: past sequence number" << std::endl;
|
||||
return terPAST_SEQ;
|
||||
}
|
||||
else src->setIFieldU32(sfSequence, t_seq);
|
||||
else sleSrc->setIFieldU32(sfSequence, t_seq);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -164,7 +163,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
}
|
||||
|
||||
std::vector<AffectedAccount> accounts;
|
||||
accounts.push_back(std::make_pair(taaMODIFY, src));
|
||||
accounts.push_back(std::make_pair(taaMODIFY, sleSrc));
|
||||
|
||||
switch(txn.getTxnType())
|
||||
{
|
||||
@@ -219,7 +218,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
|
||||
|
||||
Serializer s;
|
||||
txn.add(s);
|
||||
mLedger->addTransaction(txID, s, txnFee);
|
||||
mLedger->addTransaction(txID, s, saPaid);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -384,20 +383,20 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction
|
||||
accounts.push_back(std::make_pair(taaMODIFY, dest));
|
||||
}
|
||||
|
||||
uint64 uAmount = txn.getITFieldU64(sfAmount);
|
||||
STAmount saAmount = txn.getITFieldAmount(sfAmount);
|
||||
|
||||
if (!currency)
|
||||
{
|
||||
uint64 uSrcBalance = accounts[0].second->getIFieldU64(sfBalance);
|
||||
STAmount saSrcBalance = accounts[0].second->getIValueFieldAmount(sfBalance);
|
||||
|
||||
if (uSrcBalance < uAmount)
|
||||
if (saSrcBalance < saAmount)
|
||||
{
|
||||
std::cerr << "doPayment: Delay transaction: Insufficent funds." << std::endl;
|
||||
return terUNFUNDED;
|
||||
}
|
||||
|
||||
accounts[0].second->setIFieldU64(sfBalance, uSrcBalance - uAmount);
|
||||
accounts[1].second->setIFieldU64(sfBalance, accounts[1].second->getIFieldU64(sfBalance) + uAmount);
|
||||
accounts[0].second->setIFieldAmount(sfBalance, saSrcBalance - saAmount);
|
||||
accounts[1].second->setIFieldAmount(sfBalance, accounts[1].second->getIValueFieldAmount(sfBalance) + saAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -9,9 +9,8 @@ TransactionFormat InnerTxnFormats[]=
|
||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
||||
{ S_FIELD(Currency), STI_HASH160, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 4 },
|
||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
||||
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 2 },
|
||||
{ S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },
|
||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user