From 4ddadb8792cf15f576e14fbfe2ba85fa17982dbd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 28 Oct 2013 16:48:47 -0700 Subject: [PATCH] Correctly compute amount left on sell offer when a crossing offer pays us more than we asked for. --- src/ripple_app/tx/OfferCreateTransactor.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ripple_app/tx/OfferCreateTransactor.cpp b/src/ripple_app/tx/OfferCreateTransactor.cpp index 327f8822e..b059ac568 100644 --- a/src/ripple_app/tx/OfferCreateTransactor.cpp +++ b/src/ripple_app/tx/OfferCreateTransactor.cpp @@ -334,7 +334,15 @@ TER OfferCreateTransactor::takeOffers ( if (tesSUCCESS == terResult) terResult = lesActive.accountSend (uTakerAccountID, uOfferOwnerID, saSubTakerPaid); // Taker pays offer owner. - if (!bSell) + if (bSell) + { + // Sell semantics: + // Reduce amount considered received to original offer's rate. + // Not by crossing rate, which is higher. + STAmount saEffectiveGot = STAmount::divide(saSubTakerPaid, saTakerRate, saTakerGets); + saSubTakerGot = std::min(saEffectiveGot, saSubTakerGot); + } + else { // Buy semantics: Reduce amount considered paid by taker's rate. Not by actual cost which is lower. // That is, take less as to just satify our buy requirement.