diff --git a/src/Amount.cpp b/src/Amount.cpp index 32a556a0e1..ac987ce567 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -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; @@ -823,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; @@ -834,7 +849,6 @@ static STAmount serdes(const STAmount &s) return STAmount::deserialize(sit); } - BOOST_AUTO_TEST_SUITE(amount) BOOST_AUTO_TEST_CASE( setValue_test ) diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 9b97202850..3d8bd3f7f5 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -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