diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 28af36ec5..8dd45f147 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -226,10 +226,14 @@ std::string STAmount::createHumanCurrency(const uint160& uCurrency) { return SYSTEM_CURRENCY_CODE; } - else if (uCurrency == CURRENCY_ONE) + else if (CURRENCY_ONE == uCurrency) { return "1"; } + else if (CURRENCY_BAD == uCurrency) + { + return uCurrency.ToString(); + } else { Serializer s(160/8); @@ -243,21 +247,17 @@ std::string STAmount::createHumanCurrency(const uint160& uCurrency) std::vector vucVersion = sit.getRaw(16/8); std::vector vucReserved = sit.getRaw(24/8); - if (!::isZero(vucZeros.begin(), vucZeros.size())) + bool bIso = ::isZero(vucZeros.begin(), vucZeros.size()) // Leading zeros + && ::isZero(vucVersion.begin(), vucVersion.size()) // Zero version + && ::isZero(vucReserved.begin(), vucReserved.size()); // Reserved is zero. + + if (bIso) { - throw std::runtime_error(boost::str(boost::format("bad currency: zeros: %s") % uCurrency)); - } - else if (!::isZero(vucVersion.begin(), vucVersion.size())) - { - throw std::runtime_error(boost::str(boost::format("bad currency: version: %s") % uCurrency)); - } - else if (!::isZero(vucReserved.begin(), vucReserved.size())) - { - throw std::runtime_error(boost::str(boost::format("bad currency: reserved: %s") % uCurrency)); + sCurrency.assign(vucIso.begin(), vucIso.end()); } else { - sCurrency.assign(vucIso.begin(), vucIso.end()); + sCurrency = uCurrency.ToString(); } } diff --git a/src/cpp/ripple/SerializedTypes.h b/src/cpp/ripple/SerializedTypes.h index 3a2e619bc..57d4492ba 100644 --- a/src/cpp/ripple/SerializedTypes.h +++ b/src/cpp/ripple/SerializedTypes.h @@ -463,6 +463,10 @@ public: static STAmount getPay(const STAmount& offerOut, const STAmount& offerIn, const STAmount& needed); static std::string createHumanCurrency(const uint160& uCurrency); + static Json::Value createJsonCurrency(const uint160& uCurrency) + // XXX Punted. + { return createHumanCurrency(uCurrency); } + static STAmount deserialize(SerializerIterator&); static bool currencyFromString(uint160& uDstCurrency, const std::string& sCurrency); static bool issuerFromString(uint160& uDstIssuer, const std::string& sIssuer);