Skip to content

Commit

Permalink
Merge pull request #500 from UdjinM6/v0.12.0.x_DS_single_random_denom
Browse files Browse the repository at this point in the history
V0.12.0.x Use single random denom in new DS session
  • Loading branch information
evan82 committed Aug 10, 2015
2 parents 0f42887 + 4046900 commit 0297da6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,9 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun, bool ready)

std::vector<CAmount> vecAmounts;
pwalletMain->ConvertList(vCoins, vecAmounts);
// try to get random denoms out of vecAmounts
// try to get a single random denom out of vecAmounts
while(sessionDenom == 0)
sessionDenom = GetDenominationsByAmounts(vecAmounts, true);
sessionDenom = GetDenominationsByAmounts(vecAmounts);

pnode->PushMessage("dsa", sessionDenom, txCollateral);
LogPrintf("DoAutomaticDenominating --- connected, sending dsa for %d\n", sessionDenom);
Expand Down Expand Up @@ -1914,7 +1914,7 @@ 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 fRandDenom){
int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom){
std::vector<pair<int64_t, int> > denomUsed;

// make a list of denominations, with zero uses
Expand All @@ -1937,8 +1937,11 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fRandD
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)
denom |= ((fRandDenom ? rand()%2 : 1) * s.second) << c++;
BOOST_FOREACH (PAIRTYPE(int64_t, int)& s, denomUsed) {
int bit = (fSingleRandomDenom ? rand()%2 : 1) * s.second;
denom |= bit << c++;
if(fSingleRandomDenom && bit) break; // use just one random denomination
}

// Function returns as follows:
//
Expand All @@ -1951,20 +1954,17 @@ int CDarksendPool::GetDenominations(const std::vector<CTxOut>& vout, bool fRandD
}


int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& vecAmount, bool fRandDenom){
int CDarksendPool::GetDenominationsByAmounts(std::vector<int64_t>& 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){
int nOutputs = 0;

CTxOut o(v, e);
vout1.push_back(o);
nOutputs++;
}

return GetDenominations(vout1, fRandDenom);
return GetDenominations(vout1, true);
}

int CDarksendPool::GetDenominationsByAmount(int64_t nAmount, int nDenomTarget){
Expand Down
4 changes: 2 additions & 2 deletions src/darksend.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ class CDarksendPool
bool CreateDenominated(int64_t nTotalValue);

/// Get the denominations for a list of outputs (returns a bitshifted integer)
int GetDenominations(const std::vector<CTxOut>& vout, bool fRandDenom = false);
int GetDenominations(const std::vector<CTxOut>& vout, bool fSingleRandomDenom = false);
int GetDenominations(const std::vector<CTxDSOut>& vout);

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, bool fRandDenom = false);
int GetDenominationsByAmounts(std::vector<int64_t>& vecAmount);

std::string GetMessageByID(int messageID);

Expand Down

0 comments on commit 0297da6

Please sign in to comment.