Update CMakeLists.txt - play with openssl
[novacoin.git] / src / rpcmining.cpp
index fa1eb19..c00c356 100644 (file)
@@ -3,17 +3,13 @@
 // Distributed under the MIT/X11 software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
-#include "main.h"
 #include "db.h"
-#include "txdb.h"
+#include "txdb-leveldb.h"
 #include "init.h"
 #include "miner.h"
 #include "kernel.h"
 #include "bitcoinrpc.h"
-
-#include <boost/format.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/iterator/counting_iterator.hpp>
+#include "wallet.h"
 
 using namespace json_spirit;
 using namespace std;
@@ -50,7 +46,7 @@ Value getmininginfo(const Array& params, bool fHelp)
             "getmininginfo\n"
             "Returns an object containing mining-related information.");
 
-    Object obj, diff, weight;
+    Object obj, diff;
     obj.push_back(Pair("blocks",        (int)nBestHeight));
     obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
     obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
@@ -84,7 +80,7 @@ Value scaninput(const Array& params, bool fHelp)
             "    days - time window, 90 days by default.\n"
         );
 
-    RPCTypeCheck(params, boost::assign::list_of(obj_type));
+    RPCTypeCheck(params, { obj_type });
 
     Object scanParams = params[0].get_obj();
 
