diff --git a/src/Amount.cpp b/src/Amount.cpp index dcce9a8bd8..32a556a0e1 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -88,19 +88,32 @@ std::string STAmount::getCurrencyHuman() } // Not meant to be the ultimate parser. For use by RPC which is supposed to be sane and trusted. +// Native has special handling: +// - Integer values are in base units. +// - Float values are in float units. +// - To avoid a mistake float value for native are specified with a "^" in place of a "." bool STAmount::setValue(const std::string& sAmount, const std::string& sCurrency) { if (!currencyFromString(mCurrency, sCurrency)) return false; + mIsNative = !mCurrency; + uint64 uValue; int iOffset; - size_t uDecimal = sAmount.find_first_of("^"); + size_t uDecimal = sAmount.find_first_of(mIsNative ? "^" : "."); bool bInteger = uDecimal == std::string::npos; if (bInteger) { - uValue = sAmount.empty() ? 0 : boost::lexical_cast(sAmount); + try + { + uValue = sAmount.empty() ? 0 : boost::lexical_cast(sAmount); + } + catch (...) + { + return false; + } iOffset = 0; } else @@ -125,7 +138,6 @@ bool STAmount::setValue(const std::string& sAmount, const std::string& sCurrency uValue += uFraction; } - mIsNative = !mCurrency; if (mIsNative) { if (bInteger) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index bb6afb04ee..afcd9e3c39 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1124,6 +1124,8 @@ Json::Value RPCServer::doRippleLinesGet(const Json::Value ¶ms) jPeer["node"] = uNode.ToString(); jPeer["account"] = rsLine->getAccountIDPeer().humanAccountID(); + // Amount reported is positive if current account hold's other account's IOUs. + // Amount reported is negative if other account hold's current account's IOUs. jPeer["balance"] = saBalance.getText(); jPeer["currency"] = saBalance.getCurrencyHuman(); jPeer["limit"] = saLimit.getJson(0);