X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcmining.cpp;h=8f02836681b6c2b22cef150cf5e7ff34ab8535dc;hb=363358101373af438f57181db57df5bafee96550;hp=94d367147799af780115100a90e319143b70e294;hpb=2c8f88fc67af7916670ce0086e6a9078df8182f0;p=novacoin.git diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 94d3671..8f02836 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -8,11 +8,36 @@ #include "txdb.h" #include "init.h" #include "miner.h" +#include "kernel.h" #include "bitcoinrpc.h" using namespace json_spirit; using namespace std; +extern uint256 nPoWBase; + +Value getsubsidy(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "getsubsidy [nTarget]\n" + "Returns proof-of-work subsidy value for the specified value of target."); + + unsigned int nBits = 0; + + if (params.size() != 0) + { + CBigNum bnTarget(uint256(params[0].get_str())); + nBits = bnTarget.GetCompact(); + } + else + { + nBits = GetNextTargetRequired(pindexBest, false); + } + + return (uint64_t)GetProofOfWorkReward(nBits); +} + Value getmininginfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -20,29 +45,83 @@ Value getmininginfo(const Array& params, bool fHelp) "getmininginfo\n" "Returns an object containing mining-related information."); - uint64 nMinWeight = 0, nMaxWeight = 0, nWeight = 0; - pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight); + float nKernelsRate = 0, nCoinDaysRate = 0; + pwalletMain->GetStakeStats(nKernelsRate, nCoinDaysRate); - Object obj; + Object obj, diff, weight; obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); + + diff.push_back(Pair("proof-of-work", GetDifficulty())); + diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); + diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval)); + 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("errors", GetWarnings("statusbar"))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("stakeweight", (uint64_t)nWeight)); - obj.push_back(Pair("minweight", (uint64_t)nMinWeight)); - obj.push_back(Pair("maxweight", (uint64_t)nMaxWeight)); + weight.push_back(Pair("kernelsrate", nKernelsRate)); + weight.push_back(Pair("cdaysrate", nCoinDaysRate)); + obj.push_back(Pair("stakestats", weight)); 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; } +Value scaninput(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 4 || params.size() < 2) + throw runtime_error( + "scaninput [difficulty] [days]\n" + "Scan specified input for suitable kernel solutions.\n" + " [difficulty] - upper limit for difficulty, current difficulty by default;\n" + " [days] - time window, 365 days by default.\n" + ); + + + uint256 hash; + hash.SetHex(params[0].get_str()); + + uint32_t nOut = params[1].get_int(), nBits = GetNextTargetRequired(pindexBest, true), nDays = 365; + + if (params.size() > 2) + { + CBigNum bnTarget(nPoWBase); + bnTarget *= 1000; + bnTarget /= (int) (params[2].get_real() * 1000); + nBits = bnTarget.GetCompact(); + } + + if (params.size() > 3) + { + nDays = params[3].get_int(); + } + + CTransaction tx; + uint256 hashBlock = 0; + if (GetTransaction(hash, tx, hashBlock)) + { + std::pair solution; + if (ScanInputForStakeKernelHash(tx, nOut, nBits, nDays * 86400, solution)) + { + Object r; + r.push_back(Pair("hash", solution.first.GetHex())); + r.push_back(Pair("time", DateTimeStrFormat(solution.second))); + + return r; + } + } + else + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); + + return Value::null; +} + Value getworkex(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) @@ -67,7 +146,7 @@ Value getworkex(const Array& params, bool fHelp) // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; - static int64 nStart; + static int64_t nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) @@ -198,7 +277,7 @@ Value getwork(const Array& params, bool fHelp) // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; - static int64 nStart; + static int64_t nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) @@ -334,7 +413,7 @@ Value getblocktemplate(const Array& params, bool fHelp) // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; - static int64 nStart; + static int64_t nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))