From b141598f9b35e0d40e5e5595a785e4174ce762c9 Mon Sep 17 00:00:00 2001 From: David Schwartz Date: Tue, 11 Nov 2014 15:20:16 -0800 Subject: [PATCH] Fix bugs in pathfinding with XRP as the source currency --- src/ripple/app/paths/PathRequest.cpp | 4 +++- src/ripple/app/paths/Pathfinder.cpp | 6 ++++-- src/ripple/rpc/handlers/RipplePathFind.cpp | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index 479bfd38f..6271b6e5a 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -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); diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index 3093b8a6c..3cdd0aa13 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -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) { diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 01d50c032..04dd9778e 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -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);