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:
Nik Bougalis
2014-04-28 11:22:39 -07:00
committed by Vinnie Falco
parent 6ae329f4a6
commit 912d74e805
7 changed files with 27 additions and 22 deletions

View File

@@ -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 ();

View File

@@ -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;
}