Skip to content

Commit 3f4d5c4

Browse files
CryptoDJschinzelh
authored andcommitted
Updates monetary variable int64_t types to CAmount.
Closes #677
1 parent 4212195 commit 3f4d5c4

10 files changed

+87
-86
lines changed

src/darksend.cpp

+30-30
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
173173
}
174174

175175
std::vector<CTxIn> in;
176-
int64_t nAmount;
176+
CAmount nAmount;
177177
CTransaction txCollateral;
178178
std::vector<CTxOut> out;
179179
vRecv >> in >> nAmount >> txCollateral >> out;
@@ -197,8 +197,8 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
197197

198198
//check it like a transaction
199199
{
200-
int64_t nValueIn = 0;
201-
int64_t nValueOut = 0;
200+
CAmount nValueIn = 0;
201+
CAmount nValueOut = 0;
202202
bool missingTx = false;
203203

204204
CValidationState state;
@@ -936,8 +936,8 @@ bool CDarksendPool::IsCollateralValid(const CTransaction& txCollateral){
936936
if(txCollateral.vout.size() < 1) return false;
937937
if(txCollateral.nLockTime != 0) return false;
938938

939-
int64_t nValueIn = 0;
940-
int64_t nValueOut = 0;
939+
CAmount nValueIn = 0;
940+
CAmount nValueOut = 0;
941941
bool missingTx = false;
942942

943943
BOOST_FOREACH(const CTxOut o, txCollateral.vout){
@@ -990,7 +990,7 @@ bool CDarksendPool::IsCollateralValid(const CTransaction& txCollateral){
990990
//
991991
// Add a clients transaction to the pool
992992
//
993-
bool CDarksendPool::AddEntry(const std::vector<CTxIn>& newInput, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxOut>& newOutput, int& errorID){
993+
bool CDarksendPool::AddEntry(const std::vector<CTxIn>& newInput, const CAmount& nAmount, const CTransaction& txCollateral, const std::vector<CTxOut>& newOutput, int& errorID){
994994
if (!fMasterNode) return false;
995995

996996
BOOST_FOREACH(CTxIn in, newInput) {
@@ -1092,7 +1092,7 @@ bool CDarksendPool::SignaturesComplete(){
10921092
// Execute a Darksend denomination via a Masternode.
10931093
// This is only ran from clients
10941094
//
1095-
void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64_t amount){
1095+
void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, CAmount amount){
10961096

10971097
if(fMasterNode) {
10981098
LogPrintf("CDarksendPool::SendDarksendDenominate() - Darksend from a Masternode is not supported currently.\n");
@@ -1139,7 +1139,7 @@ void CDarksendPool::SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<
11391139

11401140
//check it against the memory pool to make sure it's valid
11411141
{
1142-
int64_t nValueOut = 0;
1142+
CAmount nValueOut = 0;
11431143

11441144
CValidationState state;
11451145
CMutableTransaction tx;
@@ -1652,8 +1652,8 @@ bool CDarksendPool::PrepareDarksendDenominate()
16521652

16531653
bool CDarksendPool::SendRandomPaymentToSelf()
16541654
{
1655-
int64_t nBalance = pwalletMain->GetBalance();
1656-
int64_t nPayment = (nBalance*0.35) + (rand() % nBalance);
1655+
CAmount nBalance = pwalletMain->GetBalance();
1656+
CAmount nPayment = (nBalance*0.35) + (rand() % nBalance);
16571657

16581658
if(nPayment > nBalance) nPayment = nBalance-(0.1*COIN);
16591659

@@ -1666,9 +1666,9 @@ bool CDarksendPool::SendRandomPaymentToSelf()
16661666
scriptChange = GetScriptForDestination(vchPubKey.GetID());
16671667

16681668
CWalletTx wtx;
1669-
int64_t nFeeRet = 0;
1669+
CAmount nFeeRet = 0;
16701670
std::string strFail = "";
1671-
vector< pair<CScript, int64_t> > vecSend;
1671+
vector< pair<CScript, CAmount> > vecSend;
16721672

16731673
// ****** Add fees ************ /
16741674
vecSend.push_back(make_pair(scriptChange, nPayment));
@@ -1691,9 +1691,9 @@ bool CDarksendPool::SendRandomPaymentToSelf()
16911691
bool CDarksendPool::MakeCollateralAmounts()
16921692
{
16931693
CWalletTx wtx;
1694-
int64_t nFeeRet = 0;
1694+
CAmount nFeeRet = 0;
16951695
std::string strFail = "";
1696-
vector< pair<CScript, int64_t> > vecSend;
1696+
vector< pair<CScript, CAmount> > vecSend;
16971697
CCoinControl *coinControl = NULL;
16981698

16991699
// make our collateral address
@@ -1740,13 +1740,13 @@ bool CDarksendPool::MakeCollateralAmounts()
17401740
}
17411741

17421742
// Create denominations
1743-
bool CDarksendPool::CreateDenominated(int64_t nTotalValue)
1743+
bool CDarksendPool::CreateDenominated(CAmount nTotalValue)
17441744
{
17451745
CWalletTx wtx;
1746-
int64_t nFeeRet = 0;
1746+
CAmount nFeeRet = 0;
17471747
std::string strFail = "";
1748-
vector< pair<CScript, int64_t> > vecSend;
1749-
int64_t nValueLeft = nTotalValue;
1748+
vector< pair<CScript, CAmount> > vecSend;
1749+
CAmount nValueLeft = nTotalValue;
17501750

17511751
// make our collateral address
17521752
CReserveKey reservekeyCollateral(pwalletMain);
@@ -1768,7 +1768,7 @@ bool CDarksendPool::CreateDenominated(int64_t nTotalValue)
17681768

17691769
// ****** Add denoms ************ /
17701770

1771-
BOOST_REVERSE_FOREACH(int64_t v, darkSendDenominations){
1771+
BOOST_REVERSE_FOREACH(CAmount v, darkSendDenominations){
17721772

17731773
// Note: denoms are skipped if there are already DENOMS_COUNT_MAX of them
17741774

@@ -1852,7 +1852,7 @@ bool CDarksendPool::IsCompatibleWithEntries(std::vector<CTxOut>& vout)
18521852
return true;
18531853
}
18541854

1855-
bool CDarksendPool::IsCompatibleWithSession(int64_t nDenom, CTransaction txCollateral, int& errorID)
1855+
bool CDarksendPool::IsCompatibleWithSession(CAmount nDenom, CTransaction txCollateral, int& errorID)
18561856
{
18571857
if(nDenom == 0) return false;
18581858

@@ -1953,16 +1953,16 @@ int CDarksendPool::GetDenominations(const std::vector<CTxDSOut>& vout){
19531953

19541954
// return a bitshifted integer representing the denominations in this list
19551955
int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom){
1956-
std::vector<pair<int64_t, int> > denomUsed;
1956+
std::vector<pair<CAmount, int> > denomUsed;
19571957

19581958
// make a list of denominations, with zero uses
1959-
BOOST_FOREACH(int64_t d, darkSendDenominations)
1959+
BOOST_FOREACH(CAmount d, darkSendDenominations)
19601960
denomUsed.push_back(make_pair(d, 0));
19611961

19621962
// look for denominations and update uses to 1
19631963
BOOST_FOREACH(CTxOut out, vout){
19641964
bool found = false;
1965-
BOOST_FOREACH (PAIRTYPE(int64_t, int)& s, denomUsed){
1965+
BOOST_FOREACH (PAIRTYPE(CAmount, int)& s, denomUsed){
19661966
if (out.nValue == s.first){
19671967
s.second = 1;
19681968
found = true;
@@ -1975,7 +1975,7 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fSingl
19751975
int c = 0;
19761976
// if the denomination is used, shift the bit on.
19771977
// then move to the next
1978-
BOOST_FOREACH (PAIRTYPE(int64_t, int)& s, denomUsed) {
1978+
BOOST_FOREACH (PAIRTYPE(CAmount, int)& s, denomUsed) {
19791979
int bit = (fSingleRandomDenom ? rand()%2 : 1) * s.second;
19801980
denom |= bit << c++;
19811981
if(fSingleRandomDenom && bit) break; // use just one random denomination
@@ -1992,27 +1992,27 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fSingl
19921992
}
19931993

19941994

1995-
int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& vecAmount){
1995+
int CDarksendPool::GetDenominationsByAmounts(std::vector<CAmount>& vecAmount){
19961996
CScript e = CScript();
19971997
std::vector<CTxOut> vout1;
19981998

19991999
// Make outputs by looping through denominations, from small to large
2000-
BOOST_REVERSE_FOREACH(int64_t v, vecAmount){
2000+
BOOST_REVERSE_FOREACH(CAmount v, vecAmount){
20012001
CTxOut o(v, e);
20022002
vout1.push_back(o);
20032003
}
20042004

20052005
return GetDenominations(vout1, true);
20062006
}
20072007

2008-
int CDarksendPool::GetDenominationsByAmount(int64_t nAmount, int nDenomTarget){
2008+
int CDarksendPool::GetDenominationsByAmount(CAmount nAmount, int nDenomTarget){
20092009
CScript e = CScript();
2010-
int64_t nValueLeft = nAmount;
2010+
CAmount nValueLeft = nAmount;
20112011

20122012
std::vector<CTxOut> vout1;
20132013

20142014
// Make outputs by looping through denominations, from small to large
2015-
BOOST_REVERSE_FOREACH(int64_t v, darkSendDenominations){
2015+
BOOST_REVERSE_FOREACH(CAmount v, darkSendDenominations){
20162016
if(nDenomTarget != 0){
20172017
bool fAccepted = false;
20182018
if((nDenomTarget & (1 << 0)) && v == ((100*COIN)+100000)) {fAccepted = true;}
@@ -2200,7 +2200,7 @@ void CDarksendPool::RelayFinalTransaction(const int sessionID, const CTransactio
22002200
}
22012201
}
22022202

2203-
void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout)
2203+
void CDarksendPool::RelayIn(const std::vector<CTxDSIn>& vin, const CAmount& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout)
22042204
{
22052205
if(!pSubmittedToMasternode) return;
22062206

src/darksend.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class CActiveMasternode;
4646
#define DARKSEND_RELAY_OUT 2
4747
#define DARKSEND_RELAY_SIG 3
4848

49-
static const int64_t DARKSEND_COLLATERAL = (0.01*COIN);
50-
static const int64_t DARKSEND_POOL_MAX = (999.99*COIN);
51-
static const int64_t DENOMS_COUNT_MAX = 100;
49+
static const CAmount DARKSEND_COLLATERAL = (0.01*COIN);
50+
static const CAmount DARKSEND_POOL_MAX = (999.99*COIN);
51+
static const CAmount DENOMS_COUNT_MAX = 100;
5252

5353
extern CDarksendPool darkSendPool;
5454
extern CDarkSendSigner darkSendSigner;
@@ -99,7 +99,7 @@ class CDarkSendEntry
9999
bool isSet;
100100
std::vector<CTxDSIn> sev;
101101
std::vector<CTxDSOut> vout;
102-
int64_t amount;
102+
CAmount amount;
103103
CTransaction collateral;
104104
CTransaction txSupporting;
105105
int64_t addedTime; // time in UTC milliseconds
@@ -112,7 +112,7 @@ class CDarkSendEntry
112112
}
113113

114114
/// Add entries to use for Darksend
115-
bool Add(const std::vector<CTxIn> vinIn, int64_t amountIn, const CTransaction collateralIn, const std::vector<CTxOut> voutIn)
115+
bool Add(const std::vector<CTxIn> vinIn, CAmount amountIn, const CTransaction collateralIn, const std::vector<CTxOut> voutIn)
116116
{
117117
if(isSet){return false;}
118118

@@ -291,7 +291,7 @@ class CDarksendPool
291291

292292
int64_t lastNewBlock;
293293

294-
std::vector<int64_t> darkSendDenominationsSkipped;
294+
std::vector<CAmount> darkSendDenominationsSkipped;
295295

296296
//debugging data
297297
std::string strAutoDenomResult;
@@ -369,8 +369,8 @@ class CDarksendPool
369369
darkSendDenominationsSkipped.clear();
370370
}
371371

372-
bool IsDenomSkipped(int64_t denom) {
373-
BOOST_FOREACH(int64_t d, darkSendDenominationsSkipped) {
372+
bool IsDenomSkipped(CAmount denom) {
373+
BOOST_FOREACH(CAmount d, darkSendDenominationsSkipped) {
374374
if (d == denom) {
375375
return true;
376376
}
@@ -450,7 +450,7 @@ class CDarksendPool
450450
bool IsCompatibleWithEntries(std::vector<CTxOut>& vout);
451451

452452
/// Is this amount compatible with other client in the pool?
453-
bool IsCompatibleWithSession(int64_t nAmount, CTransaction txCollateral, int &errorID);
453+
bool IsCompatibleWithSession(CAmount nAmount, CTransaction txCollateral, int &errorID);
454454

455455
/// Passively run Darksend in the background according to the configuration in settings (only for QT)
456456
bool DoAutomaticDenominating(bool fDryRun=false);
@@ -470,13 +470,13 @@ class CDarksendPool
470470
/// If the collateral is valid given by a client
471471
bool IsCollateralValid(const CTransaction& txCollateral);
472472
/// Add a clients entry to the pool
473-
bool AddEntry(const std::vector<CTxIn>& newInput, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxOut>& newOutput, int& errorID);
473+
bool AddEntry(const std::vector<CTxIn>& newInput, const CAmount& nAmount, const CTransaction& txCollateral, const std::vector<CTxOut>& newOutput, int& errorID);
474474
/// Add signature to a vin
475475
bool AddScriptSig(const CTxIn& newVin);
476476
/// Check that all inputs are signed. (Are all inputs signed?)
477477
bool SignaturesComplete();
478478
/// As a client, send a transaction to a Masternode to start the denomination process
479-
void SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, int64_t amount);
479+
void SendDarksendDenominate(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout, CAmount amount);
480480
/// Get Masternode updates about the progress of Darksend
481481
bool StatusUpdate(int newState, int newEntriesCount, int newAccepted, int &errorID, int newSessionID=0);
482482

@@ -494,7 +494,7 @@ class CDarksendPool
494494

495495
/// Split up large inputs or make fee sized inputs
496496
bool MakeCollateralAmounts();
497-
bool CreateDenominated(int64_t nTotalValue);
497+
bool CreateDenominated(CAmount nTotalValue);
498498

499499
/// Get the denominations for a list of outputs (returns a bitshifted integer)
500500
int GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom = false);
@@ -503,8 +503,8 @@ class CDarksendPool
503503
void GetDenominationsToString(int nDenom, std::string& strDenom);
504504

505505
/// Get the denominations for a specific amount of dash.
506-
int GetDenominationsByAmount(int64_t nAmount, int nDenomTarget=0); // is not used anymore?
507-
int GetDenominationsByAmounts(std::vector<int64_t>& vecAmount);
506+
int GetDenominationsByAmount(CAmount nAmount, int nDenomTarget=0); // is not used anymore?
507+
int GetDenominationsByAmounts(std::vector<CAmount>& vecAmount);
508508

509509
std::string GetMessageByID(int messageID);
510510

@@ -515,7 +515,7 @@ class CDarksendPool
515515
void RelayFinalTransaction(const int sessionID, const CTransaction& txNew);
516516
void RelaySignaturesAnon(std::vector<CTxIn>& vin);
517517
void RelayInAnon(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout);
518-
void RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout);
518+
void RelayIn(const std::vector<CTxDSIn>& vin, const CAmount& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout);
519519
void RelayStatus(const int sessionID, const int newState, const int newEntriesCount, const int newAccepted, const int errorID=MSG_NOERR);
520520
void RelayCompletedTransaction(const int sessionID, const bool error, const int errorID);
521521
};

src/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1534,14 +1534,14 @@ double ConvertBitsToDouble(unsigned int nBits)
15341534
return dDiff;
15351535
}
15361536

1537-
int64_t GetBlockValue(int nBits, int nHeight, const CAmount& nFees)
1537+
CAmount GetBlockValue(int nBits, int nHeight, const CAmount& nFees)
15381538
{
15391539
double dDiff = (double)0x0000ffff / (double)(nBits & 0x00ffffff);
15401540

15411541
/* fixed bug caused diff to not be correctly calculated */
15421542
if(nHeight > 4500 || Params().NetworkID() == CBaseChainParams::TESTNET) dDiff = ConvertBitsToDouble(nBits);
15431543

1544-
int64_t nSubsidy = 0;
1544+
CAmount nSubsidy = 0;
15451545
if(nHeight >= 5465) {
15461546
if((nHeight >= 17000 && dDiff > 75) || nHeight >= 24000) { // GPU/ASIC difficulty calc
15471547
// 2222222/(((x+2600)/9)^2)
@@ -1584,9 +1584,9 @@ int64_t GetBlockValue(int nBits, int nHeight, const CAmount& nFees)
15841584
return nSubsidy + nFees;
15851585
}
15861586

1587-
int64_t GetMasternodePayment(int nHeight, int64_t blockValue)
1587+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
15881588
{
1589-
int64_t ret = blockValue/5; // start at 20%
1589+
CAmount ret = blockValue/5; // start at 20%
15901590

15911591
if(Params().NetworkID() == CBaseChainParams::TESTNET) {
15921592
if(nHeight > 46000) ret += blockValue / 20; //25% - 2014-10-07

src/main.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool DisconnectBlocksAndReprocess(int blocks);
215215

216216
// ***TODO***
217217
double ConvertBitsToDouble(unsigned int nBits);
218-
int64_t GetMasternodePayment(int nHeight, int64_t blockValue);
218+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue);
219219
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock);
220220

221221
bool ActivateBestChain(CValidationState &state, CBlock *pblock = NULL);

src/masternode-payments.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void DumpMasternodePayments()
182182
LogPrintf("Budget dump finished %dms\n", GetTimeMillis() - nStart);
183183
}
184184

185-
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue){
185+
bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue){
186186
CBlockIndex* pindexPrev = chainActive.Tip();
187187
if(pindexPrev == NULL) return true;
188188

@@ -267,7 +267,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
267267
}
268268

269269

270-
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees)
270+
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
271271
{
272272
CBlockIndex* pindexPrev = chainActive.Tip();
273273
if(!pindexPrev) return;
@@ -288,7 +288,7 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
288288
}
289289
}
290290

291-
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees)
291+
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
292292
{
293293
CBlockIndex* pindexPrev = chainActive.Tip();
294294
if(!pindexPrev) return;

src/masternode-payments.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
3030
bool IsReferenceNode(CTxIn& vin);
3131
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight);
3232
std::string GetRequiredPaymentsString(int nBlockHeight);
33-
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue);
34-
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
33+
bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue);
34+
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees);
3535

3636
void DumpMasternodePayments();
3737

@@ -268,7 +268,7 @@ class CMasternodePayments
268268
int GetMinMasternodePaymentsProto();
269269
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
270270
std::string GetRequiredPaymentsString(int nBlockHeight);
271-
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
271+
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees);
272272
std::string ToString() const;
273273
int GetOldestBlock();
274274
int GetNewestBlock();

src/util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool fSucessfullyLoaded = false;
119119
bool fEnableDarksend = false;
120120
bool fDarksendMultiSession = false;
121121
/** All denominations used by darksend */
122-
std::vector<int64_t> darkSendDenominations;
122+
std::vector<CAmount> darkSendDenominations;
123123
string strBudgetMode = "";
124124

125125
map<string, string> mapArgs;

0 commit comments

Comments
 (0)