Changeset View
Changeset View
Standalone View
Standalone View
src/amount.h
Show All 12 Lines | |||||
#include <ostream> | #include <ostream> | ||||
#include <string> | #include <string> | ||||
#include <type_traits> | #include <type_traits> | ||||
struct Amount { | struct Amount { | ||||
private: | private: | ||||
int64_t amount; | int64_t amount; | ||||
explicit constexpr Amount(int64_t _amount) : amount(_amount) {} | |||||
public: | public: | ||||
constexpr Amount() : amount(0) {} | constexpr Amount() : amount(0) {} | ||||
constexpr Amount(const Amount &_camount) : amount(_camount.amount) {} | constexpr Amount(const Amount &_camount) : amount(_camount.amount) {} | ||||
explicit constexpr Amount(int64_t _amount) : amount(_amount) {} | |||||
static constexpr Amount zero() { return Amount(0); } | static constexpr Amount zero() { return Amount(0); } | ||||
static constexpr Amount satoshi() { return Amount(1); } | static constexpr Amount satoshi() { return Amount(1); } | ||||
/** | /** | ||||
* Implement standard operators | * Implement standard operators | ||||
*/ | */ | ||||
Amount &operator+=(const Amount a) { | Amount &operator+=(const Amount a) { | ||||
amount += a.amount; | amount += a.amount; | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Note that this constant is *not* the total money supply, which in Bitcoin | * Note that this constant is *not* the total money supply, which in Bitcoin | ||||
* currently happens to be less than 21,000,000 BCH for various reasons, but | * currently happens to be less than 21,000,000 BCH for various reasons, but | ||||
* rather a sanity check. As this sanity check is used by consensus-critical | * 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 | * validation code, the exact value of the MAX_MONEY constant is consensus | ||||
* critical; in unusual circumstances like a(nother) overflow bug that allowed | * 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. | * for the creation of coins out of thin air modification could lead to a fork. | ||||
*/ | */ | ||||
static const Amount MAX_MONEY = 21000000 * COIN; | static constexpr Amount MAX_MONEY = 21000000 * COIN; | ||||
inline bool MoneyRange(const Amount nValue) { | inline bool MoneyRange(const Amount nValue) { | ||||
return nValue >= Amount::zero() && nValue <= MAX_MONEY; | return nValue >= Amount::zero() && nValue <= MAX_MONEY; | ||||
} | } | ||||
#endif // BITCOIN_AMOUNT_H | #endif // BITCOIN_AMOUNT_H |