@@ -134,13 +130,13 @@ Value scaninput(const Array& params, bool fHelp)
         if (inputs_v.type() == array_type)
         {
             Array inputs = inputs_v.get_array();
-            BOOST_FOREACH(const Value &v_out, inputs)
+            for (const Value &v_out : inputs)
             {
                 int nOut = v_out.get_int();
                 if (nOut < 0 || nOut > (int)tx.vout.size() - 1)
                 {
                     stringstream strErrorMsg;
-                    strErrorMsg << boost::format("Invalid parameter, input number %d is out of range") % nOut;
+                    strErrorMsg << "Invalid parameter, input number " << to_string(nOut) << " is out of range";
                     throw JSONRPCError(RPC_INVALID_PARAMETER, strErrorMsg.str());
                 }
 
@@ -153,7 +149,7 @@ Value scaninput(const Array& params, bool fHelp)
             if (nOut < 0 || nOut > (int)tx.vout.size() - 1)
             {
                 stringstream strErrorMsg;
-                strErrorMsg << boost::format("Invalid parameter, input number %d is out of range") % nOut;
+                strErrorMsg << "Invalid parameter, input number " << to_string(nOut) << " is out of range";
                 throw JSONRPCError(RPC_INVALID_PARAMETER, strErrorMsg.str());
             }
 
@@ -161,7 +157,7 @@ Value scaninput(const Array& params, bool fHelp)
         }
         else
         {
-            vInputs = vector<int>(boost::counting_iterator<int>( 0 ), boost::counting_iterator<int>( tx.vout.size() ));
+            for (size_t i = 0; i != tx.vout.size(); ++i) vInputs.push_back(i);
         }
 
         CTxDB txdb("r");
@@ -189,7 +185,7 @@ Value scaninput(const Array& params, bool fHelp)
         interval.second = interval.first + nDays * nOneDay;
 
         Array results;
-        BOOST_FOREACH(const int &nOut, vInputs)
+        for (const int &nOut : vInputs)
         {
             // Check for spent flag
             // It doesn't make sense to scan spent inputs.
@@ -209,7 +205,7 @@ Value scaninput(const Array& params, bool fHelp)
             std::vector<std::pair<uint256, uint32_t> > result;
             if (ScanKernelForward((unsigned char *)&itK[0], nBits, tx.nTime, tx.vout[nOut].nValue, interval, result))
             {
-                BOOST_FOREACH(const PAIRTYPE(uint256, uint32_t) solution, result)
+                for (const auto &solution : result)
                 {
                     Object item;
                     item.push_back(Pair("nout", nOut));
@@ -244,9 +240,9 @@ Value getworkex(const Array& params, bool fHelp)
     if (IsInitialBlockDownload())
         throw JSONRPCError(-10, "NovaCoin is downloading blocks...");
 
-    typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
+    typedef map<uint256, pair<shared_ptr<CBlock>, CScript> > mapNewBlock_t;
     static mapNewBlock_t mapNewBlock;
-    static vector<CBlock*> vNewBlock;
+    static vector<std::shared_ptr<CBlock>> vNewBlock;
     static CReserveKey reservekey(pwalletMain);
 
     if (params.size() == 0)
@@ -255,7 +251,7 @@ Value getworkex(const Array& params, bool fHelp)
         static unsigned int nTransactionsUpdatedLast;
         static CBlockIndex* pindexPrev;
         static int64_t nStart;
-        static CBlock* pblock;
+        static shared_ptr<CBlock> pblock;
         if (pindexPrev != pindexBest ||
             (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
         {
@@ -263,8 +259,6 @@ Value getworkex(const Array& params, bool fHelp)
             {
                 // Deallocate old blocks since they're obsolete now
                 mapNewBlock.clear();
-                BOOST_FOREACH(CBlock* pblock, vNewBlock)
-                    delete pblock;
                 vNewBlock.clear();
             }
             nTransactionsUpdatedLast = nTransactionsUpdated;
@@ -310,7 +304,7 @@ Value getworkex(const Array& params, bool fHelp)
 
         Array merkle_arr;
 
-        BOOST_FOREACH(uint256 merkleh, merkle) {
+        for (uint256 merkleh : merkle) {
             merkle_arr.push_back(HexStr(BEGIN(merkleh), END(merkleh)));
         }
 
@@ -340,7 +334,7 @@ Value getworkex(const Array& params, bool fHelp)
         // Get saved block
         if (!mapNewBlock.count(pdata->hashMerkleRoot))
             return false;
-        CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
+        std::shared_ptr<CBlock> pblock = mapNewBlock[pdata->hashMerkleRoot].first;
 
         pblock->nTime = pdata->nTime;
         pblock->nNonce = pdata->nNonce;
@@ -375,9 +369,9 @@ Value getwork(const Array& params, bool fHelp)
     if (IsInitialBlockDownload())
         throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "NovaCoin is downloading blocks...");
 
-    typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
+    typedef map<uint256, pair<shared_ptr<CBlock>, CScript> > mapNewBlock_t;
     static mapNewBlock_t mapNewBlock;    // FIXME: thread safety
-    static vector<CBlock*> vNewBlock;
+    static vector<shared_ptr<CBlock>> vNewBlock;
     static CReserveKey reservekey(pwalletMain);
 
     if (params.size() == 0)
@@ -386,7 +380,7 @@ Value getwork(const Array& params, bool fHelp)
         static unsigned int nTransactionsUpdatedLast;
         static CBlockIndex* pindexPrev;
         static int64_t nStart;
-        static CBlock* pblock;
+        static shared_ptr<CBlock> pblock;
         if (pindexPrev != pindexBest ||
             (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
         {
@@ -394,8 +388,6 @@ Value getwork(const Array& params, bool fHelp)
             {
                 // Deallocate old blocks since they're obsolete now
                 mapNewBlock.clear();
-                BOOST_FOREACH(CBlock* pblock, vNewBlock)
-                    delete pblock;
                 vNewBlock.clear();
             }
 
@@ -458,7 +450,7 @@ Value getwork(const Array& params, bool fHelp)
         // Get saved block
         if (!mapNewBlock.count(pdata->hashMerkleRoot))
             return false;
-        CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
+        std::shared_ptr<CBlock> pblock = mapNewBlock[pdata->hashMerkleRoot].first;
 
         pblock->nTime = pdata->nTime;
         pblock->nNonce = pdata->nNonce;
@@ -522,7 +514,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
     static unsigned int nTransactionsUpdatedLast;
     static CBlockIndex* pindexPrev;
     static int64_t nStart;
-    static CBlock* pblock;
+    static std::shared_ptr<CBlock> pblock;
     if (pindexPrev != pindexBest ||
         (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
     {
@@ -537,8 +529,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
         // Create new block
         if(pblock)
         {
-            delete pblock;
-            pblock = NULL;
+            pblock.reset();
         }
         pblock = CreateNewBlock(pwalletMain);
         if (!pblock)
@@ -556,7 +547,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
     map<uint256, int64_t> setTxIndex;
     int i = 0;
     CTxDB txdb("r");
-    BOOST_FOREACH (CTransaction& tx, pblock->vtx)
+    for (CTransaction& tx : pblock->vtx)
     {
         uint256 txHash = tx.GetHash();
         setTxIndex[txHash] = i++;
@@ -580,7 +571,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
             entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut())));
 
             Array deps;
-            BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)
+            for (MapPrevTx::value_type& inp : mapInputs)
             {
                 if (setTxIndex.count(inp.first))
                     deps.push_back(setTxIndex[inp.first]);