Fix bugs in pathfinding with XRP as the source currency

This commit is contained in:
David Schwartz
2014-11-11 15:20:16 -08:00
parent d1618d79b0
commit b141598f9b
3 changed files with 12 additions and 4 deletions

View File

@@ -515,7 +515,9 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
if (rc.result () == tesSUCCESS)
{
Json::Value jvEntry (Json::objectValue);
rc.actualAmountIn.setIssuer (sourceAccount);
if (!isXRP (currIssuer.currency))
rc.actualAmountIn.setIssuer (sourceAccount);
jvEntry["source_amount"] = rc.actualAmountIn.getJson (0);
jvEntry["paths_computed"] = spsPaths.getJson (0);

View File

@@ -172,7 +172,8 @@ Pathfinder::Pathfinder (
mDstAmount (saDstAmount),
mSrcCurrency (uSrcCurrency),
mSrcIssuer (uSrcIssuer),
mSrcAmount ({uSrcCurrency, uSrcIssuer}, 1u, 0, true),
mSrcAmount ({uSrcCurrency,
isXRP (uSrcCurrency) ? xrpAccount() : uSrcIssuer }, 1u, 0, true),
mLedger (cache->getLedger ()),
mRLCache (cache)
{
@@ -188,7 +189,8 @@ Pathfinder::Pathfinder (
mDstAccount (uDstAccount),
mDstAmount (saDstAmount),
mSrcCurrency (uSrcCurrency),
mSrcAmount ({uSrcCurrency, uSrcAccount}, 1u, 0, true),
mSrcAmount ({uSrcCurrency,
isXRP (uSrcCurrency) ? xrpAccount() : uSrcAccount }, 1u, 0, true),
mLedger (cache->getLedger ()),
mRLCache (cache)
{

View File

@@ -228,8 +228,9 @@ Json::Value doRipplePathFind (RPC::Context& context)
}
STPath fullLiquidityPath;
bool sourceIsXrp = isXRP (uSrcCurrencyID);
auto valid = fp.findPathsForIssue (
{uSrcCurrencyID, uSrcIssuerID},
{uSrcCurrencyID, sourceIsXrp ? xrpAccount() : uSrcIssuerID},
spsComputed,
fullLiquidityPath);
if (!valid)
@@ -298,6 +299,9 @@ Json::Value doRipplePathFind (RPC::Context& context)
// anyway to produce the canonical. (At least unless we
// make a direct canonical.)
if (!sourceIsXrp)
rc.actualAmountIn.setIssuer (issuer);
jvEntry["source_amount"] = rc.actualAmountIn.getJson (0);
jvEntry["paths_canonical"] = Json::arrayValue;
jvEntry["paths_computed"] = spsComputed.getJson (0);