Skip to content
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
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
34 changes: 27 additions & 7 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COutput> 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)
Expand All @@ -3530,6 +3538,7 @@ bool CWallet::MultiSend()
{
if(vDisabledAddresses[i] == CBitcoinAddress(address).ToString())
{
LogPrintf("Multisend: disabled address preventing multisend\n");
return false;
}
}
Expand All @@ -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
Expand All @@ -3560,19 +3570,29 @@ 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
CWalletDB walletdb(strWalletFile);
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;
Expand Down