Clean up aborted offers support going into debt.

This commit is contained in:
Arthur Britto
2012-12-25 16:50:10 -08:00
parent f3b216b39f
commit 14380311a1
3 changed files with 20 additions and 39 deletions

View File

@@ -1006,7 +1006,7 @@ uint32 LedgerEntrySet::rippleQualityIn(const uint160& uToAccountID, const uint16
// Return how much of uIssuerID's uCurrencyID IOUs that uAccountID holds. May be negative. // Return how much of uIssuerID's uCurrencyID IOUs that uAccountID holds. May be negative.
// <-- IOU's uAccountID has of uIssuerID. // <-- IOU's uAccountID has of uIssuerID.
STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail) STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
{ {
STAmount saBalance; STAmount saBalance;
SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, Ledger::getRippleStateIndex(uAccountID, uIssuerID, uCurrencyID)); SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, Ledger::getRippleStateIndex(uAccountID, uIssuerID, uCurrencyID));
@@ -1017,30 +1017,14 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
} }
else if (uAccountID > uIssuerID) else if (uAccountID > uIssuerID)
{ {
if (false && bAvail) saBalance = sleRippleState->getFieldAmount(sfBalance);
{ saBalance.negate(); // Put balance in uAccountID terms.
saBalance = sleRippleState->getFieldAmount(sfLowLimit);
saBalance -= sleRippleState->getFieldAmount(sfBalance);
}
else
{
saBalance = sleRippleState->getFieldAmount(sfBalance);
saBalance.negate(); // Put balance in uAccountID terms.
}
saBalance.setIssuer(uIssuerID); saBalance.setIssuer(uIssuerID);
} }
else else
{ {
if (false && bAvail) saBalance = sleRippleState->getFieldAmount(sfBalance);
{
saBalance = sleRippleState->getFieldAmount(sfHighLimit);
saBalance += sleRippleState->getFieldAmount(sfBalance);
}
else
{
saBalance = sleRippleState->getFieldAmount(sfBalance);
}
saBalance.setIssuer(uIssuerID); saBalance.setIssuer(uIssuerID);
} }
@@ -1049,7 +1033,7 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
} }
// <-- saAmount: amount of uCurrencyID held by uAccountID. May be negative. // <-- saAmount: amount of uCurrencyID held by uAccountID. May be negative.
STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail) STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID)
{ {
STAmount saAmount; STAmount saAmount;
@@ -1071,13 +1055,12 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
} }
else else
{ {
saAmount = rippleHolds(uAccountID, uCurrencyID, uIssuerID, bAvail); saAmount = rippleHolds(uAccountID, uCurrencyID, uIssuerID);
} }
cLog(lsINFO) << boost::str(boost::format("accountHolds: uAccountID=%s saAmount=%s bAvail=%d") cLog(lsINFO) << boost::str(boost::format("accountHolds: uAccountID=%s saAmount=%s")
% RippleAddress::createHumanAccountID(uAccountID) % RippleAddress::createHumanAccountID(uAccountID)
% saAmount.getFullText() % saAmount.getFullText());
% bAvail);
return saAmount; return saAmount;
} }
@@ -1086,10 +1069,9 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
// Use when you need a default for rippling uAccountID's currency. // Use when you need a default for rippling uAccountID's currency.
// XXX Should take into account quality? // XXX Should take into account quality?
// --> saDefault/currency/issuer // --> saDefault/currency/issuer
// --> bAvail: true to include going into debt.
// <-- saFunds: Funds available. May be negative. // <-- saFunds: Funds available. May be negative.
// If the issuer is the same as uAccountID, funds are unlimited, use result is saDefault. // If the issuer is the same as uAccountID, funds are unlimited, use result is saDefault.
STAmount LedgerEntrySet::accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail) STAmount LedgerEntrySet::accountFunds(const uint160& uAccountID, const STAmount& saDefault)
{ {
STAmount saFunds; STAmount saFunds;
@@ -1103,13 +1085,12 @@ STAmount LedgerEntrySet::accountFunds(const uint160& uAccountID, const STAmount&
} }
else else
{ {
saFunds = accountHolds(uAccountID, saDefault.getCurrency(), saDefault.getIssuer(), bAvail); saFunds = accountHolds(uAccountID, saDefault.getCurrency(), saDefault.getIssuer());
cLog(lsINFO) << boost::str(boost::format("accountFunds: uAccountID=%s saDefault=%s saFunds=%s bAvail=%d") cLog(lsINFO) << boost::str(boost::format("accountFunds: uAccountID=%s saDefault=%s saFunds=%s")
% RippleAddress::createHumanAccountID(uAccountID) % RippleAddress::createHumanAccountID(uAccountID)
% saDefault.getFullText() % saDefault.getFullText()
% saFunds.getFullText() % saFunds.getFullText());
% bAvail);
} }
return saFunds; return saFunds;

View File

@@ -119,13 +119,13 @@ public:
uint32 rippleQualityOut(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID) uint32 rippleQualityOut(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID)
{ return rippleQualityIn(uToAccountID, uFromAccountID, uCurrencyID, sfLowQualityOut, sfHighQualityOut); } { return rippleQualityIn(uToAccountID, uFromAccountID, uCurrencyID, sfLowQualityOut, sfHighQualityOut); }
STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false); STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID);
STAmount rippleTransferFee(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount); STAmount rippleTransferFee(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount);
TER rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer=true); TER rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer=true);
TER rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, STAmount& saActual); TER rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, STAmount& saActual);
STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false); STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID);
STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail=false); STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault);
TER accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount); TER accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
TER trustCreate( TER trustCreate(

View File

@@ -117,8 +117,8 @@ TER OfferCreateTransactor::takeOffers(
cLog(lsINFO) << "takeOffers: saOfferPays=" << saOfferPays.getFullText(); cLog(lsINFO) << "takeOffers: saOfferPays=" << saOfferPays.getFullText();
STAmount saOfferFunds = mEngine->getNodes().accountFunds(uOfferOwnerID, saOfferPays, true); STAmount saOfferFunds = mEngine->getNodes().accountFunds(uOfferOwnerID, saOfferPays);
STAmount saTakerFunds = mEngine->getNodes().accountFunds(uTakerAccountID, saTakerPays, true); STAmount saTakerFunds = mEngine->getNodes().accountFunds(uTakerAccountID, saTakerPays);
SLE::pointer sleOfferAccount; // Owner of offer. SLE::pointer sleOfferAccount; // Owner of offer.
if (!saOfferFunds.isPositive()) if (!saOfferFunds.isPositive())
@@ -327,7 +327,7 @@ TER OfferCreateTransactor::doApply()
terResult = temBAD_ISSUER; terResult = temBAD_ISSUER;
} }
else if (!mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets, true).isPositive()) else if (!mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).isPositive())
{ {
cLog(lsWARNING) << "doOfferCreate: delay: Offers must be at least partially funded."; cLog(lsWARNING) << "doOfferCreate: delay: Offers must be at least partially funded.";
@@ -387,7 +387,7 @@ TER OfferCreateTransactor::doApply()
cLog(lsWARNING) << "doOfferCreate: takeOffers: saTakerPays=" << saTakerPays.getFullText(); cLog(lsWARNING) << "doOfferCreate: takeOffers: saTakerPays=" << saTakerPays.getFullText();
cLog(lsWARNING) << "doOfferCreate: takeOffers: saTakerGets=" << saTakerGets.getFullText(); cLog(lsWARNING) << "doOfferCreate: takeOffers: saTakerGets=" << saTakerGets.getFullText();
cLog(lsWARNING) << "doOfferCreate: takeOffers: mTxnAccountID=" << RippleAddress::createHumanAccountID(mTxnAccountID); cLog(lsWARNING) << "doOfferCreate: takeOffers: mTxnAccountID=" << RippleAddress::createHumanAccountID(mTxnAccountID);
cLog(lsWARNING) << "doOfferCreate: takeOffers: FUNDS=" << mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets, true).getFullText(); cLog(lsWARNING) << "doOfferCreate: takeOffers: FUNDS=" << mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).getFullText();
// cLog(lsWARNING) << "doOfferCreate: takeOffers: uPaysIssuerID=" << RippleAddress::createHumanAccountID(uPaysIssuerID); // cLog(lsWARNING) << "doOfferCreate: takeOffers: uPaysIssuerID=" << RippleAddress::createHumanAccountID(uPaysIssuerID);
// cLog(lsWARNING) << "doOfferCreate: takeOffers: uGetsIssuerID=" << RippleAddress::createHumanAccountID(uGetsIssuerID); // cLog(lsWARNING) << "doOfferCreate: takeOffers: uGetsIssuerID=" << RippleAddress::createHumanAccountID(uGetsIssuerID);
@@ -395,7 +395,7 @@ TER OfferCreateTransactor::doApply()
if (tesSUCCESS != terResult if (tesSUCCESS != terResult
|| !saTakerPays // Wants nothing more. || !saTakerPays // Wants nothing more.
|| !saTakerGets // Offering nothing more. || !saTakerGets // Offering nothing more.
|| !mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets, true).isPositive()) // Not funded. || !mEngine->getNodes().accountFunds(mTxnAccountID, saTakerGets).isPositive()) // Not funded.
{ {
// Complete as is. // Complete as is.
nothing(); nothing();