mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin into continuousClose
This commit is contained in:
@@ -44,7 +44,8 @@ bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCur
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
std::string STAmount::getCurrencyHuman()
|
||||
// XXX Broken for custom currencies?
|
||||
std::string STAmount::getCurrencyHuman() const
|
||||
{
|
||||
std::string sCurrency;
|
||||
|
||||
@@ -88,19 +89,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<uint64>(sAmount);
|
||||
try
|
||||
{
|
||||
uValue = sAmount.empty() ? 0 : boost::lexical_cast<uint64>(sAmount);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
iOffset = 0;
|
||||
}
|
||||
else
|
||||
@@ -125,7 +139,6 @@ bool STAmount::setValue(const std::string& sAmount, const std::string& sCurrency
|
||||
uValue += uFraction;
|
||||
}
|
||||
|
||||
mIsNative = !mCurrency;
|
||||
if (mIsNative)
|
||||
{
|
||||
if (bInteger)
|
||||
@@ -811,6 +824,20 @@ STAmount STAmount::deserialize(SerializerIterator& it)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value STAmount::getJson(int) const
|
||||
{
|
||||
Json::Value elem(Json::objectValue);
|
||||
|
||||
elem["value"] = getText();
|
||||
|
||||
// This is a hack, many places don't specify a currency. STAmount is used just as a value.
|
||||
if (!mIsNative)
|
||||
elem["currency"] = getCurrencyHuman();
|
||||
|
||||
return elem;
|
||||
}
|
||||
|
||||
// For unit tests:
|
||||
static STAmount serdes(const STAmount &s)
|
||||
{
|
||||
Serializer ser;
|
||||
@@ -822,7 +849,6 @@ static STAmount serdes(const STAmount &s)
|
||||
return STAmount::deserialize(sit);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(amount)
|
||||
|
||||
BOOST_AUTO_TEST_CASE( setValue_test )
|
||||
|
||||
@@ -1124,10 +1124,12 @@ 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);
|
||||
jPeer["limit_peer"] = saLimitPeer.getJson(0);
|
||||
jPeer["limit"] = saLimit.getText();
|
||||
jPeer["limit_peer"] = saLimitPeer.getText();
|
||||
|
||||
jsonLines.append(jPeer);
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ public:
|
||||
int64 getSNValue() const;
|
||||
void setSNValue(int64);
|
||||
|
||||
std::string getCurrencyHuman();
|
||||
std::string getCurrencyHuman() const;
|
||||
|
||||
bool isNative() const { return mIsNative; }
|
||||
bool isZero() const { return mValue == 0; }
|
||||
@@ -342,6 +342,8 @@ public:
|
||||
|
||||
static STAmount deserialize(SerializerIterator&);
|
||||
static bool currencyFromString(uint160& uDstCurrency, const std::string& sCurrency);
|
||||
|
||||
Json::Value getJson(int) const;
|
||||
};
|
||||
|
||||
class STHash128 : public SerializedType
|
||||
|
||||
Reference in New Issue
Block a user