Merge pull request #139 from UdjinM6/fix_more_usage_of_IsDenominatedAmount
use IsDenominatedAmount instead of loops and GetInputDarksendRounds where applicable
This commit is contained in:
commit
2158023d4c
@ -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
|
||||
//make sure the final output is non-denominate
|
||||
if(rounds == 0 && !pwalletMain->IsDenominatedAmount(tx.vout[in.prevout.n].nValue)) return -2; //NOT DENOM
|
||||
|
||||
bool found = false;
|
||||
BOOST_FOREACH(int64_t d, darkSendDenominations)
|
||||
if(tx.vout[in.prevout.n].nValue == d) found = true;
|
||||
|
||||
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;
|
||||
|
@ -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));
|
||||
|
@ -747,7 +747,7 @@ 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);
|
||||
@ -755,16 +755,10 @@ int64_t CWallet::IsDenominated(const CTxIn &txin) const
|
||||
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
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
@ -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));
|
||||
|
||||
|
@ -309,9 +309,9 @@ public:
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user