Default owner count to 0 if not available.

This commit is contained in:
Arthur Britto
2012-12-18 14:40:11 -08:00
parent 05b77f7468
commit 8b19a356f5
4 changed files with 19 additions and 51 deletions

View File

@@ -845,7 +845,7 @@ bool LedgerEntrySet::dirNext(
} }
// If there is a count, adjust the owner count by iAmount. Otherwise, compute the owner count and store it. // If there is a count, adjust the owner count by iAmount. Otherwise, compute the owner count and store it.
TER LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot) void LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot)
{ {
SLE::pointer sleHold = sleAccountRoot SLE::pointer sleHold = sleAccountRoot
? SLE::pointer() ? SLE::pointer()
@@ -855,31 +855,10 @@ TER LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::
? sleAccountRoot ? sleAccountRoot
: sleHold; : sleHold;
const bool bHaveOwnerCount = sleRoot->isFieldPresent(sfOwnerCount);
TER terResult;
if (bHaveOwnerCount)
{
const uint32 uOwnerCount = sleRoot->getFieldU32(sfOwnerCount); const uint32 uOwnerCount = sleRoot->getFieldU32(sfOwnerCount);
if (iAmount + int(uOwnerCount) >= 0) if (iAmount + int(uOwnerCount) >= 0)
sleRoot->setFieldU32(sfOwnerCount, uOwnerCount+iAmount); sleRoot->setFieldU32(sfOwnerCount, uOwnerCount+iAmount);
terResult = tesSUCCESS;
}
else
{
uint32 uActualCount;
terResult = dirCount(Ledger::getOwnerDirIndex(uOwnerID), uActualCount);
if (tesSUCCESS == terResult)
{
sleRoot->setFieldU32(sfOwnerCount, uActualCount);
}
}
return terResult;
} }
TER LedgerEntrySet::offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID) TER LedgerEntrySet::offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID)
@@ -889,11 +868,8 @@ TER LedgerEntrySet::offerDelete(const SLE::pointer& sleOffer, const uint256& uOf
if (tesSUCCESS == terResult) if (tesSUCCESS == terResult)
{ {
terResult = ownerCountAdjust(uOwnerID, -1); ownerCountAdjust(uOwnerID, -1);
}
if (tesSUCCESS == terResult)
{
uint256 uDirectory = sleOffer->getFieldH256(sfBookDirectory); uint256 uDirectory = sleOffer->getFieldH256(sfBookDirectory);
uint64 uBookNode = sleOffer->getFieldU64(sfBookNode); uint64 uBookNode = sleOffer->getFieldU64(sfBookNode);

View File

@@ -103,7 +103,7 @@ public:
bool dirNext(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex); bool dirNext(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex);
TER dirCount(const uint256& uDirIndex, uint32& uCount); TER dirCount(const uint256& uDirIndex, uint32& uCount);
TER ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot=SLE::pointer()); void ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot=SLE::pointer());
// Offer functions. // Offer functions.
TER offerDelete(const uint256& uOfferIndex); TER offerDelete(const uint256& uOfferIndex);

View File

@@ -397,14 +397,11 @@ TER OfferCreateTransactor::doApply()
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID, boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
saTakerGets.getCurrency(), uGetsIssuerID, uRate)); saTakerGets.getCurrency(), uGetsIssuerID, uRate));
// Update owner count.
if (tesSUCCESS == terResult)
{
terResult = mEngine->getNodes().ownerCountAdjust(mTxnAccountID, 1, mTxnAccount);
}
if (tesSUCCESS == terResult) if (tesSUCCESS == terResult)
{ {
mEngine->getNodes().ownerCountAdjust(mTxnAccountID, 1, mTxnAccount); // Update owner count.
uint256 uBookBase = Ledger::getBookBase(uPaysCurrency, uPaysIssuerID, uGetsCurrency, uGetsIssuerID); uint256 uBookBase = Ledger::getBookBase(uPaysCurrency, uPaysIssuerID, uGetsCurrency, uGetsIssuerID);
Log(lsINFO) << boost::str(boost::format("doOfferCreate: adding to book: %s : %s/%s -> %s/%s") Log(lsINFO) << boost::str(boost::format("doOfferCreate: adding to book: %s : %s/%s -> %s/%s")

View File

@@ -180,50 +180,44 @@ TER TrustSetTransactor::doApply()
{ {
// Set reserve for low account. // Set reserve for low account.
terResult = mEngine->getNodes().ownerCountAdjust(uLowAccountID, 1, sleLowAccount); mEngine->getNodes().ownerCountAdjust(uLowAccountID, 1, sleLowAccount);
uFlagsOut |= lsfLowReserve; uFlagsOut |= lsfLowReserve;
if (!bHigh) if (!bHigh)
bReserveIncrease = true; bReserveIncrease = true;
} }
if (tesSUCCESS == terResult && bLowReserveClear && bLowReserved) if (bLowReserveClear && bLowReserved)
{ {
// Clear reserve for low account. // Clear reserve for low account.
terResult = mEngine->getNodes().ownerCountAdjust(uLowAccountID, -1, sleLowAccount); mEngine->getNodes().ownerCountAdjust(uLowAccountID, -1, sleLowAccount);
uFlagsOut &= ~lsfLowReserve; uFlagsOut &= ~lsfLowReserve;
} }
if (tesSUCCESS == terResult && bHighReserveSet && !bHighReserved) if (bHighReserveSet && !bHighReserved)
{ {
// Set reserve for high account. // Set reserve for high account.
terResult = mEngine->getNodes().ownerCountAdjust(uHighAccountID, 1, sleHighAccount); mEngine->getNodes().ownerCountAdjust(uHighAccountID, 1, sleHighAccount);
uFlagsOut |= lsfHighReserve; uFlagsOut |= lsfHighReserve;
if (bHigh) if (bHigh)
bReserveIncrease = true; bReserveIncrease = true;
} }
if (tesSUCCESS == terResult && bHighReserveClear && bHighReserved) if (bHighReserveClear && bHighReserved)
{ {
// Clear reserve for high account. // Clear reserve for high account.
terResult = mEngine->getNodes().ownerCountAdjust(uHighAccountID, -1, sleHighAccount); mEngine->getNodes().ownerCountAdjust(uHighAccountID, -1, sleHighAccount);
uFlagsOut &= ~lsfHighReserve; uFlagsOut &= ~lsfHighReserve;
} }
if (uFlagsIn != uFlagsOut) if (uFlagsIn != uFlagsOut)
sleRippleState->setFieldU32(sfFlags, uFlagsOut); sleRippleState->setFieldU32(sfFlags, uFlagsOut);
if (tesSUCCESS != terResult) if (bDefault)
{
Log(lsINFO) << "doTrustSet: Error";
nothing();
}
else if (bDefault)
{ {
// Can delete. // Can delete.
@@ -299,15 +293,16 @@ TER TrustSetTransactor::doApply()
boost::bind(&Ledger::ownerDirDescriber, _1, mTxnAccountID)); boost::bind(&Ledger::ownerDirDescriber, _1, mTxnAccountID));
if (tesSUCCESS == terResult) if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().ownerCountAdjust(mTxnAccountID, 1, mTxnAccount); {
mEngine->getNodes().ownerCountAdjust(mTxnAccountID, 1, mTxnAccount);
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().dirAdd( terResult = mEngine->getNodes().dirAdd(
uSrcRef, uSrcRef,
Ledger::getOwnerDirIndex(uDstAccountID), Ledger::getOwnerDirIndex(uDstAccountID),
sleRippleState->getIndex(), sleRippleState->getIndex(),
boost::bind(&Ledger::ownerDirDescriber, _1, uDstAccountID)); boost::bind(&Ledger::ownerDirDescriber, _1, uDstAccountID));
} }
}
Log(lsINFO) << "doTrustSet<"; Log(lsINFO) << "doTrustSet<";