mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
beast cleanup and tidying:
* Replace custom types with C++11 <cstdint> types * Fix sqlite integer intos and uses * Fix String implicit integer constructors * Escape the enclosing namespace in sqdb * Replace contract checks with assert * Make many header files compile independently * Remove the dependence on beast_core.h in many places * Remove unused or obsolete classes and functions * Remove unused or obsolete macros * Remove unused network functions and files * Remove unused or obsolete classes: - ChildProcess - HighResolutionTimer - InterProcessLock - Throw - TrackedMutex - UntrackedMutex - XmlDocument - XmlElement
This commit is contained in:
@@ -21,7 +21,7 @@ namespace ripple {
|
||||
|
||||
SETUP_LOG (STAmount)
|
||||
|
||||
beast::uint64 STAmount::uRateOne = STAmount::getRate (STAmount (1), STAmount (1));
|
||||
std::uint64_t STAmount::uRateOne = STAmount::getRate (STAmount (1), STAmount (1));
|
||||
|
||||
bool STAmount::issuerFromString (uint160& uDstIssuer, const std::string& sIssuer)
|
||||
{
|
||||
@@ -199,7 +199,7 @@ STAmount::STAmount (SField::ref n, const Json::Value& v)
|
||||
{
|
||||
if (mIsNative)
|
||||
{
|
||||
beast::int64 val = beast::lexicalCastThrow <beast::int64> (value.asString ());
|
||||
std::int64_t val = beast::lexicalCastThrow <std::int64_t> (value.asString ());
|
||||
|
||||
if (val >= 0)
|
||||
mValue = val;
|
||||
@@ -297,13 +297,13 @@ bool STAmount::setValue (const std::string& sAmount)
|
||||
|
||||
if (!smMatch[4].matched) // integer only
|
||||
{
|
||||
mValue = beast::lexicalCast <beast::uint64> (std::string (smMatch[2]));
|
||||
mValue = beast::lexicalCast <std::uint64_t> (std::string (smMatch[2]));
|
||||
mOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// integer and fraction
|
||||
mValue = beast::lexicalCast <beast::uint64> (smMatch[2] + smMatch[4]);
|
||||
mValue = beast::lexicalCast <std::uint64_t> (smMatch[2] + smMatch[4]);
|
||||
mOffset = - (smMatch[4].length ());
|
||||
}
|
||||
|
||||
@@ -485,20 +485,20 @@ void STAmount::add (Serializer& s) const
|
||||
if (isZero ())
|
||||
s.add64 (cNotNative);
|
||||
else if (mIsNegative) // 512 = not native
|
||||
s.add64 (mValue | (static_cast<beast::uint64> (mOffset + 512 + 97) << (64 - 10)));
|
||||
s.add64 (mValue | (static_cast<std::uint64_t> (mOffset + 512 + 97) << (64 - 10)));
|
||||
else // 256 = positive
|
||||
s.add64 (mValue | (static_cast<beast::uint64> (mOffset + 512 + 256 + 97) << (64 - 10)));
|
||||
s.add64 (mValue | (static_cast<std::uint64_t> (mOffset + 512 + 256 + 97) << (64 - 10)));
|
||||
|
||||
s.add160 (mCurrency);
|
||||
s.add160 (mIssuer);
|
||||
}
|
||||
}
|
||||
|
||||
STAmount STAmount::createFromInt64 (SField::ref name, beast::int64 value)
|
||||
STAmount STAmount::createFromInt64 (SField::ref name, std::int64_t value)
|
||||
{
|
||||
return value >= 0
|
||||
? STAmount (name, static_cast<beast::uint64> (value), false)
|
||||
: STAmount (name, static_cast<beast::uint64> (-value), true);
|
||||
? STAmount (name, static_cast<std::uint64_t> (value), false)
|
||||
: STAmount (name, static_cast<std::uint64_t> (-value), true);
|
||||
}
|
||||
|
||||
void STAmount::setValue (const STAmount& a)
|
||||
@@ -538,7 +538,7 @@ int STAmount::compare (const STAmount& a) const
|
||||
|
||||
STAmount* STAmount::construct (SerializerIterator& sit, SField::ref name)
|
||||
{
|
||||
beast::uint64 value = sit.get64 ();
|
||||
std::uint64_t value = sit.get64 ();
|
||||
|
||||
if ((value & cNotNative) == 0)
|
||||
{
|
||||
@@ -578,29 +578,29 @@ STAmount* STAmount::construct (SerializerIterator& sit, SField::ref name)
|
||||
return new STAmount (name, uCurrencyID, uIssuerID);
|
||||
}
|
||||
|
||||
beast::int64 STAmount::getSNValue () const
|
||||
std::int64_t STAmount::getSNValue () const
|
||||
{
|
||||
// signed native value
|
||||
if (!mIsNative) throw std::runtime_error ("not native");
|
||||
|
||||
if (mIsNegative) return - static_cast<beast::int64> (mValue);
|
||||
if (mIsNegative) return - static_cast<std::int64_t> (mValue);
|
||||
|
||||
return static_cast<beast::int64> (mValue);
|
||||
return static_cast<std::int64_t> (mValue);
|
||||
}
|
||||
|
||||
void STAmount::setSNValue (beast::int64 v)
|
||||
void STAmount::setSNValue (std::int64_t v)
|
||||
{
|
||||
if (!mIsNative) throw std::runtime_error ("not native");
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
mIsNegative = false;
|
||||
mValue = static_cast<beast::uint64> (v);
|
||||
mValue = static_cast<std::uint64_t> (v);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIsNegative = true;
|
||||
mValue = static_cast<beast::uint64> (-v);
|
||||
mValue = static_cast<std::uint64_t> (-v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,7 +746,7 @@ STAmount STAmount::operator- (void) const
|
||||
return STAmount (getFName (), mCurrency, mIssuer, mValue, mOffset, mIsNative, !mIsNegative);
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator= (beast::uint64 v)
|
||||
STAmount& STAmount::operator= (std::uint64_t v)
|
||||
{
|
||||
// does not copy name, does not change currency type
|
||||
mOffset = 0;
|
||||
@@ -758,52 +758,52 @@ STAmount& STAmount::operator= (beast::uint64 v)
|
||||
return *this;
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator+= (beast::uint64 v)
|
||||
STAmount& STAmount::operator+= (std::uint64_t v)
|
||||
{
|
||||
if (mIsNative)
|
||||
setSNValue (getSNValue () + static_cast<beast::int64> (v));
|
||||
setSNValue (getSNValue () + static_cast<std::int64_t> (v));
|
||||
else *this += STAmount (mCurrency, v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator-= (beast::uint64 v)
|
||||
STAmount& STAmount::operator-= (std::uint64_t v)
|
||||
{
|
||||
if (mIsNative)
|
||||
setSNValue (getSNValue () - static_cast<beast::int64> (v));
|
||||
setSNValue (getSNValue () - static_cast<std::int64_t> (v));
|
||||
else *this -= STAmount (mCurrency, v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool STAmount::operator< (beast::uint64 v) const
|
||||
bool STAmount::operator< (std::uint64_t v) const
|
||||
{
|
||||
return getSNValue () < static_cast<beast::int64> (v);
|
||||
return getSNValue () < static_cast<std::int64_t> (v);
|
||||
}
|
||||
|
||||
bool STAmount::operator> (beast::uint64 v) const
|
||||
bool STAmount::operator> (std::uint64_t v) const
|
||||
{
|
||||
return getSNValue () > static_cast<beast::int64> (v);
|
||||
return getSNValue () > static_cast<std::int64_t> (v);
|
||||
}
|
||||
|
||||
bool STAmount::operator<= (beast::uint64 v) const
|
||||
bool STAmount::operator<= (std::uint64_t v) const
|
||||
{
|
||||
return getSNValue () <= static_cast<beast::int64> (v);
|
||||
return getSNValue () <= static_cast<std::int64_t> (v);
|
||||
}
|
||||
|
||||
bool STAmount::operator>= (beast::uint64 v) const
|
||||
bool STAmount::operator>= (std::uint64_t v) const
|
||||
{
|
||||
return getSNValue () >= static_cast<beast::int64> (v);
|
||||
return getSNValue () >= static_cast<std::int64_t> (v);
|
||||
}
|
||||
|
||||
STAmount STAmount::operator+ (beast::uint64 v) const
|
||||
STAmount STAmount::operator+ (std::uint64_t v) const
|
||||
{
|
||||
return STAmount (getFName (), getSNValue () + static_cast<beast::int64> (v));
|
||||
return STAmount (getFName (), getSNValue () + static_cast<std::int64_t> (v));
|
||||
}
|
||||
|
||||
STAmount STAmount::operator- (beast::uint64 v) const
|
||||
STAmount STAmount::operator- (std::uint64_t v) const
|
||||
{
|
||||
return STAmount (getFName (), getSNValue () - static_cast<beast::int64> (v));
|
||||
return STAmount (getFName (), getSNValue () - static_cast<std::int64_t> (v));
|
||||
}
|
||||
|
||||
STAmount::operator double () const
|
||||
@@ -833,7 +833,7 @@ STAmount operator+ (const STAmount& v1, const STAmount& v2)
|
||||
return STAmount (v1.getFName (), v1.getSNValue () + v2.getSNValue ());
|
||||
|
||||
int ov1 = v1.mOffset, ov2 = v2.mOffset;
|
||||
beast::int64 vv1 = static_cast<beast::int64> (v1.mValue), vv2 = static_cast<beast::int64> (v2.mValue);
|
||||
std::int64_t vv1 = static_cast<std::int64_t> (v1.mValue), vv2 = static_cast<std::int64_t> (v2.mValue);
|
||||
|
||||
if (v1.mIsNegative) vv1 = -vv1;
|
||||
|
||||
@@ -851,9 +851,9 @@ STAmount operator+ (const STAmount& v1, const STAmount& v2)
|
||||
++ov2;
|
||||
}
|
||||
|
||||
// this addition cannot overflow an beast::int64, it can overflow an STAmount and the constructor will throw
|
||||
// this addition cannot overflow an std::int64_t, it can overflow an STAmount and the constructor will throw
|
||||
|
||||
beast::int64 fv = vv1 + vv2;
|
||||
std::int64_t fv = vv1 + vv2;
|
||||
|
||||
if ((fv >= -10) && (fv <= 10))
|
||||
return STAmount (v1.getFName (), v1.mCurrency, v1.mIssuer);
|
||||
@@ -876,7 +876,7 @@ STAmount operator- (const STAmount& v1, const STAmount& v2)
|
||||
}
|
||||
|
||||
int ov1 = v1.mOffset, ov2 = v2.mOffset;
|
||||
beast::int64 vv1 = static_cast<beast::int64> (v1.mValue), vv2 = static_cast<beast::int64> (v2.mValue);
|
||||
std::int64_t vv1 = static_cast<std::int64_t> (v1.mValue), vv2 = static_cast<std::int64_t> (v2.mValue);
|
||||
|
||||
if (v1.mIsNegative) vv1 = -vv1;
|
||||
|
||||
@@ -894,9 +894,9 @@ STAmount operator- (const STAmount& v1, const STAmount& v2)
|
||||
++ov2;
|
||||
}
|
||||
|
||||
// this subtraction cannot overflow an beast::int64, it can overflow an STAmount and the constructor will throw
|
||||
// this subtraction cannot overflow an std::int64_t, it can overflow an STAmount and the constructor will throw
|
||||
|
||||
beast::int64 fv = vv1 - vv2;
|
||||
std::int64_t fv = vv1 - vv2;
|
||||
|
||||
if ((fv >= -10) && (fv <= 10))
|
||||
return STAmount (v1.getFName (), v1.mCurrency, v1.mIssuer);
|
||||
@@ -914,7 +914,7 @@ STAmount STAmount::divide (const STAmount& num, const STAmount& den, const uint1
|
||||
if (num.isZero ())
|
||||
return STAmount (uCurrencyID, uIssuerID);
|
||||
|
||||
beast::uint64 numVal = num.mValue, denVal = den.mValue;
|
||||
std::uint64_t numVal = num.mValue, denVal = den.mValue;
|
||||
int numOffset = num.mOffset, denOffset = den.mOffset;
|
||||
|
||||
if (num.mIsNative)
|
||||
@@ -937,7 +937,7 @@ STAmount STAmount::divide (const STAmount& num, const STAmount& den, const uint1
|
||||
|
||||
if ((BN_add_word64 (&v, numVal) != 1) ||
|
||||
(BN_mul_word64 (&v, tenTo17) != 1) ||
|
||||
(BN_div_word64 (&v, denVal) == ((beast::uint64) - 1)))
|
||||
(BN_div_word64 (&v, denVal) == ((std::uint64_t) - 1)))
|
||||
{
|
||||
throw std::runtime_error ("internal bn error");
|
||||
}
|
||||
@@ -956,8 +956,8 @@ STAmount STAmount::multiply (const STAmount& v1, const STAmount& v2, const uint1
|
||||
|
||||
if (v1.mIsNative && v2.mIsNative && uCurrencyID.isZero ())
|
||||
{
|
||||
beast::uint64 minV = (v1.getSNValue () < v2.getSNValue ()) ? v1.getSNValue () : v2.getSNValue ();
|
||||
beast::uint64 maxV = (v1.getSNValue () < v2.getSNValue ()) ? v2.getSNValue () : v1.getSNValue ();
|
||||
std::uint64_t minV = (v1.getSNValue () < v2.getSNValue ()) ? v1.getSNValue () : v2.getSNValue ();
|
||||
std::uint64_t maxV = (v1.getSNValue () < v2.getSNValue ()) ? v2.getSNValue () : v1.getSNValue ();
|
||||
|
||||
if (minV > 3000000000ull) // sqrt(cMaxNative)
|
||||
throw std::runtime_error ("Native value overflow");
|
||||
@@ -968,7 +968,7 @@ STAmount STAmount::multiply (const STAmount& v1, const STAmount& v2, const uint1
|
||||
return STAmount (v1.getFName (), minV * maxV);
|
||||
}
|
||||
|
||||
beast::uint64 value1 = v1.mValue, value2 = v2.mValue;
|
||||
std::uint64_t value1 = v1.mValue, value2 = v2.mValue;
|
||||
int offset1 = v1.mOffset, offset2 = v2.mOffset;
|
||||
|
||||
if (v1.mIsNative)
|
||||
@@ -995,7 +995,7 @@ STAmount STAmount::multiply (const STAmount& v1, const STAmount& v2, const uint1
|
||||
|
||||
if ((BN_add_word64 (&v, value1) != 1) ||
|
||||
(BN_mul_word64 (&v, value2) != 1) ||
|
||||
(BN_div_word64 (&v, tenTo14) == ((beast::uint64) - 1)))
|
||||
(BN_div_word64 (&v, tenTo14) == ((std::uint64_t) - 1)))
|
||||
{
|
||||
throw std::runtime_error ("internal bn error");
|
||||
}
|
||||
@@ -1016,7 +1016,7 @@ STAmount STAmount::multiply (const STAmount& v1, const STAmount& v2, const uint1
|
||||
// A lower rate is better for the person taking the order.
|
||||
// The taker gets more for less with a lower rate.
|
||||
// Zero is returned if the offer is worthless.
|
||||
beast::uint64 STAmount::getRate (const STAmount& offerOut, const STAmount& offerIn)
|
||||
std::uint64_t STAmount::getRate (const STAmount& offerOut, const STAmount& offerIn)
|
||||
{
|
||||
if (offerOut.isZero ())
|
||||
return 0;
|
||||
@@ -1030,7 +1030,7 @@ beast::uint64 STAmount::getRate (const STAmount& offerOut, const STAmount& offer
|
||||
|
||||
assert ((r.getExponent () >= -100) && (r.getExponent () <= 155));
|
||||
|
||||
beast::uint64 ret = r.getExponent () + 100;
|
||||
std::uint64_t ret = r.getExponent () + 100;
|
||||
|
||||
return (ret << (64 - 8)) | r.getMantissa ();
|
||||
}
|
||||
@@ -1041,12 +1041,12 @@ beast::uint64 STAmount::getRate (const STAmount& offerOut, const STAmount& offer
|
||||
}
|
||||
}
|
||||
|
||||
STAmount STAmount::setRate (beast::uint64 rate)
|
||||
STAmount STAmount::setRate (std::uint64_t rate)
|
||||
{
|
||||
if (rate == 0)
|
||||
return STAmount (CURRENCY_ONE, ACCOUNT_ONE);
|
||||
|
||||
beast::uint64 mantissa = rate & ~ (255ull << (64 - 8));
|
||||
std::uint64_t mantissa = rate & ~ (255ull << (64 - 8));
|
||||
int exponent = static_cast<int> (rate >> (64 - 8)) - 100;
|
||||
|
||||
return STAmount (CURRENCY_ONE, ACCOUNT_ONE, mantissa, exponent);
|
||||
@@ -1080,7 +1080,7 @@ STAmount STAmount::setRate (beast::uint64 rate)
|
||||
// <-- saOfferIssuerFee: Actual
|
||||
bool STAmount::applyOffer (
|
||||
const bool bSell,
|
||||
const beast::uint32 uTakerPaysRate, const beast::uint32 uOfferPaysRate,
|
||||
const std::uint32_t uTakerPaysRate, const std::uint32_t uOfferPaysRate,
|
||||
const STAmount& saOfferRate,
|
||||
const STAmount& saOfferFunds, const STAmount& saTakerFunds,
|
||||
const STAmount& saOfferPays, const STAmount& saOfferGets,
|
||||
@@ -1260,7 +1260,7 @@ STAmount STAmount::getRound () const
|
||||
if (mIsNative)
|
||||
return *this;
|
||||
|
||||
beast::uint64 valueDigits = mValue % 1000000000ull;
|
||||
std::uint64_t valueDigits = mValue % 1000000000ull;
|
||||
|
||||
if (valueDigits == 1)
|
||||
return STAmount (mCurrency, mIssuer, mValue - 1, mOffset, mIsNegative);
|
||||
@@ -1275,7 +1275,7 @@ void STAmount::roundSelf ()
|
||||
if (mIsNative)
|
||||
return;
|
||||
|
||||
beast::uint64 valueDigits = mValue % 1000000000ull;
|
||||
std::uint64_t valueDigits = mValue % 1000000000ull;
|
||||
|
||||
if (valueDigits == 1)
|
||||
{
|
||||
@@ -1380,7 +1380,7 @@ public:
|
||||
|
||||
expect (! prod1.isNative ());
|
||||
|
||||
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<beast::uint64> (a) * static_cast<beast::uint64> (b));
|
||||
STAmount prod2 (CURRENCY_ONE, ACCOUNT_ONE, static_cast<std::uint64_t> (a) * static_cast<std::uint64_t> (b));
|
||||
|
||||
if (prod1 != prod2)
|
||||
{
|
||||
@@ -1780,7 +1780,7 @@ public:
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
beast::uint64 r = rand ();
|
||||
std::uint64_t r = rand ();
|
||||
r <<= 32;
|
||||
r |= rand ();
|
||||
b.setuint64 (r);
|
||||
@@ -1882,7 +1882,7 @@ public:
|
||||
expect (bigDsmall.isZero (), beast::String ("(small/bigNative)->N != 0: ") + bigDsmall.getText ());
|
||||
|
||||
// very bad offer
|
||||
beast::uint64 r = STAmount::getRate (smallValue, bigValue);
|
||||
std::uint64_t r = STAmount::getRate (smallValue, bigValue);
|
||||
|
||||
expect (r == 0, "getRate(smallOut/bigIn) != 0");
|
||||
|
||||
@@ -1902,7 +1902,7 @@ public:
|
||||
#if 0
|
||||
beginTestCase ("rounding ");
|
||||
|
||||
beast::uint64 value = 25000000000000000ull;
|
||||
std::uint64_t value = 25000000000000000ull;
|
||||
int offset = -14;
|
||||
STAmount::canonicalizeRound (false, value, offset, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user