diff --git a/src/main.cpp b/src/main.cpp index 2427b15945..0d395662f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6977,13 +6977,13 @@ void CDarkSendPool::DoAutomaticDenominating() int64 nValueMax = 999*COIN; int64 nValueIn = 0; - if (!pwalletMain->SelectCoinsDark(nValueMin, nValueMax, vCoins, nValueIn, 0, nDarksendRounds)) + if (!pwalletMain->SelectCoinsDark(nValueMin, nValueMax, vCoins, nValueIn, -2, nDarksendRounds)) { nValueIn = 0; vCoins.clear(); //simply look for non-denominated coins - if (pwalletMain->SelectCoinsDark(nValueMax+1, 9999999*COIN, vCoins, nValueIn, 0, nDarksendRounds)) + if (pwalletMain->SelectCoinsDark(nValueMax+1, 9999999*COIN, vCoins, nValueIn, -2, nDarksendRounds)) { SplitUpMoney(); return; @@ -6993,6 +6993,11 @@ void CDarkSendPool::DoAutomaticDenominating() return; } + if(nValueIn < COIN*1.1){ + printf("DoAutomaticDenominating : Too little to denominate (must have 1.1DRK) \n"); + return; + } + int64 amount = pwalletMain->GetBalance(); if(amount > 999*COIN) amount = (999*COIN); @@ -7044,7 +7049,8 @@ bool CDarkSendPool::SplitUpMoney() nTotalOut += (nTotalBalance/5) + (nTotalBalance/5/5) + (POOL_FEE_AMOUNT*4); } - bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRet, strFail); + CCoinControl *coinControl=NULL; + bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRet, strFail, coinControl, ONLY_NONDENOMINATED); if(!success){ printf("SplitUpMoney: Error - %s\n", strFail.c_str()); return false; @@ -7138,7 +7144,7 @@ bool CDarkSendPool::GetCurrentMasterNodeConsessus(int64 blockHeight, CScript& pa // recursively find how many transactions deep the darksending goes int CDarkSendPool::GetInputDarksendRounds(CTxIn in, int rounds) { - if(rounds >= 8) return rounds; + if(rounds >= 9) return rounds; std::string padding = ""; padding.insert(0, ((rounds+1)*5)+3, ' '); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 4ec061d7eb..c15dfc0f4b 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -197,9 +197,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QListCreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); + + CCoinControl *coinControl=NULL; + AvailableCoinsType act = ONLY_DENOMINATED; + + bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason, coinControl, act); if (!fCreated) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); if (!pwalletMain->CommitTransaction(wtx, keyChange)) diff --git a/src/wallet.cpp b/src/wallet.cpp index 8ec3a737a3..9236060c30 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1236,7 +1236,7 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vector vCoins; - AvailableCoins(vCoins, false, coinControl); + AvailableCoins(vCoins, false, coinControl, ALL_COINS); printf("found coins %d\n", (int)vCoins.size()); @@ -1248,21 +1248,58 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vectorvout[out.i].nValue <= nValueMax){ CTxIn vin = CTxIn(out.tx->GetHash(),out.i); + printf(" vin nValue %"PRI64d"\n", out.tx->vout[out.i].nValue); int rounds = darkSendPool.GetInputDarksendRounds(vin); - if(rounds < 0) rounds = 0; - if(rounds < nDarksendRoundsMin && rounds >= nDarksendRoundsMax) continue; + + printf(" -- rounds %d\n", rounds); + if(rounds >= nDarksendRoundsMax) continue; + printf(" -- rounds continue\n"); + + if(rounds < nDarksendRoundsMin) continue; vin.prevPubKey = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey - printf(" vin nValue %"PRI64d"\n", out.tx->vout[out.i].nValue); nValueRet += out.tx->vout[out.i].nValue; setCoinsRet.push_back(vin); setCoinsRet2.insert(make_pair(out.tx, out.i)); printf(" -- nValueRet %"PRI64d"\n", nValueRet); - if(nValueRet >= nValueMin) return true; + if(nValueRet >= nValueMax) return true; } } + if(nValueRet >= nValueMin) return true; + + return false; +} + +bool CWallet::SelectCoinsCollateral(int64 nValueMin, int64 nValueMax, std::vector& setCoinsRet, int64& nValueRet) const +{ + CCoinControl *coinControl=NULL; + + vector vCoins; + AvailableCoins(vCoins, false, coinControl, ALL_COINS); + + printf("found coins %d\n", (int)vCoins.size()); + + set > setCoinsRet2; + + BOOST_FOREACH(const COutput& out, vCoins) + { + if(nValueRet + out.tx->vout[out.i].nValue <= nValueMax){ + CTxIn vin = CTxIn(out.tx->GetHash(),out.i); + printf(" vin nValue %"PRI64d"\n", out.tx->vout[out.i].nValue); + + vin.prevPubKey = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey + nValueRet += out.tx->vout[out.i].nValue; + setCoinsRet.push_back(vin); + setCoinsRet2.insert(make_pair(out.tx, out.i)); + printf(" -- nValueRet %"PRI64d"\n", nValueRet); + if(nValueRet >= nValueMax) return true; + } + } + + if(nValueRet >= nValueMin) return true; + return false; } @@ -1615,7 +1652,7 @@ string CWallet::DarkSendDenominate(int64 nValue) int64 nValueIn = 0; //try to use denominated funds (for added anonymity) - if (!SelectCoinsDark(nTotalValue, 1000*COIN, vCoins, nValueIn, 0, nDarksendRounds)) + if (!SelectCoinsDark(0, nTotalValue, vCoins, nValueIn, -2, nDarksendRounds)) { vCoins.clear(); return _("Insufficient funds 2"); @@ -1648,12 +1685,12 @@ string CWallet::DarkSendDenominate(int64 nValue) int64 nValueIn2 = 0; std::vector vCoinsCollateral; - if (!SelectCoinsDark(POOL_FEE_AMOUNT+(0.01*COIN), 99999*COIN, vCoinsCollateral, nValueIn2, 0, nDarksendRounds)) + if (!SelectCoinsCollateral(POOL_FEE_AMOUNT, POOL_FEE_AMOUNT*6, vCoinsCollateral, nValueIn2)) { BOOST_FOREACH(CTxIn v, vCoins) UnlockCoin(v.prevout); - return _("Error: The DarkSend requires a collateral transaction and could not locate the input!"); + return _("Error: Darksend requires a collateral transaction and could not locate an acceptable input!"); } // make our change address diff --git a/src/wallet.h b/src/wallet.h index b409817b71..c574e0b37b 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -91,6 +91,7 @@ public: bool SelectCoinsDarkDenominated(int64 nTargetValue, std::vector& setCoinsRet, int64& nValueRet) const; bool SelectCoinsExactOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, CScript& pubScript, bool confirmed) const; + bool SelectCoinsCollateral(int64 nValueMin, int64 nValueMax, std::vector& setCoinsRet, int64& nValueRet) const; bool SelectCoinsWithoutDenomination(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet) const; bool SelectCoinsMoreThanOutput(int64 nTargetValue, CTxIn& vin, int64& nValueRet, bool confirmed) const;