Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501obj.pushKV("difficulty", GetDifficulty(tip));502obj.pushKV("target", GetTarget(tip, chainman.GetConsensus().powLimit).GetHex());503obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));504obj.pushKV("pooledtx", mempool.size());505const auto mining_options{node::FlattenMiningOptions(node.mining_args)};506obj.pushKV("blockmintxfee", ValueFromAmount(CHECK_NONFATAL(mining_options.block_min_fee_rate)->GetFeePerK()));507obj.pushKV("chain", chainman.GetParams().GetChainTypeString());509UniValue next(UniValue::VOBJ);510CBlockIndex next_index;511NextEmptyBlockIndex(tip, chainman.GetConsensus(), next_index);513next.pushKV("height", next_index.nHeight);514next.pushKV("bits", strprintf("%08x", next_index.nBits));515next.pushKV("difficulty", GetDifficulty(next_index));516next.pushKV("target", GetTarget(next_index, chainman.GetConsensus().powLimit).GetHex());517obj.pushKV("next", next);519if (chainman.GetParams().GetChainType() == ChainType::SIGNET) {520const std::vector<uint8_t>& signet_challenge =521chainman.GetConsensus().signet_challenge;522obj.pushKV("signet_challenge", HexStr(signet_challenge));523}524obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));525return obj;526},527};528}531// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts532static RPCMethod prioritisetransaction()533{534return RPCMethod{"prioritisetransaction",535"Accepts the transaction into mined blocks at a higher (or lower) priority\n",536{537{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id."},538{"dummy", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "API-Compatibility for previous API. Must be zero or null.\n"539" DEPRECATED. For forward compatibility use named arguments and omit this parameter.",540RPCArgOptions{.placeholder = true}},541{"fee_delta", RPCArg::Type::NUM, RPCArg::Optional::NO, "The fee value (in satoshis) to add (or subtract, if negative).\n"542" Note, that this value is not a fee rate. It is a value to modify absolute fee of the TX.\n"543" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"544" considers the transaction as it would have paid a higher (or lower) fee."},545},546RPCResult{547RPCResult::Type::BOOL, "", "Returns true"},548RPCExamples{549HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")550+ HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")551},552[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue553{554LOCK(cs_main);556auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};557const auto dummy{self.MaybeArg<double>("dummy")};558CAmount nAmount = request.params[2].getInt<int64_t>();560if (dummy && *dummy != 0) {561throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.");562}564CTxMemPool& mempool = EnsureAnyMemPool(request.context);566// Non-0 fee dust transactions are not allowed for entry, and modification not allowed afterwards567const auto& tx = mempool.get(txid);568if (mempool.m_opts.require_standard && tx && !GetDust(*tx, mempool.m_opts.dust_relay_feerate).empty()) {569throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is not supported for transactions with dust outputs.");570}572mempool.PrioritiseTransaction(txid, nAmount);573return true;574},575};576}578static RPCMethod getprioritisedtransactions()579{580return RPCMethod{"getprioritisedtransactions",581"Returns a map of all user-created (see prioritisetransaction) fee deltas by txid, and whether the tx is present in mempool.",582{},583RPCResult{584RPCResult::Type::OBJ_DYN, "", "prioritisation keyed by txid",585{586{RPCResult::Type::OBJ, "<transactionid>", "", {587{RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},588{RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},589{RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "modified fee in satoshis. Only returned if in_mempool=true"},590}}591},592},593RPCExamples{594HelpExampleCli("getprioritisedtransactions", "")595+ HelpExampleRpc("getprioritisedtransactions", "")596},597[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue598{599NodeContext& node = EnsureAnyNodeContext(request.context);600CTxMemPool& mempool = EnsureMemPool(node);601UniValue rpc_result{UniValue::VOBJ};602for (const auto& delta_info : mempool.GetPrioritisedTransactions()) {603UniValue result_inner{UniValue::VOBJ};604result_inner.pushKV("fee_delta", delta_info.delta);605result_inner.pushKV("in_mempool", delta_info.in_mempool);606if (delta_info.in_mempool) {607result_inner.pushKV("modified_fee", *delta_info.modified_fee);608}609rpc_result.pushKVEnd(delta_info.txid.GetHex(), std::move(result_inner));610}611return rpc_result;612},613};614}617// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller618static UniValue BIP22ValidationResult(const BlockValidationState& state)619{620if (state.IsValid())621return UniValue::VNULL;623if (state.IsError())624throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());625if (state.IsInvalid())626{627std::string strRejectReason = state.GetRejectReason();628if (strRejectReason.empty())629return "rejected";630return strRejectReason;631}632// Should be impossible633return "valid?";634}636// Prefix rule name with ! if not optional, see BIP9637static std::string gbt_rule_value(const std::string& name, bool gbt_optional_rule)638{639std::string s{name};640if (!gbt_optional_rule) {641s.insert(s.begin(), '!');642}643return s;644}646static RPCMethod getblocktemplate()647{648return RPCMethod{649"getblocktemplate",650"If the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"651"It returns data needed to construct a block to work on.\n"652"For full specification, see BIPs 22, 23, 9, and 145:\n"653" https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n"654" https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki\n"655" https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"656" https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n",657{658{"template_request", RPCArg::Type::OBJ, RPCArg::Optional::NO, "Format of the template",659{660{"mode", RPCArg::Type::STR, /* treat as named arg */ RPCArg::Optional::OMITTED, "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"},661{"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED, "A list of strings",662{663{"str", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "client side supported feature, 'longpoll', 'coinbasevalue', 'proposal', 'serverlist', 'workid'"},664}},665{"rules", RPCArg::Type::ARR, RPCArg::Optional::NO, "A list of strings",666{667{"segwit", RPCArg::Type::STR, RPCArg::Optional::NO, "(literal) indicates client side segwit support"},668{"str", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "other client side supported softfork deployment"},669}},670{"longpollid", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "delay processing request until the result would vary significantly from the \"longpollid\" of a prior template"},671{"data", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "proposed block data to check, encoded in hexadecimal; valid only for mode=\"proposal\""},672},673},674},675{676RPCResult{"If the proposal was accepted with mode=='proposal'", RPCResult::Type::NONE, "", ""},677RPCResult{"If the proposal was not accepted with mode=='proposal'", RPCResult::Type::STR, "", "According to BIP22"},678RPCResult{"Otherwise", RPCResult::Type::OBJ, "", "",679{680{RPCResult::Type::NUM, "version", "The preferred block version"},681{RPCResult::Type::ARR, "rules", "specific block rules that are to be enforced",682{683{RPCResult::Type::STR, "", "name of a rule the client must understand to some extent; see BIP 9 for format"},684}},685{RPCResult::Type::OBJ_DYN, "vbavailable", "set of pending, supported versionbit (BIP 9) softfork deployments",686{687{RPCResult::Type::NUM, "rulename", "identifies the bit number as indicating acceptance and readiness for the named softfork rule"},688}},689{RPCResult::Type::ARR, "capabilities", "",690{691{RPCResult::Type::STR, "value", "A supported feature, for example 'proposal'"},692}},693{RPCResult::Type::NUM, "vbrequired", "bit mask of versionbits the server requires set in submissions"},694{RPCResult::Type::STR, "previousblockhash", "The hash of current highest block"},695{RPCResult::Type::ARR, "transactions", "contents of non-coinbase transactions that should be included in the next block",696{697{RPCResult::Type::OBJ, "", "",698{699{RPCResult::Type::STR_HEX, "data", "transaction data encoded in hexadecimal (byte-for-byte)"},700{RPCResult::Type::STR_HEX, "txid", "transaction hash excluding witness data, shown in byte-reversed hex"},701{RPCResult::Type::STR_HEX, "hash", "transaction hash including witness data, shown in byte-reversed hex"},702{RPCResult::Type::ARR, "depends", "array of numbers",703{704{RPCResult::Type::NUM, "", "transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is"},705}},706{RPCResult::Type::NUM, "fee", "difference in value between transaction inputs and outputs (in satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one"},707{RPCResult::Type::NUM, "sigops", "total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero"},708{RPCResult::Type::NUM, "weight", "total transaction weight, as counted for purposes of block limits"},709}},710}},711{RPCResult::Type::OBJ_DYN, "coinbaseaux", "data that should be included in the coinbase's scriptSig content",712{713{RPCResult::Type::STR_HEX, "key", "values must be in the coinbase (keys may be ignored)"},714}},715{RPCResult::Type::NUM, "coinbasevalue", "maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)"},716{RPCResult::Type::STR, "longpollid", "an id to include with a request to longpoll on an update to this template"},717{RPCResult::Type::STR, "target", "The hash target"},718{RPCResult::Type::NUM_TIME, "mintime", "The minimum timestamp appropriate for the next block time, expressed in " + UNIX_EPOCH_TIME + ". Adjusted for the proposed BIP94 timewarp rule."},719{RPCResult::Type::ARR, "mutable", "list of ways the block template may be changed",720{721{RPCResult::Type::STR, "value", "A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'"},722}},723{RPCResult::Type::STR_HEX, "noncerange", "A range of valid nonces"},724{RPCResult::Type::NUM, "sigoplimit", "limit of sigops in blocks"},725{RPCResult::Type::NUM, "sizelimit", "limit of block size"},726{RPCResult::Type::NUM, "weightlimit", /*optional=*/true, "limit of block weight"},727{RPCResult::Type::NUM_TIME, "curtime", "current timestamp in " + UNIX_EPOCH_TIME + ". Adjusted for the proposed BIP94 timewarp rule."},728{RPCResult::Type::STR, "bits", "compressed target of next block"},729{RPCResult::Type::NUM, "height", "The height of the next block"},730{RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "Only on signet"},731{RPCResult::Type::STR_HEX, "default_witness_commitment", /*optional=*/true, "a valid witness commitment for the unmodified block template"},732}},733},734RPCExamples{735HelpExampleCli("getblocktemplate", "'{\"rules\": [\"segwit\"]}'")736+ HelpExampleRpc("getblocktemplate", "{\"rules\": [\"segwit\"]}")737},738[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue739{740NodeContext& node = EnsureAnyNodeContext(request.context);741ChainstateManager& chainman = EnsureChainman(node);742Mining& miner = EnsureMining(node);744std::string strMode = "template";745UniValue lpval = NullUniValue;746std::set<std::string> setClientRules;747if (!request.params[0].isNull())748{749const UniValue& oparam = request.params[0].get_obj();750const UniValue& modeval = oparam.find_value("mode");