From ce30701744066ef1cfc4f6787bd2e416e279cd24 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 10 Apr 2012 16:04:28 -0700 Subject: [PATCH] Code to compute how much you need to pay to get a particular output from an offer. --- src/Amount.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Amount.cpp b/src/Amount.cpp index 90ec1fc731..9902a1b9eb 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -234,6 +234,8 @@ STAmount operator*(const STAmount &v1, const STAmount &v2) STAmount getRate(const STAmount& offerOut, const STAmount& offerIn) { + // offerOut = how much comes out of the offer, from the offeror to the taker + // offerIn = how much goes into the offer, from the taker to the offeror return offerOut / offerIn; } @@ -271,3 +273,11 @@ STAmount getClaimed(STAmount& offerOut, STAmount& offerIn, STAmount& paid) } return ret; } + +STAmount getNeeded(const STAmount& offerOut, const STAmount& offerIn, const STAmount& needed) +{ // Someone wants to get (needed) out of the offer, how much should they pay in? + if(offerOut.isZero()) return STAmount(); + if(needed >= offerOut) return needed; + STAmount ret = needed * (offerIn / offerOut); + return (ret > offerIn) ? offerIn : ret; +}