Really fix KillOrFill.

This commit is contained in:
Arthur Britto
2013-03-07 17:41:45 -08:00
parent 15942616e8
commit f8799a6558
2 changed files with 24 additions and 20 deletions

View File

@@ -38,6 +38,7 @@ TER OfferCreateTransactor::takeOffers(
cLog(lsINFO) << "takeOffers: against book: " << uBookBase.ToString();
LedgerEntrySet& lesActive = mEngine->getNodes();
uint256 uTipIndex = uBookBase;
const uint256 uBookEnd = Ledger::getQualityNext(uBookBase);
const uint64 uTakeQuality = STAmount::getRate(saTakerGets, saTakerPays);
@@ -57,7 +58,7 @@ TER OfferCreateTransactor::takeOffers(
{
SLE::pointer sleOfferDir;
uint64 uTipQuality = 0;
STAmount saTakerFunds = mEngine->getNodes().accountFunds(uTakerAccountID, saTakerPays);
STAmount saTakerFunds = lesActive.accountFunds(uTakerAccountID, saTakerPays);
STAmount saSubTakerPays = saTakerPays-saTakerPaid; // How much more to spend.
STAmount saSubTakerGets = saTakerGets-saTakerGot; // How much more is wanted.
@@ -130,7 +131,7 @@ TER OfferCreateTransactor::takeOffers(
unsigned int uBookEntry;
uint256 uOfferIndex;
mEngine->getNodes().dirFirst(uTipIndex, sleBookNode, uBookEntry, uOfferIndex);
lesActive.dirFirst(uTipIndex, sleBookNode, uBookEntry, uOfferIndex);
SLE::pointer sleOffer = mEngine->entryCache(ltOFFER, uOfferIndex);
@@ -168,7 +169,7 @@ TER OfferCreateTransactor::takeOffers(
cLog(lsINFO) << "takeOffers: saOfferPays=" << saOfferPays.getFullText();
STAmount saOfferFunds = mEngine->getNodes().accountFunds(uOfferOwnerID, saOfferPays);
STAmount saOfferFunds = lesActive.accountFunds(uOfferOwnerID, saOfferPays);
SLE::pointer sleOfferAccount; // Owner of offer.
if (!saOfferFunds.isPositive()) // Includes zero.
@@ -209,8 +210,8 @@ TER OfferCreateTransactor::takeOffers(
cLog(lsINFO) << "takeOffers: applyOffer: saTakerGets: " << saTakerGets.getFullText();
bool bOfferDelete = STAmount::applyOffer(
mEngine->getNodes().rippleTransferRate(uTakerAccountID, uOfferOwnerID, uTakerPaysAccountID),
mEngine->getNodes().rippleTransferRate(uOfferOwnerID, uTakerAccountID, uTakerGetsAccountID),
lesActive.rippleTransferRate(uTakerAccountID, uOfferOwnerID, uTakerPaysAccountID),
lesActive.rippleTransferRate(uOfferOwnerID, uTakerAccountID, uTakerGetsAccountID),
saOfferRate,
saOfferFunds,
saTakerFunds,
@@ -273,10 +274,10 @@ TER OfferCreateTransactor::takeOffers(
{
// Distribute funds. The sends charge appropriate fees which are implied by offer.
terResult = mEngine->getNodes().accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot); // Offer owner pays taker.
terResult = lesActive.accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot); // Offer owner pays taker.
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid); // Taker pays offer owner.
terResult = lesActive.accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid); // Taker pays offer owner.
// Reduce amount considered paid by taker's rate (not actual cost).
STAmount saTakerCould = saTakerPays - saTakerPaid; // Taker could pay.
@@ -310,7 +311,7 @@ TER OfferCreateTransactor::takeOffers(
{
cLog(lsINFO) << "takeOffers: became unfunded: " << uOfferIndex.ToString();
terResult = mEngine->getNodes().offerDelete(uOfferIndex);
terResult = lesActive.offerDelete(uOfferIndex);
if (tesSUCCESS != terResult)
break;
}
@@ -356,6 +357,9 @@ TER OfferCreateTransactor::doApply()
LedgerEntrySet& lesActive = mEngine->getNodes();
LedgerEntrySet lesCheckpoint = lesActive; // Checkpoint with just fees paid.
lesActive.bumpSeq(); // Begin ledger variance.
SLE::pointer slePayment = mEngine->entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(mTxnAccountID));
if (uTxFlags & tfOfferCreateMask)
{
@@ -405,7 +409,7 @@ TER OfferCreateTransactor::doApply()
terResult = temBAD_ISSUER;
}
else if (!mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).isPositive())
else if (!lesActive.accountFunds(mTxnAccountID, saTakerGets).isPositive())
{
cLog(lsWARNING) << "OfferCreate: delay: Offers must be at least partially funded.";
@@ -446,7 +450,7 @@ TER OfferCreateTransactor::doApply()
bPassive,
uTakeBookBase,
mTxnAccountID,
mTxnAccount,
slePayment,
saTakerGets, // Reverse as we are the taker for taking.
saTakerPays,
saPaid, // How much would have spent at full price.
@@ -470,7 +474,7 @@ TER OfferCreateTransactor::doApply()
cLog(lsWARNING) << "OfferCreate: takeOffers: saTakerPays=" << saTakerPays.getFullText();
cLog(lsWARNING) << "OfferCreate: takeOffers: saTakerGets=" << saTakerGets.getFullText();
cLog(lsWARNING) << "OfferCreate: takeOffers: mTxnAccountID=" << RippleAddress::createHumanAccountID(mTxnAccountID);
cLog(lsWARNING) << "OfferCreate: takeOffers: FUNDS=" << mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).getFullText();
cLog(lsWARNING) << "OfferCreate: takeOffers: FUNDS=" << lesActive.accountFunds(mTxnAccountID, saTakerGets).getFullText();
// cLog(lsWARNING) << "OfferCreate: takeOffers: uPaysIssuerID=" << RippleAddress::createHumanAccountID(uPaysIssuerID);
// cLog(lsWARNING) << "OfferCreate: takeOffers: uGetsIssuerID=" << RippleAddress::createHumanAccountID(uGetsIssuerID);
@@ -493,8 +497,8 @@ TER OfferCreateTransactor::doApply()
else if (
!saTakerPays // Wants nothing more.
|| !saTakerGets // Offering nothing more.
|| bImmediateOrCancel // Do not persist.
|| !mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).isPositive() // Not funded.
|| bImmediateOrCancel // Do not persist.
|| !lesActive.accountFunds(mTxnAccountID, saTakerGets).isPositive() // Not funded.
|| bUnfunded) // Consider unfunded.
{
// Complete as is.
@@ -529,14 +533,14 @@ TER OfferCreateTransactor::doApply()
% saTakerGets.getFullText());
// Add offer to owner's directory.
terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
terResult = lesActive.dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
if (tesSUCCESS == terResult)
{
mEngine->getNodes().ownerCountAdjust(mTxnAccountID, 1, mTxnAccount); // Update owner count.
lesActive.ownerCountAdjust(mTxnAccountID, 1, slePayment); // Update owner count.
uint256 uBookBase = Ledger::getBookBase(uPaysCurrency, uPaysIssuerID, uGetsCurrency, uGetsIssuerID);
@@ -550,7 +554,7 @@ TER OfferCreateTransactor::doApply()
uDirectory = Ledger::getQualityIndex(uBookBase, uRate); // Use original rate.
// Add offer to order book.
terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex,
terResult = lesActive.dirAdd(uBookNode, uDirectory, uLedgerIndex,
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
}
@@ -595,7 +599,7 @@ TER OfferCreateTransactor::doApply()
cLog(lsINFO) << "takeOffers: found unfunded: " << uOfferIndex.ToString();
terResult = mEngine->getNodes().offerDelete(uOfferIndex);
terResult = lesActive.offerDelete(uOfferIndex);
if (tesSUCCESS != terResult)
break;
}