Skip to content

Commit ed591d6

Browse files
committed
[Core] Introduce CMoneySupply class
Dumb storage class. This will be used to cache the sum of spendable transaction outputs (and the height of the chain when this sum was last updated).
1 parent 48e3c91 commit ed591d6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ BITCOIN_CORE_H = \
211211
merkleblock.h \
212212
messagesigner.h \
213213
miner.h \
214+
moneysupply.h \
214215
net.h \
215216
net_processing.h \
216217
netaddress.h \

src/moneysupply.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2020 The PIVX 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+
void Update(const CAmount& _nSupply, int _nHeight)
25+
{
26+
LOCK(cs);
27+
nSupply = _nSupply;
28+
nHeight = _nHeight;
29+
}
30+
31+
CAmount Get() const { LOCK(cs); return nSupply; }
32+
int64_t GetCacheHeight() const { LOCK(cs); return nHeight; }
33+
};
34+
35+
#endif // PIVX_MONEYSUPPLY_H

0 commit comments

Comments
 (0)