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; +}