From e2aaf097007946e996f84e8d067a120b20f42d3c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 24 Jan 2016 22:05:31 +0300 Subject: [PATCH] Cleanup - lower unobvious dependency through header files, move few includes to the right places - some trivial code cleanup Closes #680 --- src/activemasternode.cpp | 3 ++- src/darksend.cpp | 46 ++---------------------------------- src/darksend.h | 25 ++++++++++++++++---- src/init.cpp | 19 +-------------- src/instantx.cpp | 5 ++-- src/main.cpp | 7 +++--- src/masternode-budget.h | 2 +- src/masternode-payments.cpp | 2 +- src/masternode.cpp | 6 +++-- src/masternodeconfig.cpp | 5 +++- src/masternodeconfig.h | 6 ----- src/masternodeman.cpp | 6 +++-- src/qt/bitcoingui.cpp | 1 + src/qt/overviewpage.cpp | 1 + src/rpcmasternode-budget.cpp | 5 ++-- src/rpcmasternode.cpp | 5 ++-- src/rpcmining.cpp | 4 +--- 17 files changed, 56 insertions(+), 92 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 49e3b6917d..795f58e29f 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -2,9 +2,10 @@ #include "addrman.h" #include "protocol.h" #include "activemasternode.h" -#include "masternodeman.h" #include "masternode.h" +#include "masternode-sync.h" #include "masternodeconfig.h" +#include "masternodeman.h" #include "spork.h" // diff --git a/src/darksend.cpp b/src/darksend.cpp index d1af6b380c..95c1d2c020 100644 --- a/src/darksend.cpp +++ b/src/darksend.cpp @@ -6,6 +6,8 @@ #include "main.h" #include "init.h" #include "util.h" +#include "masternode-payments.h" +#include "masternode-sync.h" #include "masternodeman.h" #include "script/sign.h" #include "instantx.h" @@ -1650,43 +1652,6 @@ bool CDarksendPool::PrepareDarksendDenominate() return false; } -bool CDarksendPool::SendRandomPaymentToSelf() -{ - CAmount nBalance = pwalletMain->GetBalance(); - CAmount nPayment = (nBalance*0.35) + (rand() % nBalance); - - if(nPayment > nBalance) nPayment = nBalance-(0.1*COIN); - - // make our change address - CReserveKey reservekey(pwalletMain); - - CScript scriptChange; - CPubKey vchPubKey; - assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked - scriptChange = GetScriptForDestination(vchPubKey.GetID()); - - CWalletTx wtx; - CAmount nFeeRet = 0; - std::string strFail = ""; - vector< pair > vecSend; - - // ****** Add fees ************ / - vecSend.push_back(make_pair(scriptChange, nPayment)); - - CCoinControl *coinControl=NULL; - bool success = pwalletMain->CreateTransaction(vecSend, wtx, reservekey, nFeeRet, strFail, coinControl, ONLY_DENOMINATED); - if(!success){ - LogPrintf("SendRandomPaymentToSelf: Error - %s\n", strFail); - return false; - } - - pwalletMain->CommitTransaction(wtx, reservekey); - - LogPrintf("SendRandomPaymentToSelf Success: tx %s\n", wtx.GetHash().GetHex()); - - return true; -} - // Split up large inputs or create fee sized inputs bool CDarksendPool::MakeCollateralAmounts() { @@ -1839,13 +1804,6 @@ bool CDarksendPool::IsCompatibleWithEntries(std::vector& vout) BOOST_FOREACH(const CDarkSendEntry v, entries) { LogPrintf(" IsCompatibleWithEntries %d %d\n", GetDenominations(vout), GetDenominations(v.vout)); -/* - BOOST_FOREACH(CTxOut o1, vout) - LogPrintf(" vout 1 - %s\n", o1.ToString()); - - BOOST_FOREACH(CTxOut o2, v.vout) - LogPrintf(" vout 2 - %s\n", o2.ToString()); -*/ if(GetDenominations(vout) != GetDenominations(v.vout)) return false; } diff --git a/src/darksend.h b/src/darksend.h index eb1640d82e..cb2eee2361 100644 --- a/src/darksend.h +++ b/src/darksend.h @@ -9,9 +9,7 @@ #include "sync.h" #include "activemasternode.h" #include "masternodeman.h" -#include "masternode-payments.h" #include "darksend-relay.h" -#include "masternode-sync.h" class CTxIn; class CDarksendPool; @@ -378,6 +376,27 @@ public: return false; } + void InitDenominations() { + darkSendDenominations.clear(); + /* Denominations + + A note about convertability. Within Darksend pools, each denomination + is convertable to another. + + For example: + 1DRK+1000 == (.1DRK+100)*10 + 10DRK+10000 == (1DRK+1000)*10 + */ + darkSendDenominations.push_back( (100 * COIN)+100000 ); + darkSendDenominations.push_back( (10 * COIN)+10000 ); + darkSendDenominations.push_back( (1 * COIN)+1000 ); + darkSendDenominations.push_back( (.1 * COIN)+100 ); + /* Disabled till we need them + darkSendDenominations.push_back( (.01 * COIN)+10 ); + darkSendDenominations.push_back( (.001 * COIN)+1 ); + */ + } + void SetMinBlockSpacing(int minBlockSpacingIn){ minBlockSpacing = minBlockSpacingIn; } @@ -489,8 +508,6 @@ public: void NewBlock(); void CompletedTransaction(bool error, int errorID); void ClearLastMessage(); - /// Used for liquidity providers - bool SendRandomPaymentToSelf(); /// Split up large inputs or make fee sized inputs bool MakeCollateralAmounts(); diff --git a/src/init.cpp b/src/init.cpp index 4bda251e30..1e48f8d3ab 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1564,24 +1564,7 @@ bool AppInit2(boost::thread_group& threadGroup) LogPrintf("Anonymize Dash Amount %d\n", nAnonymizeDarkcoinAmount); LogPrintf("Budget Mode %s\n", strBudgetMode.c_str()); - /* Denominations - - A note about convertability. Within Darksend pools, each denomination - is convertable to another. - - For example: - 1DRK+1000 == (.1DRK+100)*10 - 10DRK+10000 == (1DRK+1000)*10 - */ - darkSendDenominations.push_back( (100 * COIN)+100000 ); - darkSendDenominations.push_back( (10 * COIN)+10000 ); - darkSendDenominations.push_back( (1 * COIN)+1000 ); - darkSendDenominations.push_back( (.1 * COIN)+100 ); - /* Disabled till we need them - darkSendDenominations.push_back( (.01 * COIN)+10 ); - darkSendDenominations.push_back( (.001 * COIN)+1 ); - */ - + darkSendPool.InitDenominations(); darkSendPool.InitCollateralAddress(); threadGroup.create_thread(boost::bind(&ThreadCheckDarkSendPool)); diff --git a/src/instantx.cpp b/src/instantx.cpp index 60527bf129..58ee901b92 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -9,8 +9,9 @@ #include "protocol.h" #include "instantx.h" #include "activemasternode.h" -#include "masternodeman.h" #include "darksend.h" +#include "masternode-sync.h" +#include "masternodeman.h" #include "spork.h" #include @@ -206,7 +207,7 @@ bool IsIXTXValid(const CTransaction& txCollateral){ return true; } - if(nValueIn-nValueOut < COIN*0.01) { + if(nValueIn-nValueOut < CENT) { LogPrint("instantx", "IsIXTXValid - did not include enough fees in transaction %d\n%s\n", nValueOut-nValueIn, txCollateral.ToString().c_str()); return false; } diff --git a/src/main.cpp b/src/main.cpp index 9b4dbe84fd..9ee1341c5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,9 +14,10 @@ #include "init.h" #include "instantx.h" #include "darksend.h" -#include "masternodeman.h" -#include "masternode-payments.h" #include "masternode-budget.h" +#include "masternode-payments.h" +#include "masternode-sync.h" +#include "masternodeman.h" #include "merkleblock.h" #include "net.h" #include "pow.h" @@ -1578,7 +1579,7 @@ CAmount GetBlockValue(int nBits, int nHeight, const CAmount& nFees) if(Params().NetworkID() == CBaseChainParams::TESTNET){ if(nHeight > 77900+576) nSubsidy -= nSubsidy/10; } else { - if(nHeight > 309759+(553*33)) nSubsidy -= nSubsidy/10; // 328008 - 10.0% - September 6, 2015 + if(nHeight > 309759+(553*33)) nSubsidy -= nSubsidy/10; // 328008 - 10.0% - 2015-08-30 } return nSubsidy + nFees; diff --git a/src/masternode-budget.h b/src/masternode-budget.h index 132238d5c6..47ceb56114 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -426,7 +426,7 @@ public: //Proposals must be at least a day old to make it into a budget if(Params().NetworkID() == CBaseChainParams::MAIN) return (nTime < GetTime() - (60*60*24)); - //for testing purposes - 4 hours + //for testing purposes - 20 minutes return (nTime < GetTime() - (60*20)); } diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index c498db9afa..2b7c3a4b10 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -299,7 +299,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, CAmount nFe //spork if(!masternodePayments.GetBlockPayee(pindexPrev->nHeight+1, payee)){ //no masternode detected - CMasternode* winningNode = mnodeman.GetCurrentMasterNode(1); + CMasternode* winningNode = mnodeman.GetCurrentMasterNode(); if(winningNode){ payee = GetScriptForDestination(winningNode->pubkey.GetID()); } else { diff --git a/src/masternode.cpp b/src/masternode.cpp index c7bd925ecd..8ecc04a4db 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -2,9 +2,11 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "masternode.h" -#include "masternodeman.h" #include "darksend.h" +#include "masternode.h" +#include "masternode-payments.h" +#include "masternode-sync.h" +#include "masternodeman.h" #include "util.h" #include "sync.h" #include "addrman.h" diff --git a/src/masternodeconfig.cpp b/src/masternodeconfig.cpp index 6e5b732fe4..fb180cc7cf 100644 --- a/src/masternodeconfig.cpp +++ b/src/masternodeconfig.cpp @@ -3,7 +3,10 @@ #include "masternodeconfig.h" #include "util.h" #include "ui_interface.h" -#include +#include "chainparams.h" + +#include +#include CMasternodeConfig masternodeConfig; diff --git a/src/masternodeconfig.h b/src/masternodeconfig.h index 59e7012c30..b399615b3e 100644 --- a/src/masternodeconfig.h +++ b/src/masternodeconfig.h @@ -6,12 +6,6 @@ #ifndef SRC_MASTERNODECONFIG_H_ #define SRC_MASTERNODECONFIG_H_ -#include -#include - -#include -#include - class CMasternodeConfig; extern CMasternodeConfig masternodeConfig; diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 36b4f145ef..736e5e0567 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -3,9 +3,11 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "masternodeman.h" -#include "masternode.h" #include "activemasternode.h" #include "darksend.h" +#include "masternode.h" +#include "masternode-payments.h" +#include "masternode-sync.h" #include "util.h" #include "addrman.h" #include "spork.h" @@ -454,7 +456,7 @@ CMasternode* CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight mn.Check(); if(!mn.IsEnabled()) continue; - // //check protocol version + //check protocol version if(mn.protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) continue; //it's in the list (up to 8 entries ahead of current block to allow propagation) -- so let's skip it diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 489f9f52b5..fc13064c5d 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -29,6 +29,7 @@ #include "init.h" #include "ui_interface.h" #include "util.h" +#include "masternode-sync.h" #include diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index e5d19950a6..d5d5153bed 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -17,6 +17,7 @@ #include "transactiontablemodel.h" #include "walletmodel.h" #include "init.h" +#include "masternode-sync.h" #include #include diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index c1ce56bc92..709c312d63 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -6,10 +6,11 @@ #include "db.h" #include "init.h" #include "activemasternode.h" -#include "masternodeman.h" -#include "masternode-payments.h" #include "masternode-budget.h" +#include "masternode-payments.h" +#include "masternode-sync.h" #include "masternodeconfig.h" +#include "masternodeman.h" #include "rpcserver.h" #include "utilmoneystr.h" #include diff --git a/src/rpcmasternode.cpp b/src/rpcmasternode.cpp index e139c1fbdb..cbc067212a 100644 --- a/src/rpcmasternode.cpp +++ b/src/rpcmasternode.cpp @@ -7,10 +7,11 @@ #include "db.h" #include "init.h" #include "activemasternode.h" -#include "masternodeman.h" -#include "masternode-payments.h" #include "masternode-budget.h" +#include "masternode-payments.h" +#include "masternode-sync.h" #include "masternodeconfig.h" +#include "masternodeman.h" #include "rpcserver.h" #include "utilmoneystr.h" diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 4f42e7e534..905485edb6 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -19,6 +19,7 @@ #ifdef ENABLE_WALLET #include "db.h" #include "wallet.h" +#include "masternode-sync.h" #endif #include @@ -583,8 +584,6 @@ Value getblocktemplate(const Array& params, bool fHelp) aMutable.push_back("prevblock"); } - Array aVotes; - Object result; result.push_back(Pair("capabilities", aCaps)); result.push_back(Pair("version", pblock->nVersion)); @@ -602,7 +601,6 @@ Value getblocktemplate(const Array& params, bool fHelp) result.push_back(Pair("curtime", pblock->GetBlockTime())); result.push_back(Pair("bits", strprintf("%08x", pblock->nBits))); result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1))); - result.push_back(Pair("votes", aVotes)); if(pblock->payee != CScript()){