diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index da5d7e2b..a46473e5 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -7,8 +7,8 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2019 Howard Chu - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright 2018-2024 SChernykh + * Copyright 2016-2024 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,11 +24,9 @@ * along with this program. If not, see . */ - #include #include - #include "base/net/stratum/Job.h" #include "base/tools/Alignment.h" #include "base/tools/Buffer.h" @@ -112,26 +110,36 @@ bool xmrig::Job::setSeedHash(const char *hash) bool xmrig::Job::setTarget(const char *target) { - if (!target) { + static auto parse = [](const char *target, const Algorithm &algorithm) -> uint64_t { + if (!target) { + return 0; + } + + if (algorithm == Algorithm::RX_YADA) { + return strtoull(target, nullptr, 16); + } + + const auto raw = Cvt::fromHex(target, strlen(target)); + + switch (raw.size()) { + case 4: + return 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast(raw.data()))); + + case 8: + return *reinterpret_cast(raw.data()); + + default: + break; + } + + return 0; + }; + + if ((m_target = parse(target, algorithm())) == 0) { return false; } - const auto raw = Cvt::fromHex(target, strlen(target)); - const size_t size = raw.size(); - if (algorithm() == Algorithm::RX_YADA) { - m_target = strtoull(target, nullptr, 16); - } - else { - if (size == 4) { - m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast(raw.data()))); - } - else if (size == 8) { - m_target = *reinterpret_cast(raw.data()); - } - else { - return false; - } - } + m_diff = toDiff(m_target); # ifdef XMRIG_PROXY_PROJECT assert(sizeof(m_rawTarget) > (size * 2)); @@ -140,7 +148,6 @@ bool xmrig::Job::setTarget(const char *target) memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget))); # endif - m_diff = toDiff(m_target); return true; } @@ -177,14 +184,22 @@ void xmrig::Job::setSigKey(const char *sig_key) int32_t xmrig::Job::nonceOffset() const { - auto f = algorithm().family(); - if (f == Algorithm::KAWPOW) return 32; - if (f == Algorithm::GHOSTRIDER) return 76; + switch (algorithm().family()) { + case Algorithm::KAWPOW: + return 32; - auto id = algorithm().id(); - if (id == Algorithm::RX_YADA) return 147; + case Algorithm::GHOSTRIDER: + return 76; - return 39; + default: + break; + } + + if (algorithm() == Algorithm::RX_YADA) { + return 147; + } + + return 39; } uint32_t xmrig::Job::getNumTransactions() const diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 1ecff369..1bdd5b75 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -7,8 +7,8 @@ * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2019 Howard Chu - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright 2018-2024 SChernykh + * Copyright 2016-2024 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,11 +27,9 @@ #ifndef XMRIG_JOB_H #define XMRIG_JOB_H - #include #include - #include "base/crypto/Algorithm.h" #include "base/tools/Buffer.h" #include "base/tools/String.h" @@ -111,7 +109,7 @@ public: inline bool operator!=(const Job &other) const { return !isEqual(other); } inline bool operator==(const Job &other) const { return isEqual(other); } - inline Job &operator=(const Job &other) { copy(other); return *this; } + inline Job &operator=(const Job &other) { if (this != &other) { copy(other); } return *this; } inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; } # ifdef XMRIG_FEATURE_BENCHMARK