// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2021 The Limenka developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef LIMENKA_CONSENSUS_AMOUNT_H #define LIMENKA_CONSENSUS_AMOUNT_H #include /** Amount in satoshis (Can be negative). * Using __int128 to provide 64 extra bits of sub-satoshi precision, * futureproofing against fiat inflation for the foreseeable future. * COIN = 10^-8 BTC is unchanged; the extra bits sit below satoshis. */ typedef __int128 CAmount; /** The amount of satoshis in one BTC. */ static constexpr CAmount COIN = 100000000; /** Attosats per satoshi (10^-18 = 18 decimals of sub-satoshi precision). * CT committed values and the CT kernel fee use attosat units. */ static constexpr CAmount ATTOSATS_PER_SATOSHI = 1000000000000000000; /** No amount larger than this (in satoshi) is valid. * * Note that this constant is *not* the total money supply, which in Limenka * currently happens to be less than 21,000,000 BTC for various reasons, but * rather a sanity check. As this sanity check is used by consensus-critical * validation code, the exact value of the MAX_MONEY constant is consensus * critical; in unusual circumstances like a(nother) overflow bug that allowed * for the creation of coins out of thin air modification could lead to a fork. * */ static constexpr CAmount MAX_MONEY = 21000000 * COIN; inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } #include /** Stream insertion for __int128 (not provided by standard library). */ inline std::ostream& operator<<(std::ostream& os, const __int128& n) { __int128 abs_n = n; if (abs_n < 0) { os << '-'; abs_n = -abs_n; } char buf[40]; int p = sizeof(buf); do { buf[--p] = '0' + static_cast(abs_n % 10); abs_n /= 10; } while (abs_n > 0); return os.write(buf + p, sizeof(buf) - p); } #endif // LIMENKA_CONSENSUS_AMOUNT_H