diff --git a/src/Amount.cpp b/src/Amount.cpp index 6aa3439728..f51dbd5204 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -401,6 +401,50 @@ STAmount& STAmount::operator-=(uint64 v) return *this; } +bool STAmount::operator<(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + return mValue < v; +} + +bool STAmount::operator>(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + return mValue > v; +} + +bool STAmount::operator<=(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + return mValue <= v; +} + +bool STAmount::operator>=(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + return mValue >= v; +} + +STAmount STAmount::operator+(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + return STAmount(true, mValue + v); +} + +STAmount STAmount::operator-(uint64 v) const +{ + if (!mIsNative) + throw std::runtime_error("operation not legal no non-native currency"); + if (mValue < v) + throw std::runtime_error("native currency underflow"); + return STAmount(true, mValue - v); +} + STAmount::operator double() const { // Does not keep the precise value. Not recommended if (!mValue) diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index a525402ecf..1e4c9c92a2 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -200,6 +200,7 @@ protected: void canonicalize(); STAmount* duplicate() const { return new STAmount(name, mCurrency, mValue, mOffset); } static STAmount* construct(SerializerIterator&, const char* name = NULL); + STAmount(bool, uint64 value) : mValue(value), mOffset(0), mIsNative(true) { ; } static const int cMinOffset = -96, cMaxOffset = 80; static const uint64 cMinValue = 1000000000000000ull, cMaxValue = 9999999999999999ull; @@ -250,6 +251,14 @@ public: bool isComparable(const STAmount&) const; void throwComparable(const STAmount&) const; + // native currency only + bool operator<(uint64) const; + bool operator>(uint64) const; + bool operator<=(uint64) const; + bool operator>=(uint64) const; + STAmount operator+(uint64) const; + STAmount operator-(uint64) const; + STAmount& operator+=(const STAmount&); STAmount& operator-=(const STAmount&); STAmount& operator=(const STAmount&);