Remove GetKernelMidstate, rename ScanMidstateForward and ScanMidstateBackward to...
[novacoin.git] / src / rpcmining.cpp
index 28d6ed8..a4f9680 100644 (file)
@@ -15,6 +15,7 @@ using namespace json_spirit;
 using namespace std;
 
 extern uint256 nPoWBase;
+extern uint64_t nStakeInputsMapSize;
 
 Value getsubsidy(const Array& params, bool fHelp)
 {
@@ -45,9 +46,6 @@ Value getmininginfo(const Array& params, bool fHelp)
             "getmininginfo\n"
             "Returns an object containing mining-related information.");
 
-    float nKernelsRate = 0, nCoinDaysRate = 0;
-    pwalletMain->GetStakeStats(nKernelsRate, nCoinDaysRate);
-
     Object obj, diff, weight;
     obj.push_back(Pair("blocks",        (int)nBestHeight));
     obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
@@ -59,16 +57,14 @@ Value getmininginfo(const Array& params, bool fHelp)
     obj.push_back(Pair("difficulty",    diff));
 
     obj.push_back(Pair("blockvalue",    (uint64_t)GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits)));
-    obj.push_back(Pair("netmhashps",     GetPoWMHashPS()));
-    obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
+    obj.push_back(Pair("netmhashps",    GetPoWMHashPS()));
+    obj.push_back(Pair("netstakeweight",GetPoSKernelPS()));
     obj.push_back(Pair("errors",        GetWarnings("statusbar")));
     obj.push_back(Pair("pooledtx",      (uint64_t)mempool.size()));
 
-    weight.push_back(Pair("kernelsrate",   nKernelsRate));
-    weight.push_back(Pair("cdaysrate",   nCoinDaysRate));
-    obj.push_back(Pair("stakestats", weight));
+    obj.push_back(Pair("stakeinputs",   (uint64_t)nStakeInputsMapSize));
+    obj.push_back(Pair("stakeinterest", GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true)));
 
-    obj.push_back(Pair("stakeinterest",    (uint64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true)));
     obj.push_back(Pair("testnet",       fTestNet));
     return obj;
 }
@@ -136,17 +132,28 @@ Value scaninput(const Array& params, bool fHelp)
             interval.first += (nStakeMinAge + block.nTime - interval.first);
         interval.second = interval.first + nDays * 86400;
 
-        SHA256_CTX ctx;
-        GetKernelMidstate(nStakeModifier, block.nTime, txindex.pos.nTxPos - txindex.pos.nBlockPos, tx.nTime, nOut, ctx);
+        // Build static part of kernel
+        CDataStream ssKernel(SER_GETHASH, 0);
+        ssKernel << nStakeModifier;
+        ssKernel << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << tx.nTime << nOut;
+        CDataStream::const_iterator itK = ssKernel.begin();
 
-        std::pair<uint256, uint32_t> solution;
-        if (ScanMidstateForward(ctx, nBits, tx.nTime, tx.vout[nOut].nValue, interval, solution))
+        std::vector<std::pair<uint256, uint32_t> > solutions;
+        if (ScanKernelForward((unsigned char *)&itK[0], nBits, tx.nTime, tx.vout[nOut].nValue, interval, solutions))
         {
-            Object r;
-            r.push_back(Pair("hash", solution.first.GetHex()));
-            r.push_back(Pair("time", DateTimeStrFormat(solution.second)));
+            Array results;
+
+            BOOST_FOREACH(const PAIRTYPE(uint256, uint32_t) solution, solutions)
+            {
+
+                Object item;
+                item.push_back(Pair("hash", solution.first.GetHex()));
+                item.push_back(Pair("time", DateTimeStrFormat(solution.second)));
+
+                results.push_back(item);
+            }
 
-            return r;
+            return results;
         }
     }
     else
@@ -567,7 +574,7 @@ Value submitblock(const Array& params, bool fHelp)
     try {
         ssBlock >> block;
     }
-    catch (std::exception &e) {
+    catch (const std::exception&) {
         throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
     }