Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates monetary variable int64_t types to CAmount #677

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
}

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

//check it like a transaction
{
int64_t nValueIn = 0;
int64_t nValueOut = 0;
CAmount nValueIn = 0;
CAmount nValueOut = 0;
bool missingTx = false;

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

int64_t nValueIn = 0;
int64_t nValueOut = 0;
CAmount nValueIn = 0;
CAmount nValueOut = 0;
bool missingTx = false;

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

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

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

//check it against the memory pool to make sure it's valid
{
int64_t nValueOut = 0;
CAmount nValueOut = 0;

CValidationState state;
CMutableTransaction tx;
Expand Down Expand Up @@ -1652,8 +1652,8 @@ bool CDarksendPool::PrepareDarksendDenominate()

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

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

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

CWalletTx wtx;
int64_t nFeeRet = 0;
CAmount nFeeRet = 0;
std::string strFail = "";
vector< pair<CScript, int64_t> > vecSend;
vector< pair<CScript, CAmount> > vecSend;

// ****** Add fees ************ /
vecSend.push_back(make_pair(scriptChange, nPayment));
Expand All @@ -1691,9 +1691,9 @@ bool CDarksendPool::SendRandomPaymentToSelf()
bool CDarksendPool::MakeCollateralAmounts()
{
CWalletTx wtx;
int64_t nFeeRet = 0;
CAmount nFeeRet = 0;
std::string strFail = "";
vector< pair<CScript, int64_t> > vecSend;
vector< pair<CScript, CAmount> > vecSend;
CCoinControl *coinControl = NULL;

// make our collateral address
Expand Down Expand Up @@ -1740,13 +1740,13 @@ bool CDarksendPool::MakeCollateralAmounts()
}

// Create denominations
bool CDarksendPool::CreateDenominated(int64_t nTotalValue)
bool CDarksendPool::CreateDenominated(CAmount nTotalValue)
{
CWalletTx wtx;
int64_t nFeeRet = 0;
CAmount nFeeRet = 0;
std::string strFail = "";
vector< pair<CScript, int64_t> > vecSend;
int64_t nValueLeft = nTotalValue;
vector< pair<CScript, CAmount> > vecSend;
CAmount nValueLeft = nTotalValue;

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

// ****** Add denoms ************ /

BOOST_REVERSE_FOREACH(int64_t v, darkSendDenominations){
BOOST_REVERSE_FOREACH(CAmount v, darkSendDenominations){

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

Expand Down Expand Up @@ -1852,7 +1852,7 @@ bool CDarksendPool::IsCompatibleWithEntries(std::vector<CTxOut>& vout)
return true;
}

bool CDarksendPool::IsCompatibleWithSession(int64_t nDenom, CTransaction txCollateral, int& errorID)
bool CDarksendPool::IsCompatibleWithSession(CAmount nDenom, CTransaction txCollateral, int& errorID)
{
if(nDenom == 0) return false;

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

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

// make a list of denominations, with zero uses
BOOST_FOREACH(int64_t d, darkSendDenominations)
BOOST_FOREACH(CAmount d, darkSendDenominations)
denomUsed.push_back(make_pair(d, 0));

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


int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& vecAmount){
int CDarksendPool::GetDenominationsByAmounts(std::vector<CAmount>& vecAmount){
CScript e = CScript();
std::vector<CTxOut> vout1;

// Make outputs by looping through denominations, from small to large
BOOST_REVERSE_FOREACH(int64_t v, vecAmount){
BOOST_REVERSE_FOREACH(CAmount v, vecAmount){
CTxOut o(v, e);
vout1.push_back(o);
}

return GetDenominations(vout1, true);
}

int CDarksendPool::GetDenominationsByAmount(int64_t nAmount, int nDenomTarget){
int CDarksendPool::GetDenominationsByAmount(CAmount nAmount, int nDenomTarget){
CScript e = CScript();
int64_t nValueLeft = nAmount;
CAmount nValueLeft = nAmount;

std::vector<CTxOut> vout1;

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

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

Expand Down
30 changes: 15 additions & 15 deletions src/darksend.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class CActiveMasternode;
#define DARKSEND_RELAY_OUT 2
#define DARKSEND_RELAY_SIG 3

static const int64_t DARKSEND_COLLATERAL = (0.01*COIN);
static const int64_t DARKSEND_POOL_MAX = (999.99*COIN);
static const int64_t DENOMS_COUNT_MAX = 100;
static const CAmount DARKSEND_COLLATERAL = (0.01*COIN);
static const CAmount DARKSEND_POOL_MAX = (999.99*COIN);
static const CAmount DENOMS_COUNT_MAX = 100;

extern CDarksendPool darkSendPool;
extern CDarkSendSigner darkSendSigner;
Expand Down Expand Up @@ -99,7 +99,7 @@ class CDarkSendEntry
bool isSet;
std::vector<CTxDSIn> sev;
std::vector<CTxDSOut> vout;
int64_t amount;
CAmount amount;
CTransaction collateral;
CTransaction txSupporting;
int64_t addedTime; // time in UTC milliseconds
Expand All @@ -112,7 +112,7 @@ class CDarkSendEntry
}

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

Expand Down Expand Up @@ -291,7 +291,7 @@ class CDarksendPool

int64_t lastNewBlock;

std::vector<int64_t> darkSendDenominationsSkipped;
std::vector<CAmount> darkSendDenominationsSkipped;

//debugging data
std::string strAutoDenomResult;
Expand Down Expand Up @@ -369,8 +369,8 @@ class CDarksendPool
darkSendDenominationsSkipped.clear();
}

bool IsDenomSkipped(int64_t denom) {
BOOST_FOREACH(int64_t d, darkSendDenominationsSkipped) {
bool IsDenomSkipped(CAmount denom) {
BOOST_FOREACH(CAmount d, darkSendDenominationsSkipped) {
if (d == denom) {
return true;
}
Expand Down Expand Up @@ -450,7 +450,7 @@ class CDarksendPool
bool IsCompatibleWithEntries(std::vector<CTxOut>& vout);

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

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

Expand All @@ -494,7 +494,7 @@ class CDarksendPool

/// Split up large inputs or make fee sized inputs
bool MakeCollateralAmounts();
bool CreateDenominated(int64_t nTotalValue);
bool CreateDenominated(CAmount nTotalValue);

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

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

std::string GetMessageByID(int messageID);

Expand All @@ -515,7 +515,7 @@ class CDarksendPool
void RelayFinalTransaction(const int sessionID, const CTransaction& txNew);
void RelaySignaturesAnon(std::vector<CTxIn>& vin);
void RelayInAnon(std::vector<CTxIn>& vin, std::vector<CTxOut>& vout);
void RelayIn(const std::vector<CTxDSIn>& vin, const int64_t& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout);
void RelayIn(const std::vector<CTxDSIn>& vin, const CAmount& nAmount, const CTransaction& txCollateral, const std::vector<CTxDSOut>& vout);
void RelayStatus(const int sessionID, const int newState, const int newEntriesCount, const int newAccepted, const int errorID=MSG_NOERR);
void RelayCompletedTransaction(const int sessionID, const bool error, const int errorID);
};
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,14 +1534,14 @@ double ConvertBitsToDouble(unsigned int nBits)
return dDiff;
}

int64_t GetBlockValue(int nBits, int nHeight, const CAmount& nFees)
CAmount GetBlockValue(int nBits, int nHeight, const CAmount& nFees)
{
double dDiff = (double)0x0000ffff / (double)(nBits & 0x00ffffff);

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

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

int64_t GetMasternodePayment(int nHeight, int64_t blockValue)
CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
{
int64_t ret = blockValue/5; // start at 20%
CAmount ret = blockValue/5; // start at 20%

if(Params().NetworkID() == CBaseChainParams::TESTNET) {
if(nHeight > 46000) ret += blockValue / 20; //25% - 2014-10-07
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ bool DisconnectBlocksAndReprocess(int blocks);

// ***TODO***
double ConvertBitsToDouble(unsigned int nBits);
int64_t GetMasternodePayment(int nHeight, int64_t blockValue);
CAmount GetMasternodePayment(int nHeight, CAmount blockValue);
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock);

bool ActivateBestChain(CValidationState &state, CBlock *pblock = NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void DumpMasternodePayments()
LogPrintf("Budget dump finished %dms\n", GetTimeMillis() - nStart);
}

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

Expand Down Expand Up @@ -267,7 +267,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight)
}


void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees)
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if(!pindexPrev) return;
Expand All @@ -288,7 +288,7 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
}
}

void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFees)
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if(!pindexPrev) return;
Expand Down
6 changes: 3 additions & 3 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
bool IsReferenceNode(CTxIn& vin);
bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue);
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees);

void DumpMasternodePayments();

Expand Down Expand Up @@ -268,7 +268,7 @@ class CMasternodePayments
int GetMinMasternodePaymentsProto();
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, int64_t nFees);
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees);
std::string ToString() const;
int GetOldestBlock();
int GetNewestBlock();
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool fSucessfullyLoaded = false;
bool fEnableDarksend = false;
bool fDarksendMultiSession = false;
/** All denominations used by darksend */
std::vector<int64_t> darkSendDenominations;
std::vector<CAmount> darkSendDenominations;
string strBudgetMode = "";

map<string, string> mapArgs;
Expand Down
Loading