Unify mining algorithm parsing

This commit is contained in:
Capri 2026-09-16 18:40:42 +00:00
commit 775cf67ddd
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM

View file

@ -868,21 +868,23 @@ static RPCHelpMan getblocktemplate()
std::set<std::string> setClientRules; std::set<std::string> setClientRules;
int64_t nMaxVersionPreVB = -1; int64_t nMaxVersionPreVB = -1;
int algo = ALGO_SHA256D; const std::string algo_name =
if (!request.params[1].isNull()) { request.params[1].isNull() ? "sha256d" : request.params[1].get_str();
const std::string strAlgo = request.params[1].get_str(); const int algo = ParseMiningAlgo(algo_name);
if (strAlgo == "sha256d") { if (algo == ALGO_UNKNOWN) {
algo = ALGO_SHA256D; throw JSONRPCError(
} else if (strAlgo == "randomx") { RPC_INVALID_PARAMETER,
const CBlockIndex* tip = chainman.ActiveChain().Tip(); strprintf("Unknown mining algorithm: %s", algo_name));
if (tip == nullptr || }
tip->nHeight + 1 < Params().GetConsensus().randomXActivationHeight) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "RandomX is not active yet"); if (algo == ALGO_RANDOMX) {
} const CBlockIndex* tip = chainman.ActiveChain().Tip();
algo = ALGO_RANDOMX; if (tip == nullptr ||
} else { tip->nHeight + 1 < Params().GetConsensus().randomXActivationHeight) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proof-of-work algorithm"); throw JSONRPCError(
RPC_INVALID_PARAMETER,
"RandomX is not active yet");
} }
} }
CChainState& active_chainstate = chainman.ActiveChainstate(); CChainState& active_chainstate = chainman.ActiveChainstate();