Unify mining algorithm parsing
This commit is contained in:
parent
7413884a7a
commit
775cf67ddd
1 changed files with 17 additions and 15 deletions
|
|
@ -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,
|
||||||
|
strprintf("Unknown mining algorithm: %s", algo_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (algo == ALGO_RANDOMX) {
|
||||||
const CBlockIndex* tip = chainman.ActiveChain().Tip();
|
const CBlockIndex* tip = chainman.ActiveChain().Tip();
|
||||||
if (tip == nullptr ||
|
if (tip == nullptr ||
|
||||||
tip->nHeight + 1 < Params().GetConsensus().randomXActivationHeight) {
|
tip->nHeight + 1 < Params().GetConsensus().randomXActivationHeight) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "RandomX is not active yet");
|
throw JSONRPCError(
|
||||||
}
|
RPC_INVALID_PARAMETER,
|
||||||
algo = ALGO_RANDOMX;
|
"RandomX is not active yet");
|
||||||
} else {
|
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proof-of-work algorithm");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue