From 85f23009205ad153f4d3e8d3fa15768561422c7f Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sun, 27 Jul 2014 06:36:59 -0700 Subject: [PATCH] many various fixes --- src/main.cpp | 29 ++++++++++++++++++----------- src/wallet.cpp | 12 ++++++++---- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8029f1a30c..44da9f55f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6086,6 +6086,7 @@ void CDarkSendPool::Check() if((state == POOL_STATUS_TRANSMISSION && fMasterNode) || (state == POOL_STATUS_SIGNING && completedTransaction) ) { printf("CDarkSendPool::Check() -- COMPLETED -- RESETTING \n"); SetNull(); + UnlockCoins(); if(fMasterNode) RelayDarkSendStatus(darkSendPool.GetState(), darkSendPool.GetEntriesCount(), -1); pwalletMain->Lock(); } @@ -6093,6 +6094,7 @@ void CDarkSendPool::Check() if((state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) && GetTimeMillis()-lastTimeChanged >= 10000) { printf("CDarkSendPool::Check() -- RESETTING MESSAGE \n"); SetNull(); + UnlockCoins(); } } @@ -6218,6 +6220,7 @@ bool CDarkSendPool::AddEntry(const std::vector& newInput, const int64& nA if(entries.size() >= POOL_MAX_TRANSACTIONS){ if(fDebug) printf ("CDarkSendPool::AddEntry - entries is full!\n"); error = "entries is full"; + SetNull(); // not sure how this happens. Just reset for now. return false; } @@ -6801,8 +6804,7 @@ void CDarkSendPool::NewBlock() RelayDarkSendStatus(darkSendPool.GetState(), darkSendPool.GetEntriesCount(), -1); } } else { - - if(myEntries.size() != 0) { + if(pindexBest->nHeight % 10 == 0 && myEntries.size() != 0) { bool run = true; uint256 n1 = 0; @@ -6980,6 +6982,8 @@ void CDarkSendPool::DoAutomaticDenominating() nValueIn = 0; vCoins.clear(); + printf("failed\n"); + //simply look for non-denominated coins if (pwalletMain->SelectCoinsDark(nValueMax+1, 9999999*COIN, vCoins, nValueIn, 0, nDarksendRounds)) { @@ -6994,15 +6998,16 @@ void CDarkSendPool::DoAutomaticDenominating() int64 amount = pwalletMain->GetBalance(); if(amount > 999*COIN) amount = (999*COIN); - amount -= (rand() % (amount/10)); + amount -= amount/10; amount = roundUp64(amount, COIN/100); + std::string strError = pwalletMain->DarkSendDenominate(amount); - printf("DoAutomaticDenominating : Running darksend denominate for %"PRI64d" coins.\n", nValueIn/COIN); + printf("DoAutomaticDenominating : Running darksend denominate for %"PRI64d" coins. Return '%s'\n", nValueIn, strError.c_str()); if(strError == "") return; - if(strError == "Error: The DarkSend requires a collateral transaction and could not locate the input!") { + if(strError == "Error: The DarkSend requires a collateral transaction and could not locate the input!" || strError == "Insufficient funds 2") { SplitUpMoney(); } else { printf("DoAutomaticDenominating : Error running denominate, %s\n", strError.c_str()); @@ -7019,6 +7024,7 @@ bool CDarkSendPool::SplitUpMoney() // make our change address CReserveKey reservekey(pwalletMain); + CScript scriptChange; CPubKey vchPubKey; assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked @@ -7029,14 +7035,15 @@ bool CDarkSendPool::SplitUpMoney() std::string strFail = ""; vector< pair > vecSend; - while(nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN) < nTotalBalance-(0.002*COIN)){ - //printf(" nTotalOut %"PRI64d"\n", nTotalOut); - //printf(" nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN) %"PRI64d"\n", nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN)); - //printf(" nTotalBalance-(0.002*COIN) %"PRI64d"\n", nTotalBalance-(0.002*COIN)); + int64 FEE = 0.002*COIN; + while(nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + (POOL_FEE_AMOUNT*4)) < nTotalBalance-(FEE)){ + printf(" nTotalOut %"PRI64d"\n", nTotalOut); + printf(" nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN) %"PRI64d"\n", nTotalOut + ((nTotalBalance/5) + (nTotalBalance/5/5) + ((POOL_FEE_AMOUNT*4)))); + printf(" nTotalBalance-(FEE) %"PRI64d"\n", nTotalBalance-(FEE)); vecSend.push_back(make_pair(scriptChange, nTotalBalance/5)); vecSend.push_back(make_pair(scriptChange, nTotalBalance/5/5)); - vecSend.push_back(make_pair(scriptChange, 0.01*COIN)); - nTotalOut += (nTotalBalance/5) + (nTotalBalance/5/5) + 0.01*COIN; + vecSend.push_back(make_pair(scriptChange, POOL_FEE_AMOUNT*4)); + nTotalOut += (nTotalBalance/5) + (nTotalBalance/5/5) + (POOL_FEE_AMOUNT*4); } bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRet, strFail); diff --git a/src/wallet.cpp b/src/wallet.cpp index a3938d9044..d4dd58f15d 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -988,9 +988,12 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const bool found = false; if(onlyDarksendInputs) { //should make this a vector - BOOST_FOREACH(int64 d, darkSendDenominations) - if(pcoin->vout[i].nValue == d) - found = true; + + COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain()); + CTxIn vin = CTxIn(out.tx->GetHash(), out.i); + int rounds = darkSendPool.GetInputDarksendRounds(vin); + if(rounds >= nDarksendRounds) found = true; + } else { found = true; } @@ -1226,7 +1229,6 @@ bool CWallet::SelectCoins(int64 nTargetValue, set& setCoinsRet, int64& nValueRet, int nDarksendRoundsMin, int nDarksendRoundsMax) const { CCoinControl *coinControl=NULL; - int64 nTargetValue = 0; vector vCoins; AvailableCoins(vCoins, false, coinControl); @@ -1237,6 +1239,7 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vectorvout[out.i].nValue == POOL_FEE_AMOUNT*4) continue; //these are made for collateral if(nValueRet + out.tx->vout[out.i].nValue <= nValueMax){ CTxIn vin = CTxIn(out.tx->GetHash(),out.i); @@ -1250,6 +1253,7 @@ bool CWallet::SelectCoinsDark(int64 nValueMin, int64 nValueMax, std::vectorvout[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; } }