mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add issuerFromString() and bSetJson() to STAmount.
This commit is contained in:
@@ -16,6 +16,31 @@ SETUP_LOG();
|
|||||||
|
|
||||||
uint64 STAmount::uRateOne = STAmount::getRate(STAmount(1), STAmount(1));
|
uint64 STAmount::uRateOne = STAmount::getRate(STAmount(1), STAmount(1));
|
||||||
|
|
||||||
|
bool STAmount::issuerFromString(uint160& uDstIssuer, const std::string& sIssuer)
|
||||||
|
{
|
||||||
|
bool bSuccess = true;
|
||||||
|
|
||||||
|
if (sIssuer.size() == (160/4))
|
||||||
|
{
|
||||||
|
uDstIssuer.SetHex(sIssuer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RippleAddress raIssuer;
|
||||||
|
|
||||||
|
if (raIssuer.setAccountID(sIssuer))
|
||||||
|
{
|
||||||
|
uDstIssuer = raIssuer.getAccountID();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bSuccess = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
// --> sCurrency: "", "XRP", or three letter ISO code.
|
// --> sCurrency: "", "XRP", or three letter ISO code.
|
||||||
bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCurrency)
|
bool STAmount::currencyFromString(uint160& uDstCurrency, const std::string& sCurrency)
|
||||||
{
|
{
|
||||||
@@ -58,6 +83,21 @@ std::string STAmount::getHumanCurrency() const
|
|||||||
return createHumanCurrency(mCurrency);
|
return createHumanCurrency(mCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool STAmount::bSetJson(const Json::Value& jvSource)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
STAmount saParsed(sfGeneric, jvSource);
|
||||||
|
|
||||||
|
*this = saParsed;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
STAmount::STAmount(SField::ref n, const Json::Value& v)
|
STAmount::STAmount(SField::ref n, const Json::Value& v)
|
||||||
: SerializedType(n), mValue(0), mOffset(0), mIsNegative(false)
|
: SerializedType(n), mValue(0), mOffset(0), mIsNegative(false)
|
||||||
{
|
{
|
||||||
@@ -105,23 +145,10 @@ STAmount::STAmount(SField::ref n, const Json::Value& v)
|
|||||||
if (!currencyFromString(mCurrency, currency.asString()))
|
if (!currencyFromString(mCurrency, currency.asString()))
|
||||||
throw std::runtime_error("invalid currency");
|
throw std::runtime_error("invalid currency");
|
||||||
|
|
||||||
if (!issuer.isString())
|
if (!issuer.isString()
|
||||||
|
|| !issuerFromString(mIssuer, issuer.asString()))
|
||||||
throw std::runtime_error("invalid issuer");
|
throw std::runtime_error("invalid issuer");
|
||||||
|
|
||||||
if (issuer.size() == (160/4))
|
|
||||||
{
|
|
||||||
mIssuer.SetHex(issuer.asString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RippleAddress is;
|
|
||||||
|
|
||||||
if(!is.setAccountID(issuer.asString()))
|
|
||||||
throw std::runtime_error("invalid issuer");
|
|
||||||
|
|
||||||
mIssuer = is.getAccountID();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mIssuer.isZero())
|
if (mIssuer.isZero())
|
||||||
throw std::runtime_error("invalid issuer");
|
throw std::runtime_error("invalid issuer");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,6 +259,8 @@ public:
|
|||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
|
bool bSetJson(const Json::Value& jvSource);
|
||||||
|
|
||||||
static STAmount saFromRate(uint64 uRate = 0)
|
static STAmount saFromRate(uint64 uRate = 0)
|
||||||
{ return STAmount(CURRENCY_ONE, ACCOUNT_ONE, uRate, -9, false); }
|
{ return STAmount(CURRENCY_ONE, ACCOUNT_ONE, uRate, -9, false); }
|
||||||
|
|
||||||
@@ -379,6 +381,7 @@ public:
|
|||||||
static std::string createHumanCurrency(const uint160& uCurrency);
|
static std::string createHumanCurrency(const uint160& uCurrency);
|
||||||
static STAmount deserialize(SerializerIterator&);
|
static STAmount deserialize(SerializerIterator&);
|
||||||
static bool currencyFromString(uint160& uDstCurrency, const std::string& sCurrency);
|
static bool currencyFromString(uint160& uDstCurrency, const std::string& sCurrency);
|
||||||
|
static bool issuerFromString(uint160& uDstIssuer, const std::string& sIssuer);
|
||||||
|
|
||||||
Json::Value getJson(int) const;
|
Json::Value getJson(int) const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user