diff options
Diffstat (limited to 'src/rpc/mining.cpp')
-rw-r--r-- | src/rpc/mining.cpp | 176 |
1 files changed, 67 insertions, 109 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 1753ecd3fc..dd74095b62 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2010 Satoshi Nakamoto -// Copyright (c) 2009-2016 The Bitcoin Core developers +// Copyright (c) 2009-2017 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -29,8 +29,6 @@ #include <memory> #include <stdint.h> -#include <univalue.h> - unsigned int ParseConfirmTarget(const UniValue& value) { int target = value.get_int(); @@ -203,7 +201,6 @@ UniValue getmininginfo(const JSONRPCRequest& request) " \"pooledtx\": n (numeric) The size of the mempool\n" " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" " \"warnings\": \"...\" (string) any network and blockchain warnings\n" - " \"errors\": \"...\" (string) DEPRECATED. Same as warnings. Only shown when bitcoind is started with -deprecatedrpc=getmininginfo\n" "}\n" "\nExamples:\n" + HelpExampleCli("getmininginfo", "") @@ -214,18 +211,14 @@ UniValue getmininginfo(const JSONRPCRequest& request) LOCK(cs_main); UniValue obj(UniValue::VOBJ); - obj.push_back(Pair("blocks", (int)chainActive.Height())); - obj.push_back(Pair("currentblockweight", (uint64_t)nLastBlockWeight)); - obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("networkhashps", getnetworkhashps(request))); - obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("chain", Params().NetworkIDString())); - if (IsDeprecatedRPCEnabled("getmininginfo")) { - obj.push_back(Pair("errors", GetWarnings("statusbar"))); - } else { - obj.push_back(Pair("warnings", GetWarnings("statusbar"))); - } + obj.pushKV("blocks", (int)chainActive.Height()); + obj.pushKV("currentblockweight", (uint64_t)nLastBlockWeight); + obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx); + obj.pushKV("difficulty", (double)GetDifficulty()); + obj.pushKV("networkhashps", getnetworkhashps(request)); + obj.pushKV("pooledtx", (uint64_t)mempool.size()); + obj.pushKV("chain", Params().NetworkIDString()); + obj.pushKV("warnings", GetWarnings("statusbar")); return obj; } @@ -557,9 +550,9 @@ UniValue getblocktemplate(const JSONRPCRequest& request) UniValue entry(UniValue::VOBJ); - entry.push_back(Pair("data", EncodeHexTx(tx))); - entry.push_back(Pair("txid", txHash.GetHex())); - entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex())); + entry.pushKV("data", EncodeHexTx(tx)); + entry.pushKV("txid", txHash.GetHex()); + entry.pushKV("hash", tx.GetWitnessHash().GetHex()); UniValue deps(UniValue::VARR); for (const CTxIn &in : tx.vin) @@ -567,23 +560,23 @@ UniValue getblocktemplate(const JSONRPCRequest& request) if (setTxIndex.count(in.prevout.hash)) deps.push_back(setTxIndex[in.prevout.hash]); } - entry.push_back(Pair("depends", deps)); + entry.pushKV("depends", deps); int index_in_template = i - 1; - entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template])); + entry.pushKV("fee", pblocktemplate->vTxFees[index_in_template]); int64_t nTxSigOps = pblocktemplate->vTxSigOpsCost[index_in_template]; if (fPreSegWit) { assert(nTxSigOps % WITNESS_SCALE_FACTOR == 0); nTxSigOps /= WITNESS_SCALE_FACTOR; } - entry.push_back(Pair("sigops", nTxSigOps)); - entry.push_back(Pair("weight", GetTransactionWeight(tx))); + entry.pushKV("sigops", nTxSigOps); + entry.pushKV("weight", GetTransactionWeight(tx)); transactions.push_back(entry); } UniValue aux(UniValue::VOBJ); - aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()))); + aux.pushKV("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())); arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); @@ -593,7 +586,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) aMutable.push_back("prevblock"); UniValue result(UniValue::VOBJ); - result.push_back(Pair("capabilities", aCaps)); + result.pushKV("capabilities", aCaps); UniValue aRules(UniValue::VARR); UniValue vbavailable(UniValue::VOBJ); @@ -612,7 +605,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) case THRESHOLD_STARTED: { const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos]; - vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit)); + vbavailable.pushKV(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit); if (setClientRules.find(vbinfo.name) == setClientRules.end()) { if (!vbinfo.gbt_force) { // If the client doesn't support this, don't indicate it in the [default] version @@ -637,10 +630,10 @@ UniValue getblocktemplate(const JSONRPCRequest& request) } } } - result.push_back(Pair("version", pblock->nVersion)); - result.push_back(Pair("rules", aRules)); - result.push_back(Pair("vbavailable", vbavailable)); - result.push_back(Pair("vbrequired", int(0))); + result.pushKV("version", pblock->nVersion); + result.pushKV("rules", aRules); + result.pushKV("vbavailable", vbavailable); + result.pushKV("vbrequired", int(0)); if (nMaxVersionPreVB >= 2) { // If VB is supported by the client, nMaxVersionPreVB is -1, so we won't get here @@ -650,15 +643,15 @@ UniValue getblocktemplate(const JSONRPCRequest& request) aMutable.push_back("version/force"); } - result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex())); - result.push_back(Pair("transactions", transactions)); - result.push_back(Pair("coinbaseaux", aux)); - result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue)); - result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); - result.push_back(Pair("target", hashTarget.GetHex())); - result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); - result.push_back(Pair("mutable", aMutable)); - result.push_back(Pair("noncerange", "00000000ffffffff")); + result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex()); + result.pushKV("transactions", transactions); + result.pushKV("coinbaseaux", aux); + result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue); + result.pushKV("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)); + result.pushKV("target", hashTarget.GetHex()); + result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1); + result.pushKV("mutable", aMutable); + result.pushKV("noncerange", "00000000ffffffff"); int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST; int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE; if (fPreSegWit) { @@ -667,17 +660,17 @@ UniValue getblocktemplate(const JSONRPCRequest& request) assert(nSizeLimit % WITNESS_SCALE_FACTOR == 0); nSizeLimit /= WITNESS_SCALE_FACTOR; } - result.push_back(Pair("sigoplimit", nSigOpLimit)); - result.push_back(Pair("sizelimit", nSizeLimit)); + result.pushKV("sigoplimit", nSigOpLimit); + result.pushKV("sizelimit", nSizeLimit); if (!fPreSegWit) { - result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT)); + result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT); } - result.push_back(Pair("curtime", pblock->GetBlockTime())); - result.push_back(Pair("bits", strprintf("%08x", pblock->nBits))); - result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1))); + result.pushKV("curtime", pblock->GetBlockTime()); + result.pushKV("bits", strprintf("%08x", pblock->nBits)); + result.pushKV("height", (int64_t)(pindexPrev->nHeight+1)); if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) { - result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end()))); + result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())); } return result; @@ -774,43 +767,8 @@ UniValue submitblock(const JSONRPCRequest& request) UniValue estimatefee(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - "estimatefee nblocks\n" - "\nDEPRECATED. Please use estimatesmartfee for more intelligent estimates." - "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" - "confirmation within nblocks blocks. Uses virtual transaction size of transaction\n" - "as defined in BIP 141 (witness data is discounted).\n" - "\nArguments:\n" - "1. nblocks (numeric, required)\n" - "\nResult:\n" - "n (numeric) estimated fee-per-kilobyte\n" - "\n" - "A negative value is returned if not enough transactions and blocks\n" - "have been observed to make an estimate.\n" - "-1 is always returned for nblocks == 1 as it is impossible to calculate\n" - "a fee that is high enough to get reliably included in the next block.\n" - "\nExample:\n" - + HelpExampleCli("estimatefee", "6") - ); - - if (!IsDeprecatedRPCEnabled("estimatefee")) { - throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee is deprecated and will be fully removed in v0.17. " - "To use estimatefee in v0.16, restart bitcoind with -deprecatedrpc=estimatefee.\n" - "Projects should transition to using estimatesmartfee before upgrading to v0.17"); - } - - RPCTypeCheck(request.params, {UniValue::VNUM}); - - int nBlocks = request.params[0].get_int(); - if (nBlocks < 1) - nBlocks = 1; - - CFeeRate feeRate = ::feeEstimator.estimateFee(nBlocks); - if (feeRate == CFeeRate(0)) - return -1.0; - - return ValueFromAmount(feeRate.GetFeePerK()); + throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee was removed in v0.17.\n" + "Clients should use estimatesmartfee."); } UniValue estimatesmartfee(const JSONRPCRequest& request) @@ -865,12 +823,12 @@ UniValue estimatesmartfee(const JSONRPCRequest& request) FeeCalculation feeCalc; CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative); if (feeRate != CFeeRate(0)) { - result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK()))); + result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK())); } else { errors.push_back("Insufficient data or no feerate found"); - result.push_back(Pair("errors", errors)); + result.pushKV("errors", errors); } - result.push_back(Pair("blocks", feeCalc.returnedTarget)); + result.pushKV("blocks", feeCalc.returnedTarget); return result; } @@ -941,37 +899,37 @@ UniValue estimaterawfee(const JSONRPCRequest& request) UniValue horizon_result(UniValue::VOBJ); UniValue errors(UniValue::VARR); UniValue passbucket(UniValue::VOBJ); - passbucket.push_back(Pair("startrange", round(buckets.pass.start))); - passbucket.push_back(Pair("endrange", round(buckets.pass.end))); - passbucket.push_back(Pair("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0)); - passbucket.push_back(Pair("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0)); - passbucket.push_back(Pair("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0)); - passbucket.push_back(Pair("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0)); + passbucket.pushKV("startrange", round(buckets.pass.start)); + passbucket.pushKV("endrange", round(buckets.pass.end)); + passbucket.pushKV("withintarget", round(buckets.pass.withinTarget * 100.0) / 100.0); + passbucket.pushKV("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0); + passbucket.pushKV("inmempool", round(buckets.pass.inMempool * 100.0) / 100.0); + passbucket.pushKV("leftmempool", round(buckets.pass.leftMempool * 100.0) / 100.0); UniValue failbucket(UniValue::VOBJ); - failbucket.push_back(Pair("startrange", round(buckets.fail.start))); - failbucket.push_back(Pair("endrange", round(buckets.fail.end))); - failbucket.push_back(Pair("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0)); - failbucket.push_back(Pair("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0)); - failbucket.push_back(Pair("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0)); - failbucket.push_back(Pair("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0)); + failbucket.pushKV("startrange", round(buckets.fail.start)); + failbucket.pushKV("endrange", round(buckets.fail.end)); + failbucket.pushKV("withintarget", round(buckets.fail.withinTarget * 100.0) / 100.0); + failbucket.pushKV("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0); + failbucket.pushKV("inmempool", round(buckets.fail.inMempool * 100.0) / 100.0); + failbucket.pushKV("leftmempool", round(buckets.fail.leftMempool * 100.0) / 100.0); // CFeeRate(0) is used to indicate error as a return value from estimateRawFee if (feeRate != CFeeRate(0)) { - horizon_result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK()))); - horizon_result.push_back(Pair("decay", buckets.decay)); - horizon_result.push_back(Pair("scale", (int)buckets.scale)); - horizon_result.push_back(Pair("pass", passbucket)); + horizon_result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK())); + horizon_result.pushKV("decay", buckets.decay); + horizon_result.pushKV("scale", (int)buckets.scale); + horizon_result.pushKV("pass", passbucket); // buckets.fail.start == -1 indicates that all buckets passed, there is no fail bucket to output - if (buckets.fail.start != -1) horizon_result.push_back(Pair("fail", failbucket)); + if (buckets.fail.start != -1) horizon_result.pushKV("fail", failbucket); } else { // Output only information that is still meaningful in the event of error - horizon_result.push_back(Pair("decay", buckets.decay)); - horizon_result.push_back(Pair("scale", (int)buckets.scale)); - horizon_result.push_back(Pair("fail", failbucket)); + horizon_result.pushKV("decay", buckets.decay); + horizon_result.pushKV("scale", (int)buckets.scale); + horizon_result.pushKV("fail", failbucket); errors.push_back("Insufficient data or no feerate found which meets threshold"); - horizon_result.push_back(Pair("errors",errors)); + horizon_result.pushKV("errors",errors); } - result.push_back(Pair(StringForFeeEstimateHorizon(horizon), horizon_result)); + result.pushKV(StringForFeeEstimateHorizon(horizon), horizon_result); } return result; } @@ -988,7 +946,7 @@ static const CRPCCommand commands[] = { "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} }, - { "util", "estimatefee", &estimatefee, {"nblocks"} }, + { "hidden", "estimatefee", &estimatefee, {} }, { "util", "estimatesmartfee", &estimatesmartfee, {"conf_target", "estimate_mode"} }, { "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} }, |