mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 19:45:53 +00:00
Handle errors from ripple state creating.
This commit is contained in:
@@ -1194,7 +1194,7 @@ TER LedgerEntrySet::trustCreate(
|
||||
}
|
||||
|
||||
// Direct send w/o fees: redeeming IOUs and/or sending own IOUs.
|
||||
void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer)
|
||||
TER LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer)
|
||||
{
|
||||
uint160 uIssuerID = saAmount.getIssuer();
|
||||
uint160 uCurrencyID = saAmount.getCurrency();
|
||||
@@ -1205,6 +1205,8 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
|
||||
uint256 uIndex = Ledger::getRippleStateIndex(uSenderID, uReceiverID, saAmount.getCurrency());
|
||||
SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, uIndex);
|
||||
|
||||
TER terResult;
|
||||
|
||||
assert(!!uSenderID && uSenderID != ACCOUNT_ONE);
|
||||
assert(!!uReceiverID && uReceiverID != ACCOUNT_ONE);
|
||||
|
||||
@@ -1221,8 +1223,7 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
|
||||
% RippleAddress::createHumanAccountID(uReceiverID)
|
||||
% saAmount.getFullText());
|
||||
|
||||
// XXX Pass back result.
|
||||
TER terResult = trustCreate(
|
||||
terResult = trustCreate(
|
||||
bSenderHigh,
|
||||
uSenderID,
|
||||
entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uSenderID)),
|
||||
@@ -1252,25 +1253,31 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
|
||||
sleRippleState->setFieldAmount(sfBalance, saBalance);
|
||||
|
||||
entryModify(sleRippleState);
|
||||
|
||||
terResult = tesSUCCESS;
|
||||
}
|
||||
|
||||
return terResult;
|
||||
}
|
||||
|
||||
// Send regardless of limits.
|
||||
// --> saAmount: Amount/currency/issuer for receiver to get.
|
||||
// <-- saActual: Amount actually sent. Sender pay's fees.
|
||||
STAmount LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount)
|
||||
TER LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, STAmount& saActual)
|
||||
{
|
||||
STAmount saActual;
|
||||
const uint160 uIssuerID = saAmount.getIssuer();
|
||||
TER terResult;
|
||||
|
||||
assert(!!uSenderID && !!uReceiverID);
|
||||
|
||||
if (uSenderID == uIssuerID || uReceiverID == uIssuerID || uIssuerID == ACCOUNT_ONE)
|
||||
{
|
||||
// Direct send: redeeming IOUs and/or sending own IOUs.
|
||||
rippleCredit(uSenderID, uReceiverID, saAmount, false);
|
||||
terResult = rippleCredit(uSenderID, uReceiverID, saAmount, false);
|
||||
|
||||
saActual = saAmount;
|
||||
|
||||
terResult = tesSUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1282,16 +1289,19 @@ STAmount LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uRe
|
||||
|
||||
saActual.setIssuer(uIssuerID); // XXX Make sure this done in + above.
|
||||
|
||||
rippleCredit(uIssuerID, uReceiverID, saAmount);
|
||||
rippleCredit(uSenderID, uIssuerID, saActual);
|
||||
terResult = rippleCredit(uIssuerID, uReceiverID, saAmount);
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = rippleCredit(uSenderID, uIssuerID, saActual);
|
||||
}
|
||||
|
||||
return saActual;
|
||||
return terResult;
|
||||
}
|
||||
|
||||
void LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount)
|
||||
TER LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount)
|
||||
{
|
||||
assert(!saAmount.isNegative());
|
||||
TER terResult = tesSUCCESS;
|
||||
|
||||
if (!saAmount)
|
||||
{
|
||||
@@ -1334,8 +1344,12 @@ void LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uRecei
|
||||
}
|
||||
else
|
||||
{
|
||||
rippleSend(uSenderID, uReceiverID, saAmount);
|
||||
STAmount saActual;
|
||||
|
||||
terResult = rippleSend(uSenderID, uReceiverID, saAmount, saActual);
|
||||
}
|
||||
|
||||
return terResult;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -121,12 +121,12 @@ public:
|
||||
|
||||
STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false);
|
||||
STAmount rippleTransferFee(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount);
|
||||
void rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer=true);
|
||||
STAmount rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
|
||||
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);
|
||||
|
||||
STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false);
|
||||
STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail=false);
|
||||
void accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
|
||||
TER accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
|
||||
|
||||
TER trustCreate(
|
||||
const bool bSrcHigh,
|
||||
|
||||
@@ -200,23 +200,30 @@ TER OfferCreateTransactor::takeOffers(
|
||||
cLog(lsINFO) << "takeOffers: offer partial claim.";
|
||||
}
|
||||
|
||||
// Offer owner pays taker.
|
||||
// saSubTakerGot.setIssuer(uTakerGetsAccountID); // XXX Move this earlier?
|
||||
assert(!!saSubTakerGot.getIssuer());
|
||||
|
||||
mEngine->getNodes().accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot);
|
||||
mEngine->getNodes().accountSend(uOfferOwnerID, uTakerGetsAccountID, saOfferIssuerFee);
|
||||
|
||||
saTakerGot += saSubTakerGot;
|
||||
|
||||
// Taker pays offer owner.
|
||||
// saSubTakerPaid.setIssuer(uTakerPaysAccountID);
|
||||
assert(!!saSubTakerPaid.getIssuer());
|
||||
|
||||
mEngine->getNodes().accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid);
|
||||
mEngine->getNodes().accountSend(uTakerAccountID, uTakerPaysAccountID, saTakerIssuerFee);
|
||||
// Offer owner pays taker.
|
||||
// saSubTakerGot.setIssuer(uTakerGetsAccountID); // XXX Move this earlier?
|
||||
|
||||
terResult = mEngine->getNodes().accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot);
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = mEngine->getNodes().accountSend(uOfferOwnerID, uTakerGetsAccountID, saOfferIssuerFee);
|
||||
// Taker pays offer owner.
|
||||
// saSubTakerPaid.setIssuer(uTakerPaysAccountID);
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = mEngine->getNodes().accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid);
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = mEngine->getNodes().accountSend(uTakerAccountID, uTakerPaysAccountID, saTakerIssuerFee);
|
||||
|
||||
saTakerGot += saSubTakerGot;
|
||||
saTakerPaid += saSubTakerPaid;
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = temUNCERTAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,7 +1127,10 @@ TER RippleCalc::calcNodeDeliverRev(
|
||||
// Sending could be complicated: could fund a previous offer not yet visited.
|
||||
// However, these deductions and adjustments are tenative.
|
||||
// Must reset balances when going forward to perform actual transfers.
|
||||
lesActive.accountSend(uOfrOwnerID, uCurIssuerID, saOutPass);
|
||||
terResult = lesActive.accountSend(uOfrOwnerID, uCurIssuerID, saOutPass);
|
||||
|
||||
if (tesSUCCESS != terResult)
|
||||
break;
|
||||
|
||||
// Adjust offer
|
||||
sleOffer->setFieldAmount(sfTakerGets, saTakerGets - saOutPass);
|
||||
@@ -1147,7 +1150,7 @@ TER RippleCalc::calcNodeDeliverRev(
|
||||
saPrvDlvReq += saInPassAct;
|
||||
}
|
||||
|
||||
if (!saOutAct)
|
||||
if (tesSUCCESS == terResult && !saOutAct)
|
||||
terResult = tecPATH_DRY;
|
||||
|
||||
return terResult;
|
||||
@@ -1253,7 +1256,10 @@ TER RippleCalc::calcNodeDeliverFwd(
|
||||
% saOutPassAct.getFullText());
|
||||
|
||||
// Output: Debit offer owner, send XRP or non-XPR to next account.
|
||||
lesActive.accountSend(uOfrOwnerID, uNxtAccountID, saOutPassAct);
|
||||
terResult = lesActive.accountSend(uOfrOwnerID, uNxtAccountID, saOutPassAct);
|
||||
|
||||
if (tesSUCCESS != terResult)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1314,7 +1320,10 @@ TER RippleCalc::calcNodeDeliverFwd(
|
||||
|
||||
// Do inbound crediting.
|
||||
// Credit offer owner from in issuer/limbo (input transfer fees left with owner).
|
||||
lesActive.accountSend(!!uPrvCurrencyID ? uInAccountID : ACCOUNT_XRP, uOfrOwnerID, saInPassAct);
|
||||
terResult = lesActive.accountSend(!!uPrvCurrencyID ? uInAccountID : ACCOUNT_XRP, uOfrOwnerID, saInPassAct);
|
||||
|
||||
if (tesSUCCESS != terResult)
|
||||
break;
|
||||
|
||||
// Adjust offer
|
||||
// Fees are considered paid from a seperate budget and are not named in the offer.
|
||||
@@ -2017,7 +2026,7 @@ TER RippleCalc::calcNodeAccountFwd(
|
||||
saCurReceive = saPrvRedeemReq+saIssueCrd;
|
||||
|
||||
// Actually receive.
|
||||
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq+saPrvIssueReq, false);
|
||||
terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq+saPrvIssueReq, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2060,7 +2069,7 @@ TER RippleCalc::calcNodeAccountFwd(
|
||||
}
|
||||
|
||||
// Adjust prv --> cur balance : take all inbound
|
||||
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
|
||||
terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
|
||||
}
|
||||
}
|
||||
else if (bPrvAccount && !bNxtAccount)
|
||||
@@ -2096,7 +2105,7 @@ TER RippleCalc::calcNodeAccountFwd(
|
||||
}
|
||||
|
||||
// Adjust prv --> cur balance : take all inbound
|
||||
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
|
||||
terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2133,7 +2142,7 @@ TER RippleCalc::calcNodeAccountFwd(
|
||||
cLog(lsDEBUG) << boost::str(boost::format("calcNodeAccountFwd: ^ --> ACCOUNT -- XRP --> offer"));
|
||||
|
||||
// Deliver XRP to limbo.
|
||||
lesActive.accountSend(uCurAccountID, ACCOUNT_XRP, saCurDeliverAct);
|
||||
terResult = lesActive.accountSend(uCurAccountID, ACCOUNT_XRP, saCurDeliverAct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user