X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Frpcmining.cpp;h=8f02836681b6c2b22cef150cf5e7ff34ab8535dc;hp=e73e4417d17e079e280dc48373acd4aa5f5a65a2;hb=363358101373af438f57181db57df5bafee96550;hpb=9e2741859746f4fc9fb3bb45eb786c47e7fb8941 diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index e73e441..8f02836 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -8,11 +8,14 @@ #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) @@ -70,6 +73,55 @@ Value getmininginfo(const Array& params, bool fHelp) 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)