From ab01c7c4a70742c0e71e1644213f6a7dde15a729 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 12 Oct 2012 09:21:29 -0700 Subject: [PATCH] I believe our comparisons were broken for STAmount, for example, 0 XNS would compare greater than 1 XNS! For non-native currencies, -2 would be greater than -1, which is wrong. This should fix it. We definitely need to make some test cases. Arthur, please look over this code and make sure I didn't miss something. --- src/Amount.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index 672d67505f..ae518f8adf 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -478,10 +478,12 @@ void STAmount::setValue(const STAmount &a) uint64 STAmount::toUInt64() const { // makes them sort easily + if (mIsNative) + return mValue; if (mValue == 0) return 0x4000000000000000ull; if (mIsNegative) - return mValue | (static_cast(mOffset + 97) << (64 - 10)); + return ((cMaxNative + 1) - mValue) | (static_cast(mOffset + 97) << (64 - 10)); return mValue | (static_cast(mOffset + 256 + 97) << (64 - 10)); }