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

use IsDenominatedAmount instead of loops and GetInputDarksendRounds where applicable #139

Merged
merged 1 commit into from
Jan 30, 2015
Merged
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
37 changes: 13 additions & 24 deletions src/darksend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,45 +394,34 @@ int GetInputDarksendRounds(CTxIn in, int rounds)
padding.insert(0, ((rounds+1)*5)+3, ' ');

CWalletTx tx;
if(pwalletMain->GetTransaction(in.prevout.hash,tx)){
if(pwalletMain->GetTransaction(in.prevout.hash,tx))
{
// bounds check
if(in.prevout.n >= tx.vout.size()) return -4;

if(tx.vout[in.prevout.n].nValue == DARKSEND_FEE) return -3;

if(rounds == 0){ //make sure the final output is non-denominate
bool found = false;
BOOST_FOREACH(int64_t d, darkSendDenominations)
if(tx.vout[in.prevout.n].nValue == d) found = true;
//make sure the final output is non-denominate
if(rounds == 0 && !pwalletMain->IsDenominatedAmount(tx.vout[in.prevout.n].nValue)) return -2; //NOT DENOM

if(!found) {
//LogPrintf(" - NOT DENOM\n");
return -2;
}
}
bool found = false;

BOOST_FOREACH(CTxOut out, tx.vout){
BOOST_FOREACH(int64_t d, darkSendDenominations)
if(out.nValue == d)
found = true;
}

if(!found) {
//LogPrintf(" - NOT FOUND\n");
return rounds - 1; // -1 because of the pre-mixing creation of denominated amounts
BOOST_FOREACH(CTxOut out, tx.vout)
{
found = pwalletMain->IsDenominatedAmount(out.nValue);
if(found) break; // no need to loop more
}
if(!found) return rounds - 1; //NOT FOUND, "-1" because of the pre-mixing creation of denominated amounts

// find my vin and look that up
BOOST_FOREACH(CTxIn in2, tx.vin) {
if(pwalletMain->IsMine(in2)){
BOOST_FOREACH(CTxIn in2, tx.vin)
{
if(pwalletMain->IsMine(in2))
{
//LogPrintf("rounds :: %s %s %d NEXT\n", padding.c_str(), in.ToString().c_str(), rounds);
int n = GetInputDarksendRounds(in2, rounds+1);
if(n != -3) return n;
}
}
} else {
//LogPrintf("rounds :: %s %s %d NOTFOUND\n", padding.c_str(), in.ToString().c_str(), rounds);
}

return rounds-1;
Expand Down
6 changes: 2 additions & 4 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{
const CTxOut& txout = wtx.vout[nOut];

BOOST_FOREACH(int64_t d, darkSendDenominations)
if(txout.nValue == d)
isDarksent = true;
isDarksent = wallet->IsDenominatedAmount(txout.nValue);
if(isDarksent) break; // no need to loop more
}

parts.append(TransactionRecord(hash, nTime, isDarksent ? TransactionRecord::DarksendDenominate : TransactionRecord::Other, "", nNet, 0));
Expand Down
34 changes: 7 additions & 27 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,24 +747,18 @@ int64_t CWallet::GetDebit(const CTxIn &txin) const
return 0;
}

int64_t CWallet::IsDenominated(const CTxIn &txin) const
bool CWallet::IsDenominated(const CTxIn &txin) const
{
{
LOCK(cs_wallet);
map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
{
const CWalletTx& prev = (*mi).second;
if (txin.prevout.n < prev.vout.size()){
BOOST_FOREACH(int64_t d, darkSendDenominations){
if(prev.vout[txin.prevout.n].nValue == d) {
return true;
}
}
}
if (txin.prevout.n < prev.vout.size()) return IsDenominatedAmount(prev.vout[txin.prevout.n].nValue);
}
}
return 0;
return false;
}

bool CWallet::IsDenominatedAmount(int64_t nInputAmount) const
Expand Down Expand Up @@ -1193,9 +1187,7 @@ int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) con
if(IsSpent(out.tx->GetHash(), i)) continue;
if(!IsMine(pcoin->vout[i])) continue;
if(onlyUnconfirmed != unconfirmed) continue;

int rounds = GetInputDarksendRounds(vin);
if(onlyDenom != (rounds>=0)) continue;
if(onlyDenom != IsDenominatedAmount(pcoin->vout[i].nValue)) continue;

nTotal += pcoin->vout[i].nValue;
}
Expand Down Expand Up @@ -1266,16 +1258,11 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
if(coin_type == ONLY_DENOMINATED) {
//should make this a vector

COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain());
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
int rounds = GetInputDarksendRounds(vin);
if(rounds >= 0) found = true;
found = IsDenominatedAmount(pcoin->vout[i].nValue);
} else if(coin_type == ONLY_NONDENOMINATED || coin_type == ONLY_NONDENOMINATED_NOTMN) {
found = true;
if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts
BOOST_FOREACH(int64_t d, darkSendDenominations)
if(pcoin->vout[i].nValue == d)
found = false;
found = !IsDenominatedAmount(pcoin->vout[i].nValue);
if(found && coin_type == ONLY_NONDENOMINATED_NOTMN) found = (pcoin->vout[i].nValue != 1000*COIN); // do not use MN funds
} else {
found = true;
Expand Down Expand Up @@ -1392,14 +1379,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
int i = output.i;
int64_t n = pcoin->vout[i].nValue;

if (tryDenom == 0) // first run?
{
bool found = false;
BOOST_FOREACH(int64_t d, darkSendDenominations) // loop through predefined denoms
if(n == d)
found = true;
if (found) continue; // we don't want denom values on first run
}
if (tryDenom == 0 && IsDenominatedAmount(n)) continue; // we don't want denom values on first run

pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));

Expand Down
4 changes: 2 additions & 2 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ class CWallet : public CCryptoKeyStore, public CWalletInterface

std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;

int64_t IsDenominated(const CTxIn &txin) const;
bool IsDenominated(const CTxIn &txin) const;

int64_t IsDenominated(const CTransaction& tx) const
bool IsDenominated(const CTransaction& tx) const
{
/*
Return false if ANY inputs are non-denom
Expand Down