Skip to content

Commit 668ac61

Browse files
committed
Refactor nMaxMoneyOut back to amount.h
1 parent 2ceeb2c commit 668ac61

File tree

10 files changed

+29
-23
lines changed

10 files changed

+29
-23
lines changed

src/amount.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@
1212
#include <stdlib.h>
1313
#include <string>
1414

15+
/** Amount in PIV (Can be negative) */
1516
typedef int64_t CAmount;
1617

1718
static const CAmount COIN = 100000000;
1819
static const CAmount CENT = 1000000;
1920

20-
/** Type-safe wrapper class to for fee rates
21-
* (how much to pay based on transaction size)
21+
/** No amount larger than this (in PIV) is valid in a single UTXO.
22+
*
23+
* Note that this constant is *not* the total money supply, which in PIVX
24+
* is not limited to an arbitrary hard cap, but rather a sanity check. As
25+
* this sanity check is used by consensus-critical validation code, the
26+
* exact value of the MAX_MONEY_OUT constant is consensus critical; in
27+
* unusual circumstances like an overflow bug that allows for the creation
28+
* of coins out of thin air modification could lead to a fork.
29+
*/
30+
static const CAmount MAX_MONEY_OUT = 21000000 * COIN;
31+
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY_OUT); }
32+
33+
/**
34+
* Fee rate in PIV per kilobyte: CAmount / kB
2235
*/
2336
class CFeeRate
2437
{

src/chainparams.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class CMainParams : public CChainParams
189189
nFutureTimeDriftPoW = 7200;
190190
nFutureTimeDriftPoS = 180;
191191
nMasternodeCountDrift = 20;
192-
nMaxMoneyOut = 21000000 * COIN;
193192
nMinColdStakingAmount = 1 * COIN;
194193

195194
/** Height or Time Based Activations **/
@@ -343,7 +342,6 @@ class CTestNetParams : public CMainParams
343342
nStakeMinDepth = 100;
344343
nMasternodeCountDrift = 4;
345344
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
346-
nMaxMoneyOut = 43199500 * COIN;
347345
nZerocoinStartHeight = 201576;
348346
nZerocoinStartTime = 1501776000;
349347
nBlockEnforceSerialRange = 1; //Enforce serial range starting this block
@@ -452,7 +450,6 @@ class CRegTestParams : public CTestNetParams
452450
nStakeMinDepth = 0;
453451
nMasternodeCountDrift = 4;
454452
nModifierUpdateBlock = 0;
455-
nMaxMoneyOut = 43199500 * COIN;
456453
nZerocoinStartHeight = 300;
457454
nBlockZerocoinV2 = 300;
458455
nZerocoinStartTime = 1501776000;

src/chainparams.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class CChainParams
9292
int FutureBlockTimeDrift(const int nHeight) const;
9393
bool IsValidBlockTimeStamp(const int64_t nTime, const int nHeight) const;
9494

95-
CAmount MaxMoneyOut() const { return nMaxMoneyOut; }
9695
/** The masternode count that we will allow the see-saw reward payments to be off by */
9796
int MasternodeCountDrift() const { return nMasternodeCountDrift; }
9897
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
@@ -195,7 +194,6 @@ class CChainParams
195194
int nTimeSlotLength;
196195

197196
int nModifierUpdateBlock;
198-
CAmount nMaxMoneyOut;
199197
int nMinerThreads;
200198
std::vector<CDNSSeedData> vSeeds;
201199
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];

src/main.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "addrman.h"
1414
#include "alert.h"
15+
#include "amount.h"
1516
#include "blocksignature.h"
1617
#include "chainparams.h"
1718
#include "checkpoints.h"
@@ -930,11 +931,6 @@ int GetIXConfirmations(uint256 nTXHash)
930931
return 0;
931932
}
932933

933-
bool MoneyRange(CAmount nValueOut)
934-
{
935-
return nValueOut >= 0 && nValueOut <= Params().MaxMoneyOut();
936-
}
937-
938934
bool CheckZerocoinMint(const uint256& txHash, const CTxOut& txout, CValidationState& state, bool fCheckOnly)
939935
{
940936
libzerocoin::PublicCoin pubCoin(Params().Zerocoin_Params(false));
@@ -1164,7 +1160,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
11641160
if (txout.nValue < 0)
11651161
return state.DoS(100, error("CheckTransaction() : txout.nValue negative"),
11661162
REJECT_INVALID, "bad-txns-vout-negative");
1167-
if (txout.nValue > Params().MaxMoneyOut())
1163+
if (txout.nValue > MAX_MONEY_OUT)
11681164
return state.DoS(100, error("CheckTransaction() : txout.nValue too high"),
11691165
REJECT_INVALID, "bad-txns-vout-toolarge");
11701166
nValueOut += txout.nValue;
@@ -1302,7 +1298,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
13021298
}
13031299

13041300
if (!MoneyRange(nMinFee))
1305-
nMinFee = Params().MaxMoneyOut();
1301+
nMinFee = MAX_MONEY_OUT;
13061302
return nMinFee;
13071303
}
13081304

