X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcmining.cpp;h=8f3358fc8bdf5dea0c5834f4b52635c170e06c4f;hb=ef17ac0211ddd486127e1f94756fbb3fd704a9b4;hp=71b47d4adf7026bfb1103158f9b9c6a8cba87a9b;hpb=749faf6d4decb3b364cc981060fd4a26dab82df8;p=novacoin.git diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 71b47d4..8f3358f 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -13,7 +13,6 @@ #include #include -#include using namespace json_spirit; using namespace std; @@ -50,7 +49,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)); @@ -78,7 +77,7 @@ Value scaninput(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "scaninput '{\"txid\":txid, \"vout\":[vout1, vout2, ..., voutN], \"difficulty\":difficulty, \"days\":days}'\n" + "scaninput '{\"txid\":\"txid\", \"vout\":[vout1, vout2, ..., voutN], \"difficulty\":difficulty, \"days\":days}'\n" "Scan specified transaction or input for suitable kernel solutions.\n" " difficulty - upper limit for difficulty, current difficulty by default;\n" " days - time window, 90 days by default.\n" @@ -147,9 +146,21 @@ Value scaninput(const Array& params, bool fHelp) vInputs.push_back(nOut); } } + else if(inputs_v.type() == int_type) + { + int nOut = inputs_v.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; + throw JSONRPCError(RPC_INVALID_PARAMETER, strErrorMsg.str()); + } + + vInputs.push_back(nOut); + } else { - vInputs = vector(boost::counting_iterator( 0 ), boost::counting_iterator( tx.vout.size() )); + for (size_t i = 0; i != tx.vout.size(); ++i) vInputs.push_back(i); } CTxDB txdb("r"); @@ -232,9 +243,9 @@ Value getworkex(const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(-10, "NovaCoin is downloading blocks..."); - typedef map > mapNewBlock_t; + typedef map, CScript> > mapNewBlock_t; static mapNewBlock_t mapNewBlock; - static vector vNewBlock; + static vector> vNewBlock; static CReserveKey reservekey(pwalletMain); if (params.size() == 0) @@ -243,7 +254,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 pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) { @@ -251,8 +262,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; @@ -328,7 +337,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 pblock = mapNewBlock[pdata->hashMerkleRoot].first; pblock->nTime = pdata->nTime; pblock->nNonce = pdata->nNonce; @@ -363,9 +372,9 @@ Value getwork(const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "NovaCoin is downloading blocks..."); - typedef map > mapNewBlock_t; + typedef map, CScript> > mapNewBlock_t; static mapNewBlock_t mapNewBlock; // FIXME: thread safety - static vector vNewBlock; + static vector> vNewBlock; static CReserveKey reservekey(pwalletMain); if (params.size() == 0) @@ -374,7 +383,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 pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) { @@ -382,8 +391,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(); } @@ -446,7 +453,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 pblock = mapNewBlock[pdata->hashMerkleRoot].first; pblock->nTime = pdata->nTime; pblock->nNonce = pdata->nNonce; @@ -510,7 +517,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 pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { @@ -525,8 +532,7 @@ Value getblocktemplate(const Array& params, bool fHelp) // Create new block if(pblock) { - delete pblock; - pblock = NULL; + pblock.reset(); } pblock = CreateNewBlock(pwalletMain); if (!pblock)