mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Tidy up some STAmount and base_uint operations:
* Constrain use of arithmetic operators in STAmount * Prevent constructor conversion of uint256 to uint128 - make intent clear * Prevent implicit conversion of uint64_t to uint256 * Prevent implicit conversion of uint64_t to uint160
This commit is contained in:
committed by
Vinnie Falco
parent
6ae329f4a6
commit
912d74e805
@@ -30,7 +30,7 @@ uint128 CKey::PassPhraseToKey (const std::string& passPhrase)
|
||||
|
||||
s.addRaw (passPhrase);
|
||||
uint256 hash256 = s.getSHA512Half ();
|
||||
uint128 ret (hash256);
|
||||
uint128 ret (uint128::low128(hash256));
|
||||
|
||||
s.secureErase ();
|
||||
|
||||
|
||||
@@ -765,19 +765,23 @@ STAmount& STAmount::operator= (std::uint64_t v)
|
||||
|
||||
STAmount& STAmount::operator+= (std::uint64_t v)
|
||||
{
|
||||
if (mIsNative)
|
||||
setSNValue (getSNValue () + static_cast<std::int64_t> (v));
|
||||
else *this += STAmount (mCurrency, v);
|
||||
assert (mIsNative);
|
||||
|
||||
if (!mIsNative)
|
||||
throw std::runtime_error ("not native");
|
||||
|
||||
setSNValue (getSNValue () + static_cast<std::int64_t> (v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
STAmount& STAmount::operator-= (std::uint64_t v)
|
||||
{
|
||||
if (mIsNative)
|
||||
setSNValue (getSNValue () - static_cast<std::int64_t> (v));
|
||||
else *this -= STAmount (mCurrency, v);
|
||||
assert (mIsNative);
|
||||
|
||||
if (!mIsNative)
|
||||
throw std::runtime_error ("not native");
|
||||
|
||||
setSNValue (getSNValue () - static_cast<std::int64_t> (v));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user