diff --git a/src/Amount.cpp b/src/Amount.cpp index 28f3516cf3..0e7f63988e 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -299,18 +299,11 @@ void STAmount::add(Serializer& s) const } } -STAmount::STAmount(SField::ref name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true) +STAmount STAmount::createFromInt64(SField::ref name, int64 value) { - if (value >= 0) - { - mIsNegative = false; - mValue = static_cast(value); - } - else - { - mIsNegative = true; - mValue = static_cast(-value); - } + return value >= 0 + ? STAmount(name, static_cast(value), false) + : STAmount(name, static_cast(-value), true); } void STAmount::setValue(const STAmount &a) @@ -623,7 +616,7 @@ STAmount operator-(const STAmount& v1, const STAmount& v2) v1.throwComparable(v2); if (v2.mIsNative) - return STAmount(v1.fName, v1.getSNValue() - v2.getSNValue()); + return STAmount::createFromInt64(v1.getFName(), v1.getSNValue() - v2.getSNValue()); int ov1 = v1.mOffset, ov2 = v2.mOffset; int64 vv1 = static_cast(v1.mValue), vv2 = static_cast(v2.mValue); diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index de1fb75eb6..246e4cde1f 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -216,11 +216,6 @@ protected: static const uint64 cNotNative = 0x8000000000000000ull; static const uint64 cPosNative = 0x4000000000000000ull; - STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; } - - STAmount(SField::ref name, uint64 value, bool isNegative) - : SerializedType(name), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative) - { ; } STAmount(SField::ref name, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg) : SerializedType(name), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off), mIsNative(isNat), mIsNegative(isNeg) { ; } @@ -236,8 +231,8 @@ public: STAmount(uint64 v = 0, bool isNeg = false) : mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg) { if (v == 0) mIsNegative = false; } - STAmount(SField::ref n, uint64 v = 0) - : SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(false) + STAmount(SField::ref n, uint64 v = 0, bool isNeg = false) + : SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; } STAmount(const uint160& uCurrencyID, const uint160& uIssuerID, uint64 uV = 0, int iOff = 0, bool bNegative = false) @@ -250,7 +245,7 @@ public: SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg) { canonicalize(); } - STAmount(SField::ref n, int64 v); + static STAmount createFromInt64(SField::ref n, int64 v); static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); }