From 866ff335c4d1ec8fafc5b4674b611eaf8f81ae14 Mon Sep 17 00:00:00 2001 From: presstab Date: Sun, 5 Feb 2017 11:23:30 -0700 Subject: [PATCH] fix multisend bugs preventing proper iteration --- src/main.cpp | 3 +-- src/wallet.cpp | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 267c9efd3bb0..ba275e94aa56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3889,8 +3889,7 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis // If turned on MultiSend will send a transaction (or more) on the 30th confirmation of a stake if (pwalletMain->fMultiSend) - if (!pwalletMain->MultiSend() ) - LogPrintf("ERROR While trying to use MultiSend \n"); + pwalletMain->MultiSend(); LogPrintf("%s : ACCEPTED\n", __func__); diff --git a/src/wallet.cpp b/src/wallet.cpp index da31248c8a3a..c23669728cda 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -3504,24 +3504,32 @@ bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, st bool CWallet::MultiSend() { if ( IsInitialBlockDownload() || IsLocked() ) + { + LogPrintf("Multisend: islocked or initial download\n"); return false; + } + + if (chainActive.Tip()->nHeight <= nLastMultiSendHeight) + { + LogPrintf("Multisend: lastmultisendheight is higher than current best height\n"); + return false; + } - int64_t nAmount = 0; { LOCK(cs_wallet); std::vector vCoins; AvailableCoins(vCoins); BOOST_FOREACH(const COutput& out, vCoins) { + if (!(out.tx->IsCoinStake() && out.tx->GetBlocksToMaturity() == 0 && out.tx->GetDepthInMainChain() == COINBASE_MATURITY + 1)) + continue; + CTxDestination address; if(!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + { + LogPrintf("Multisend: failed to extract destination\n"); continue; - - if (chainActive.Tip()->nHeight <= nLastMultiSendHeight ) - return false; - - if (!(out.tx->IsCoinStake() && out.tx->GetBlocksToMaturity() == 0 && out.tx->GetDepthInMainChain() == COINBASE_MATURITY + 1)) - return false; + } //Disabled Addresses won't send MultiSend transactions if(vDisabledAddresses.size() > 0) @@ -3530,6 +3538,7 @@ bool CWallet::MultiSend() { if(vDisabledAddresses[i] == CBitcoinAddress(address).ToString()) { + LogPrintf("Multisend: disabled address preventing multisend\n"); return false; } } @@ -3547,6 +3556,7 @@ bool CWallet::MultiSend() // loop through multisend vector and add amounts and addresses to the sending vector const isminefilter filter = ISMINE_SPENDABLE; + int64_t nAmount = 0; for(unsigned int i = 0; i < vMultiSend.size(); i++) { // MultiSend vector is a pair of 1)Address as a std::string 2) Percent of stake to send as an int @@ -3560,12 +3570,19 @@ bool CWallet::MultiSend() // Create the transaction and commit it to the network string strErr; if (!CreateTransaction(vecSend, wtx, keyChange, nFeeRet, strErr, cControl, ALL_COINS, false, CAmount(0))) + { LogPrintf("MultiSend createtransaction failed\n"); + return false; + } if(!CommitTransaction(wtx, keyChange)) + { LogPrintf("MultiSend transaction commit failed\n"); + return false; + } else fMultiSendNotify = true; + delete cControl; //write nLastMultiSendHeight to DB @@ -3573,6 +3590,9 @@ bool CWallet::MultiSend() nLastMultiSendHeight = chainActive.Tip()->nHeight; if(!walletdb.WriteMSettings(fMultiSend, nLastMultiSendHeight)) LogPrintf("Failed to write MultiSend setting to DB\n"); + + LogPrintf("MultiSend successfully sent\n"); + return true; } } return true;