diff --git a/src/amount.h b/src/amount.h --- a/src/amount.h +++ b/src/amount.h @@ -20,7 +20,8 @@ public: constexpr Amount() : amount(0) {} - template constexpr Amount(T _camount) : amount(_camount) { + template + explicit constexpr Amount(T _camount) : amount(_camount) { static_assert(std::is_integral(), "Only integer types can be used as amounts"); } @@ -108,8 +109,8 @@ /** Amount in satoshis (Can be negative) */ typedef int64_t CAmount; -static const Amount COIN = 100000000; -static const Amount CENT = 1000000; +static const Amount COIN(100000000); +static const Amount CENT(1000000); extern const std::string CURRENCY_UNIT; @@ -125,7 +126,7 @@ */ static const Amount MAX_MONEY = 21000000 * COIN; inline bool MoneyRange(const Amount nValue) { - return (nValue >= 0 && nValue <= MAX_MONEY); + return (nValue >= Amount(0) && nValue <= MAX_MONEY); } /** diff --git a/src/amount.cpp b/src/amount.cpp --- a/src/amount.cpp +++ b/src/amount.cpp @@ -21,7 +21,7 @@ if (nSize > 0) { nSatoshisPerK = 1000 * nFeePaid / nSize; } else { - nSatoshisPerK = 0; + nSatoshisPerK = Amount(0); } } @@ -31,11 +31,11 @@ Amount nFee = nSize * nSatoshisPerK / 1000; - if (nFee == 0 && nSize != 0) { - if (nSatoshisPerK > 0) { + if (nFee == Amount(0) && nSize != 0) { + if (nSatoshisPerK > Amount(0)) { nFee = Amount(1); } - if (nSatoshisPerK < 0) { + if (nSatoshisPerK < Amount(0)) { nFee = Amount(-1); } }