src/main.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ struct CDiskTxPos : public CDiskBlockPos {
297297

298298

299299
CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
300-
bool MoneyRange(CAmount nValueOut);
301300

302301
/**
303302
* Check transaction inputs, and make sure any

src/qt/bitcoinunits.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Distributed under the MIT/X11 software license, see the accompanying
55
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

7+
#include "amount.h"
78
#include "bitcoinunits.h"
89
#include "chainparams.h"
910
#include "primitives/transaction.h"
@@ -308,5 +309,5 @@ QVariant BitcoinUnits::data(const QModelIndex& index, int role) const
308309

309310
CAmount BitcoinUnits::maxMoney()
310311
{
311-
return Params().MaxMoneyOut();
312+
return MAX_MONEY_OUT;
312313
}

src/qt/blockexplorer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include "amount.h"
56
#include "blockexplorer.h"
67
#include "bitcoinunits.h"
78
#include "chainparams.h"
@@ -217,7 +218,7 @@ std::string BlockToString(CBlockIndex* pBlock)
217218
if (tx.IsCoinBase())
218219
Reward += Out;
219220
else if (In < 0)
220-
Fees = -Params().MaxMoneyOut();
221+
Fees = -MAX_MONEY_OUT;
221222
else {
222223
Fees += In - Out;
223224
OutVolume += Out;
@@ -312,7 +313,7 @@ std::string TxToString(uint256 BlockHash, const CTransaction& tx)
312313
COutPoint Out = tx.vin[i].prevout;
313314
CTxOut PrevOut = getPrevOut(tx.vin[i].prevout);
314315
if (PrevOut.nValue < 0)
315-
Input = -Params().MaxMoneyOut();
316+
Input = -MAX_MONEY_OUT;
316317
else
317318
Input += PrevOut.nValue;
318319
std::string InputsContentCells[] =
@@ -438,7 +439,7 @@ BlockExplorer::BlockExplorer(QWidget* parent) : QMainWindow(parent),
438439
ui->setupUi(this);
439440

440441
this->setStyleSheet(GUIUtil::loadStyleSheet());
441-
442+
442443
connect(ui->pushSearch, SIGNAL(released()), this, SLOT(onSearch()));
443444
connect(ui->content, SIGNAL(linkActivated(const QString&)), this, SLOT(goTo(const QString&)));
444445
connect(ui->back, SIGNAL(released()), this, SLOT(back()));

src/test/data/tx_invalid.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xae609aca8061d77c5e111f6bb62501a6bbe2bfdb EQUAL"]],
3737
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d4830450220063222cbb128731fc09de0d7323746539166544d6c1df84d867ccea84bcc8903022100bf568e8552844de664cd41648a031554327aa8844af34b4f27397c65b92c04de0123210243ec37dee0e2e053a9c976f43147e79bc7d9dc606ea51010af1ac80db6b069e1acffffffff01ffffffffffffffff015100000000", "P2SH"],
3838

39-
["MAX_MONEY + 1 output"],
39+
["MAX_MONEY_OUT + 1 output"],
4040
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x32afac281462b822adbec5094b8d4d337dd5bd6a EQUAL"]],
4141
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006e493046022100e1eadba00d9296c743cb6ecc703fd9ddc9b3cd12906176a226ae4c18d6b00796022100a71aef7d2874deff681ba6080f1b278bac7bb99c61b08a85f4311970ffe7f63f012321030c0588dc44d92bdcbf8e72093466766fdc265ead8db64517b0c542275b70fffbacffffffff010140075af0750700015100000000", "P2SH"],
4242

43-
["MAX_MONEY output + 1 output"],
43+
["MAX_MONEY_OUT output + 1 output"],
4444
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xb558cbf4930954aa6a344363a15668d7477ae716 EQUAL"]],
4545
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d483045022027deccc14aa6668e78a8c9da3484fbcd4f9dcc9bb7d1b85146314b21b9ae4d86022100d0b43dece8cfb07348de0ca8bc5b86276fa88f7f2138381128b7c36ab2e42264012321029bb13463ddd5d2cc05da6e84e37536cb9525703cfd8f43afdb414988987a92f6acffffffff020040075af075070001510001000000000000015100000000", "P2SH"],
4646

src/test/data/tx_valid.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006e493046022100c66c9cdf4c43609586d15424c54707156e316d88b0a1534c9e6b0d4f311406310221009c0fe51dbc9c4ab7cc25d3fdbeccf6679fe6827f08edf2b4a9f16ee3eb0e438a0123210338e8034509af564c62644c07691942e0c056752008a173c89f60ab2a88ac2ebfacffffffff010000000000000000015100000000", "P2SH"],
6666

6767
["Tests for CheckTransaction()"],
68-
["MAX_MONEY output"],
68+
["MAX_MONEY_OUT output"],
6969
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x32afac281462b822adbec5094b8d4d337dd5bd6a EQUAL"]],
7070
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006e493046022100e1eadba00d9296c743cb6ecc703fd9ddc9b3cd12906176a226ae4c18d6b00796022100a71aef7d2874deff681ba6080f1b278bac7bb99c61b08a85f4311970ffe7f63f012321030c0588dc44d92bdcbf8e72093466766fdc265ead8db64517b0c542275b70fffbacffffffff010040075af0750700015100000000", "P2SH"],
7171

72-
["MAX_MONEY output + 0 output"],
72+
["MAX_MONEY_OUT output + 0 output"],
7373
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xb558cbf4930954aa6a344363a15668d7477ae716 EQUAL"]],
7474
"01000000010001000000000000000000000000000000000000000000000000000000000000000000006d483045022027deccc14aa6668e78a8c9da3484fbcd4f9dcc9bb7d1b85146314b21b9ae4d86022100d0b43dece8cfb07348de0ca8bc5b86276fa88f7f2138381128b7c36ab2e42264012321029bb13463ddd5d2cc05da6e84e37536cb9525703cfd8f43afdb414988987a92f6acffffffff020040075af075070001510000000000000000015100000000", "P2SH"],
7575

src/wallet/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "wallet/wallet.h"
99

10+
#include "amount.h"
1011
#include "base58.h"
1112
#include "checkpoints.h"
1213
#include "coincontrol.h"

0 commit comments

Comments
 (0)