Line data Source code
1 : // Copyright (c) 2020 The PIVX Core developers 2 : // Distributed under the MIT/X11 software license, see the accompanying 3 : // file COPYING or https://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef PIVX_MONEYSUPPLY_H 6 : #define PIVX_MONEYSUPPLY_H 7 : 8 : #include "amount.h" 9 : #include "sync.h" 10 : 11 : /* 12 : * Class used to cache the sum of utxo's values 13 : */ 14 : class CMoneySupply { 15 : private: 16 : mutable RecursiveMutex cs; 17 : CAmount nSupply; 18 : // height of the chain when the supply was last updated 19 : int64_t nHeight; 20 : 21 : public: 22 : CMoneySupply(): nSupply(0), nHeight(0) {} 23 : 24 440 : void Update(const CAmount& _nSupply, int _nHeight) 25 : { 26 440 : LOCK(cs); 27 440 : nSupply = _nSupply; 28 440 : nHeight = _nHeight; 29 440 : } 30 : 31 12 : CAmount Get() const { LOCK(cs); return nSupply; } 32 12 : int64_t GetCacheHeight() const { LOCK(cs); return nHeight; } 33 : }; 34 : 35 : #endif // PIVX_MONEYSUPPLY_H