Merge xmrig v6.15.0 into master
This commit is contained in:
commit
29fa5c61e0
258 changed files with 13719 additions and 8163 deletions
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
@ -198,7 +197,7 @@ void xmrig::Api::genId(const String &id)
|
|||
return;
|
||||
}
|
||||
|
||||
uv_interface_address_t *interfaces;
|
||||
uv_interface_address_t *interfaces = nullptr;
|
||||
int count = 0;
|
||||
|
||||
if (uv_interface_addresses(&interfaces, &count) < 0) {
|
||||
|
|
|
@ -95,6 +95,7 @@ bool xmrig::Httpd::start()
|
|||
m_port = static_cast<uint16_t>(rc);
|
||||
|
||||
# ifdef _WIN32
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
|
||||
HRSRC src = FindResource(nullptr, MAKEINTRESOURCE(1), RT_ICON);
|
||||
if (src != nullptr) {
|
||||
HGLOBAL res = LoadResource(nullptr, src);
|
||||
|
|
|
@ -45,6 +45,9 @@ static inline const char *rpcError(int code) {
|
|||
|
||||
case IApiRequest::RPC_INVALID_PARAMS:
|
||||
return "Invalid params";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (code >= 400 && code < 600) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
set(HEADERS_BASE
|
||||
src/3rdparty/fmt/format.cc
|
||||
src/3rdparty/epee/span.h
|
||||
src/base/api/interfaces/IApiListener.h
|
||||
src/base/crypto/Algorithm.h
|
||||
src/base/crypto/Coin.h
|
||||
|
@ -81,11 +81,13 @@ set(HEADERS_BASE
|
|||
src/base/tools/cryptonote/WalletAddress.h
|
||||
src/base/tools/Cvt.h
|
||||
src/base/tools/Handle.h
|
||||
src/base/tools/Span.h
|
||||
src/base/tools/String.h
|
||||
src/base/tools/Timer.h
|
||||
)
|
||||
|
||||
set(SOURCES_BASE
|
||||
src/3rdparty/fmt/format.cc
|
||||
src/base/crypto/Algorithm.cpp
|
||||
src/base/crypto/Coin.cpp
|
||||
src/base/crypto/keccak.cpp
|
||||
|
@ -130,14 +132,14 @@ set(SOURCES_BASE
|
|||
src/base/net/tools/LineReader.cpp
|
||||
src/base/net/tools/NetBuffer.cpp
|
||||
src/base/tools/Arguments.cpp
|
||||
src/base/tools/cryptonote/BlockTemplate.cpp
|
||||
src/base/tools/cryptonote/crypto-ops-data.c
|
||||
src/base/tools/cryptonote/crypto-ops.c
|
||||
src/base/tools/cryptonote/Signatures.cpp
|
||||
src/base/tools/cryptonote/WalletAddress.cpp
|
||||
src/base/tools/Cvt.cpp
|
||||
src/base/tools/String.cpp
|
||||
src/base/tools/Timer.cpp
|
||||
src/base/tools/cryptonote/BlockTemplate.cpp
|
||||
src/base/tools/cryptonote/Signatures.cpp
|
||||
src/base/tools/cryptonote/WalletAddress.cpp
|
||||
src/base/tools/cryptonote/crypto-ops.c
|
||||
src/base/tools/cryptonote/crypto-ops-data.c
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ const char *Algorithm::kRX = "rx";
|
|||
const char *Algorithm::kRX_0 = "rx/0";
|
||||
const char *Algorithm::kRX_WOW = "rx/wow";
|
||||
const char *Algorithm::kRX_ARQ = "rx/arq";
|
||||
const char *Algorithm::kRX_GRAFT = "rx/graft";
|
||||
const char *Algorithm::kRX_SFX = "rx/sfx";
|
||||
const char *Algorithm::kRX_KEVA = "rx/keva";
|
||||
#endif
|
||||
|
@ -112,11 +113,6 @@ const char *Algorithm::kRX_XLA = "panthera";
|
|||
#define ALGO_ALIAS_AUTO(ALGO) { Algorithm::k##ALGO, Algorithm::ALGO }
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
|
||||
static const std::map<uint32_t, const char *> kAlgorithmNames = {
|
||||
ALGO_NAME(CN_0),
|
||||
ALGO_NAME(CN_1),
|
||||
|
@ -155,6 +151,7 @@ static const std::map<uint32_t, const char *> kAlgorithmNames = {
|
|||
ALGO_NAME(RX_0),
|
||||
ALGO_NAME(RX_WOW),
|
||||
ALGO_NAME(RX_ARQ),
|
||||
ALGO_NAME(RX_GRAFT),
|
||||
ALGO_NAME(RX_SFX),
|
||||
ALGO_NAME(RX_KEVA),
|
||||
# endif
|
||||
|
@ -271,6 +268,8 @@ static const std::map<const char *, Algorithm::Id, aliasCompare> kAlgorithmAlias
|
|||
ALGO_ALIAS(RX_WOW, "randomwow"),
|
||||
ALGO_ALIAS_AUTO(RX_ARQ), ALGO_ALIAS(RX_ARQ, "randomx/arq"),
|
||||
ALGO_ALIAS(RX_ARQ, "randomarq"),
|
||||
ALGO_ALIAS_AUTO(RX_GRAFT), ALGO_ALIAS(RX_GRAFT, "randomx/graft"),
|
||||
ALGO_ALIAS(RX_GRAFT, "randomgraft"),
|
||||
ALGO_ALIAS_AUTO(RX_SFX), ALGO_ALIAS(RX_SFX, "randomx/sfx"),
|
||||
ALGO_ALIAS(RX_SFX, "randomsfx"),
|
||||
ALGO_ALIAS_AUTO(RX_KEVA), ALGO_ALIAS(RX_KEVA, "randomx/keva"),
|
||||
|
@ -370,7 +369,7 @@ std::vector<xmrig::Algorithm> xmrig::Algorithm::all(const std::function<bool(con
|
|||
CN_PICO_0, CN_PICO_TLO,
|
||||
CN_UPX2,
|
||||
CN_GPU, RX_XLA,
|
||||
RX_0, RX_WOW, RX_ARQ, RX_SFX, RX_KEVA,
|
||||
RX_0, RX_WOW, RX_ARQ, RX_GRAFT, RX_SFX, RX_KEVA,
|
||||
AR2_CHUKWA, AR2_CHUKWA_V2, AR2_WRKZ,
|
||||
ASTROBWT_DERO,
|
||||
KAWPOW_RVN
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
RX_0 = 0x72151200, // "rx/0" RandomX (reference configuration).
|
||||
RX_WOW = 0x72141177, // "rx/wow" RandomWOW (Wownero).
|
||||
RX_ARQ = 0x72121061, // "rx/arq" RandomARQ (Arqma).
|
||||
RX_GRAFT = 0x72151267, // "rx/graft" RandomGRAFT (Graft).
|
||||
RX_SFX = 0x72151273, // "rx/sfx" RandomSFX (Safex Cash).
|
||||
RX_KEVA = 0x7214116b, // "rx/keva" RandomKEVA (Keva).
|
||||
AR2_CHUKWA = 0x61130000, // "argon2/chukwa" Argon2id (Chukwa).
|
||||
|
@ -137,6 +138,7 @@ public:
|
|||
static const char *kRX_0;
|
||||
static const char *kRX_WOW;
|
||||
static const char *kRX_ARQ;
|
||||
static const char *kRX_GRAFT;
|
||||
static const char *kRX_SFX;
|
||||
static const char *kRX_KEVA;
|
||||
# endif
|
||||
|
@ -174,7 +176,7 @@ public:
|
|||
static inline constexpr bool isCN(Id id) { return (id & 0xff000000) == CN_ANY; }
|
||||
static inline constexpr Id base(Id id) { return isCN(id) ? static_cast<Id>(CN_0 | (id & 0xff00)) : INVALID; }
|
||||
static inline constexpr size_t l2(Id id) { return family(id) == RANDOM_X ? (1U << ((id >> 8) & 0xff)) : 0U; }
|
||||
static inline constexpr size_t l3(Id id) { return 1U << ((id >> 16) & 0xff); }
|
||||
static inline constexpr size_t l3(Id id) { return 1ULL << ((id >> 16) & 0xff); }
|
||||
static inline constexpr uint32_t family(Id id) { return id & (isCN(id) ? 0xffff0000 : 0xff000000); }
|
||||
|
||||
inline bool isCN() const { return isCN(m_id); }
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,9 +16,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/crypto/Coin.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
#include <cstring>
|
||||
|
@ -39,74 +33,66 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
struct CoinName
|
||||
struct CoinInfo
|
||||
{
|
||||
const Algorithm::Id algorithm;
|
||||
const char *code;
|
||||
const char *name;
|
||||
const Coin::Id id;
|
||||
const uint64_t target;
|
||||
const uint64_t units;
|
||||
const char *tag;
|
||||
};
|
||||
|
||||
|
||||
static CoinName const coin_names[] = {
|
||||
{ "monero", Coin::MONERO },
|
||||
{ "xmr", Coin::MONERO },
|
||||
{ "arqma", Coin::ARQ },
|
||||
{ "arq", Coin::ARQ },
|
||||
{ "dero", Coin::DERO },
|
||||
{ "keva", Coin::KEVA },
|
||||
{ "ravencoin", Coin::RAVEN },
|
||||
{ "raven", Coin::RAVEN },
|
||||
{ "rvn", Coin::RAVEN },
|
||||
{ "conceal", Coin::CONCEAL },
|
||||
{ "wownero", Coin::WOWNERO }
|
||||
static const CoinInfo coinInfo[] = {
|
||||
{ Algorithm::INVALID, nullptr, nullptr, 0, 0, nullptr },
|
||||
{ Algorithm::RX_0, "XMR", "Monero", 120, 1000000000000, YELLOW_BG_BOLD( WHITE_BOLD_S " monero ") },
|
||||
{ Algorithm::CN_R, "SUMO", "Sumokoin", 240, 1000000000, BLUE_BG_BOLD( WHITE_BOLD_S " sumo ") },
|
||||
{ Algorithm::RX_ARQ, "ARQ", "ArQmA", 120, 1000000000, BLUE_BG_BOLD( WHITE_BOLD_S " arqma ") },
|
||||
{ Algorithm::ASTROBWT_DERO, "DERO", "DERO", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " dero ") },
|
||||
{ Algorithm::RX_GRAFT, "GRFT", "Graft", 120, 10000000000, BLUE_BG_BOLD( WHITE_BOLD_S " graft ") },
|
||||
{ Algorithm::RX_KEVA, "KVA", "Kevacoin", 0, 0, MAGENTA_BG_BOLD(WHITE_BOLD_S " keva ") },
|
||||
{ Algorithm::KAWPOW_RVN, "RVN", "Ravencoin", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " raven ") },
|
||||
{ Algorithm::RX_WOW, "WOW", "Wownero", 300, 100000000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " wownero ") },
|
||||
};
|
||||
|
||||
|
||||
static_assert(Coin::MAX == sizeof(coinInfo) / sizeof(coinInfo[0]), "size mismatch");
|
||||
|
||||
|
||||
const char *Coin::kDisabled = "DISABLED_COIN";
|
||||
const char *Coin::kField = "coin";
|
||||
const char *Coin::kUnknown = "UNKNOWN_COIN";
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
|
||||
xmrig::Algorithm::Id xmrig::Coin::algorithm(uint8_t blobVersion) const
|
||||
xmrig::Coin::Coin(const rapidjson::Value &value)
|
||||
{
|
||||
switch (id()) {
|
||||
case MONERO:
|
||||
return (blobVersion >= 12) ? Algorithm::RX_0 : Algorithm::CN_R;
|
||||
|
||||
case ARQ:
|
||||
return (blobVersion >= 15) ? Algorithm::RX_ARQ : Algorithm::CN_PICO_0;
|
||||
|
||||
case DERO:
|
||||
return (blobVersion >= 4) ? Algorithm::ASTROBWT_DERO : Algorithm::CN_0;
|
||||
|
||||
case KEVA:
|
||||
return (blobVersion >= 11) ? Algorithm::RX_KEVA : Algorithm::CN_R;
|
||||
|
||||
case RAVEN:
|
||||
return Algorithm::KAWPOW_RVN;
|
||||
|
||||
case CONCEAL:
|
||||
return Algorithm::CN_CCX;
|
||||
|
||||
case WOWNERO:
|
||||
return Algorithm::RX_WOW;
|
||||
|
||||
case INVALID:
|
||||
break;
|
||||
if (value.IsString()) {
|
||||
m_id = parse(value.GetString());
|
||||
}
|
||||
else if (value.IsObject() && !value.ObjectEmpty()) {
|
||||
m_id = parse(Json::getString(value, kField));
|
||||
}
|
||||
|
||||
return Algorithm::INVALID;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Algorithm xmrig::Coin::algorithm(uint8_t) const
|
||||
{
|
||||
return coinInfo[m_id].algorithm;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Coin::code() const
|
||||
{
|
||||
return coinInfo[m_id].code;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Coin::name() const
|
||||
{
|
||||
for (const auto &i : coin_names) {
|
||||
if (i.id == m_id) {
|
||||
return i.name;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return coinInfo[m_id].name;
|
||||
}
|
||||
|
||||
|
||||
|
@ -114,7 +100,19 @@ rapidjson::Value xmrig::Coin::toJSON() const
|
|||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
return isValid() ? Value(StringRef(name())) : Value(kNullType);
|
||||
return isValid() ? Value(StringRef(code())) : Value(kNullType);
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Coin::target(uint8_t) const
|
||||
{
|
||||
return coinInfo[m_id].target;
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Coin::units() const
|
||||
{
|
||||
return coinInfo[m_id].units;
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,11 +122,17 @@ xmrig::Coin::Id xmrig::Coin::parse(const char *name)
|
|||
return INVALID;
|
||||
}
|
||||
|
||||
for (const auto &i : coin_names) {
|
||||
if (strcasecmp(name, i.name) == 0) {
|
||||
return i.id;
|
||||
for (uint32_t i = 1; i < MAX; ++i) {
|
||||
if (strcasecmp(name, coinInfo[i].code) == 0 || strcasecmp(name, coinInfo[i].name) == 0) {
|
||||
return static_cast<Id>(i);
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Coin::tag(Id id)
|
||||
{
|
||||
return coinInfo[id].tag;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -37,38 +30,53 @@ namespace xmrig {
|
|||
class Coin
|
||||
{
|
||||
public:
|
||||
enum Id : int {
|
||||
INVALID = -1,
|
||||
enum Id : uint32_t {
|
||||
INVALID,
|
||||
MONERO,
|
||||
ARQ,
|
||||
SUMO,
|
||||
ARQMA,
|
||||
DERO,
|
||||
GRAFT,
|
||||
KEVA,
|
||||
RAVEN,
|
||||
CONCEAL,
|
||||
WOWNERO
|
||||
WOWNERO,
|
||||
MAX
|
||||
};
|
||||
|
||||
static const char *kDisabled;
|
||||
static const char *kField;
|
||||
static const char *kUnknown;
|
||||
|
||||
Coin() = default;
|
||||
inline Coin(const char *name) : m_id(parse(name)) {}
|
||||
inline Coin(Id id) : m_id(id) {}
|
||||
Coin(const rapidjson::Value &value);
|
||||
inline Coin(const char *name) : m_id(parse(name)) {}
|
||||
inline Coin(Id id) : m_id(id) {}
|
||||
inline Coin(uint32_t id) : m_id(id < MAX ? static_cast<Id>(id) : INVALID) {}
|
||||
|
||||
|
||||
inline bool isEqual(const Coin &other) const { return m_id == other.m_id; }
|
||||
inline bool isValid() const { return m_id != INVALID; }
|
||||
inline Id id() const { return m_id; }
|
||||
inline bool isEqual(const Coin &other) const { return m_id == other.m_id; }
|
||||
inline bool isValid() const { return m_id != INVALID; }
|
||||
inline Id id() const { return m_id; }
|
||||
inline const char *tag() const { return tag(m_id); }
|
||||
inline double decimal(uint64_t amount) const { return static_cast<double>(amount) / units(); }
|
||||
|
||||
Algorithm::Id algorithm(uint8_t blobVersion = 255) const;
|
||||
Algorithm algorithm(uint8_t blobVersion = 255) const;
|
||||
const char *code() const;
|
||||
const char *name() const;
|
||||
rapidjson::Value toJSON() const;
|
||||
uint64_t target(uint8_t blobVersion = 255) const;
|
||||
uint64_t units() const;
|
||||
|
||||
inline bool operator!=(Coin::Id id) const { return m_id != id; }
|
||||
inline bool operator!=(const Coin &other) const { return !isEqual(other); }
|
||||
inline bool operator==(Coin::Id id) const { return m_id == id; }
|
||||
inline bool operator==(const Coin &other) const { return isEqual(other); }
|
||||
inline operator Coin::Id() const { return m_id; }
|
||||
inline bool operator!=(Id id) const { return m_id != id; }
|
||||
inline bool operator!=(const Coin &other) const { return !isEqual(other); }
|
||||
inline bool operator<(Id id) const { return m_id < id; }
|
||||
inline bool operator<(const Coin &other) const { return m_id < other.m_id; }
|
||||
inline bool operator==(Id id) const { return m_id == id; }
|
||||
inline bool operator==(const Coin &other) const { return isEqual(other); }
|
||||
inline operator Id() const { return m_id; }
|
||||
|
||||
static Id parse(const char *name);
|
||||
static const char *tag(Id id);
|
||||
|
||||
private:
|
||||
Id m_id = INVALID;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/Console.h"
|
||||
#include "base/kernel/interfaces/IConsoleListener.h"
|
||||
#include "base/tools/Handle.h"
|
||||
|
@ -50,7 +49,7 @@ xmrig::Console::~Console()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Console::isSupported() const
|
||||
bool xmrig::Console::isSupported()
|
||||
{
|
||||
const uv_handle_type type = uv_guess_handle(0);
|
||||
return type == UV_TTY || type == UV_NAMED_PIPE;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
~Console();
|
||||
|
||||
private:
|
||||
bool isSupported() const;
|
||||
static bool isSupported();
|
||||
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/Env.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "version.h"
|
||||
|
@ -61,7 +60,7 @@ static void createVariables()
|
|||
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
|
||||
|
||||
String hostname = "HOSTNAME";
|
||||
if (!getenv(hostname)) {
|
||||
if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe)
|
||||
variables.insert({ std::move(hostname), Env::hostname() });
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +136,7 @@ xmrig::String xmrig::Env::get(const String &name, const std::map<String, String>
|
|||
}
|
||||
# endif
|
||||
|
||||
return static_cast<const char *>(getenv(name));
|
||||
return static_cast<const char *>(getenv(name)); // NOLINT(concurrency-mt-unsafe)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/json/Json.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
|
||||
|
@ -30,7 +29,7 @@ namespace xmrig {
|
|||
|
||||
static const rapidjson::Value kNullValue;
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/json/JsonChain.h"
|
||||
#include "3rdparty/rapidjson/error/en.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
@ -27,7 +26,7 @@ namespace xmrig {
|
|||
|
||||
static const rapidjson::Value kNullValue;
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::JsonChain::JsonChain() = default;
|
||||
|
@ -58,8 +57,8 @@ bool xmrig::JsonChain::addFile(const char *fileName)
|
|||
if (doc.HasParseError()) {
|
||||
const size_t offset = doc.GetErrorOffset();
|
||||
|
||||
size_t line;
|
||||
size_t pos;
|
||||
size_t line = 0;
|
||||
size_t pos = 0;
|
||||
std::vector<std::string> s;
|
||||
|
||||
if (Json::convertOffset(fileName, offset, line, pos, s)) {
|
||||
|
@ -175,7 +174,6 @@ const rapidjson::Value &xmrig::JsonChain::getValue(const char *key) const
|
|||
}
|
||||
|
||||
|
||||
|
||||
const rapidjson::Value &xmrig::JsonChain::object() const
|
||||
{
|
||||
assert(false);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/json/JsonRequest.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -17,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <windows.h>
|
||||
|
@ -103,7 +102,7 @@ public:
|
|||
endl(size);
|
||||
|
||||
std::string txt(m_buf);
|
||||
size_t i;
|
||||
size_t i = 0;
|
||||
while ((i = txt.find(CSI)) != std::string::npos) {
|
||||
txt.erase(i, txt.find('m', i) - i + 1);
|
||||
}
|
||||
|
@ -232,7 +231,7 @@ void xmrig::Log::print(const char *fmt, ...)
|
|||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_list args{};
|
||||
va_start(args, fmt);
|
||||
|
||||
d->print(NONE, fmt, args);
|
||||
|
@ -247,7 +246,7 @@ void xmrig::Log::print(Level level, const char *fmt, ...)
|
|||
return;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_list args{};
|
||||
va_start(args, fmt);
|
||||
|
||||
d->print(level, fmt, args);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -17,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/log/backends/ConsoleLog.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/config/Title.h"
|
||||
|
@ -47,7 +46,7 @@ xmrig::ConsoleLog::ConsoleLog(const Title &title)
|
|||
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
||||
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
|
||||
DWORD mode = 0;
|
||||
if (GetConsoleMode(handle, &mode)) {
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
|
@ -91,7 +90,7 @@ void xmrig::ConsoleLog::print(uint64_t, int, const char *line, size_t, size_t si
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::ConsoleLog::isSupported() const
|
||||
bool xmrig::ConsoleLog::isSupported()
|
||||
{
|
||||
const uv_handle_type type = uv_guess_handle(1);
|
||||
return type == UV_TTY || type == UV_NAMED_PIPE;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -47,7 +47,7 @@ protected:
|
|||
void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) override;
|
||||
|
||||
private:
|
||||
bool isSupported() const;
|
||||
static bool isSupported();
|
||||
|
||||
uv_tty_t *m_tty = nullptr;
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -22,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
|
@ -76,7 +69,7 @@ public:
|
|||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(BasePrivate)
|
||||
|
||||
|
||||
inline BasePrivate(Process *process)
|
||||
inline explicit BasePrivate(Process *process)
|
||||
{
|
||||
Log::init();
|
||||
|
||||
|
@ -97,7 +90,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline bool read(const JsonChain &chain, std::unique_ptr<Config> &config)
|
||||
inline static bool read(const JsonChain &chain, std::unique_ptr<Config> &config)
|
||||
{
|
||||
config = std::unique_ptr<Config>(new Config());
|
||||
|
||||
|
@ -125,7 +118,7 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
inline Config *load(Process *process)
|
||||
inline static Config *load(Process *process)
|
||||
{
|
||||
JsonChain chain;
|
||||
ConfigTransform transform;
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -109,7 +109,7 @@ static int exportTopology(const Process &)
|
|||
{
|
||||
const String path = Process::location(Process::ExeLocation, "topology.xml");
|
||||
|
||||
hwloc_topology_t topology;
|
||||
hwloc_topology_t topology = nullptr;
|
||||
hwloc_topology_init(&topology);
|
||||
hwloc_topology_load(topology);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
static inline OSVERSIONINFOEX winOsVersion()
|
||||
{
|
||||
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
|
||||
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); // NOLINT(modernize-use-using)
|
||||
OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
|
||||
|
||||
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
|
||||
|
@ -61,9 +61,9 @@ char *xmrig::Platform::createUserAgent()
|
|||
# endif
|
||||
|
||||
# ifdef __GNUC__
|
||||
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif _MSC_VER
|
||||
length += snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
|
||||
snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
return buf;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <uv.h>
|
||||
|
@ -80,7 +79,7 @@ static std::string getPath(Process::Location location)
|
|||
return {};
|
||||
}
|
||||
|
||||
const auto path = std::string(pathBuf, size);
|
||||
auto path = std::string(pathBuf, size);
|
||||
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -100,7 +100,7 @@ public:
|
|||
bool read(const IJsonReader &reader, const char *fileName) override;
|
||||
bool save() override;
|
||||
|
||||
void printVersions();
|
||||
static void printVersions();
|
||||
|
||||
protected:
|
||||
bool m_autoSave = true;
|
||||
|
@ -129,7 +129,7 @@ protected:
|
|||
# endif
|
||||
|
||||
private:
|
||||
void setVerbose(const rapidjson::Value &value);
|
||||
static void setVerbose(const rapidjson::Value &value);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
|
@ -48,14 +47,14 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans
|
|||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
int key;
|
||||
int key = 0;
|
||||
int argc = process->arguments().argc();
|
||||
char **argv = process->arguments().argv();
|
||||
|
||||
Document doc(kObjectType);
|
||||
|
||||
while (true) {
|
||||
key = getopt_long(argc, argv, short_options, options, nullptr);
|
||||
key = getopt_long(argc, argv, short_options, options, nullptr); // NOLINT(concurrency-mt-unsafe)
|
||||
if (key < 0) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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,6 +21,7 @@
|
|||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <functional>
|
||||
|
@ -46,6 +41,8 @@ class String;
|
|||
class IClient
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(IClient)
|
||||
|
||||
enum Extension {
|
||||
EXT_ALGO,
|
||||
EXT_NICEHASH,
|
||||
|
@ -57,7 +54,8 @@ public:
|
|||
|
||||
using Callback = std::function<void(const rapidjson::Value &result, bool success, uint64_t elapsed)>;
|
||||
|
||||
virtual ~IClient() = default;
|
||||
IClient() = default;
|
||||
virtual ~IClient() = default;
|
||||
|
||||
virtual bool disconnect() = 0;
|
||||
virtual bool hasExtension(Extension extension) const noexcept = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/dns/DnsConfig.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
static const char *kTTL;
|
||||
|
||||
DnsConfig() = default;
|
||||
DnsConfig(const rapidjson::Value &object);
|
||||
DnsConfig(const rapidjson::Value &value);
|
||||
|
||||
inline bool isIPv6() const { return m_ipv6; }
|
||||
inline uint32_t ttl() const { return m_ttl * 1000U; }
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
@ -36,11 +35,11 @@ const xmrig::DnsRecord &xmrig::DnsRecords::get(DnsRecord::Type prefered) const
|
|||
const size_t ipv6 = m_ipv6.size();
|
||||
|
||||
if (ipv6 && (prefered == DnsRecord::AAAA || Dns::config().isIPv6() || !ipv4)) {
|
||||
return m_ipv6[ipv6 == 1 ? 0 : static_cast<size_t>(rand()) % ipv6];
|
||||
return m_ipv6[ipv6 == 1 ? 0 : static_cast<size_t>(rand()) % ipv6]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp)
|
||||
}
|
||||
|
||||
if (ipv4) {
|
||||
return m_ipv4[ipv4 == 1 ? 0 : static_cast<size_t>(rand()) % ipv4];
|
||||
return m_ipv4[ipv4 == 1 ? 0 : static_cast<size_t>(rand()) % ipv4]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp)
|
||||
}
|
||||
|
||||
return defaultRecord;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/Fetch.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "3rdparty/rapidjson/stringbuffer.h"
|
||||
|
@ -106,7 +105,7 @@ void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttp
|
|||
}
|
||||
# endif
|
||||
|
||||
HttpClient *client;
|
||||
HttpClient *client = nullptr;
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (req.tls) {
|
||||
client = new HttpsClient(tag, std::move(req), listener);
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -22,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/Http.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
@ -39,7 +32,7 @@ const char *Http::kRestricted = "restricted";
|
|||
const char *Http::kToken = "access-token";
|
||||
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Http::Http() :
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -22,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTP_H
|
||||
#define XMRIG_HTTP_H
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert)
|
|||
}
|
||||
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen;
|
||||
unsigned int dlen = 0;
|
||||
|
||||
if (X509_digest(cert, digest, md, &dlen) != 1) {
|
||||
return false;
|
||||
|
@ -189,7 +189,7 @@ void xmrig::HttpsClient::flush(bool close)
|
|||
}
|
||||
|
||||
char *data = nullptr;
|
||||
const size_t size = BIO_get_mem_data(m_write, &data);
|
||||
const size_t size = BIO_get_mem_data(m_write, &data); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
|
||||
std::string body(data, size);
|
||||
|
||||
(void) BIO_reset(m_write);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/https/HttpsContext.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
|
@ -61,7 +60,7 @@ bool xmrig::HttpsContext::write(BIO *bio)
|
|||
}
|
||||
|
||||
char *data = nullptr;
|
||||
const size_t size = BIO_get_mem_data(bio, &data);
|
||||
const size_t size = BIO_get_mem_data(bio, &data); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
|
||||
std::string body(data, size);
|
||||
|
||||
(void) BIO_reset(bio);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
@ -53,7 +52,7 @@ void xmrig::HttpsServer::onConnection(uv_stream_t *stream, uint16_t)
|
|||
auto ctx = new HttpsContext(m_tls, m_listener);
|
||||
uv_accept(stream, ctx->stream());
|
||||
|
||||
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead);
|
||||
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPSSERVER_H
|
||||
#define XMRIG_HTTPSSERVER_H
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/AutoClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
@ -32,7 +31,7 @@ xmrig::AutoClient::AutoClient(int id, const char *agent, IClientListener *listen
|
|||
bool xmrig::AutoClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
|
||||
{
|
||||
if (m_mode == DEFAULT_MODE) {
|
||||
return Client::handleResponse(id, result, error);
|
||||
return Client::handleResponse(id, result, error); // NOLINT(bugprone-parent-virtual-call)
|
||||
}
|
||||
|
||||
return EthStratumClient::handleResponse(id, result, error);
|
||||
|
@ -74,7 +73,7 @@ bool xmrig::AutoClient::parseLogin(const rapidjson::Value &result, int *code)
|
|||
int64_t xmrig::AutoClient::submit(const JobResult &result)
|
||||
{
|
||||
if (result.algorithm.family() != Algorithm::KAWPOW) {
|
||||
return Client::submit(result);
|
||||
return Client::submit(result); // NOLINT(bugprone-parent-virtual-call)
|
||||
}
|
||||
|
||||
return EthStratumClient::submit(result);
|
||||
|
@ -85,7 +84,7 @@ void xmrig::AutoClient::parseNotification(const char *method, const rapidjson::V
|
|||
{
|
||||
if (strcmp(method, "job") == 0) {
|
||||
m_mode = DEFAULT_MODE;
|
||||
return Client::parseNotification(method, params, error);
|
||||
return Client::parseNotification(method, params, error); // NOLINT(bugprone-parent-virtual-call)
|
||||
}
|
||||
|
||||
m_mode = ETH_MODE;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -22,8 +16,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
@ -58,7 +52,7 @@ void xmrig::BaseClient::setPool(const Pool &pool)
|
|||
m_user = Env::expand(pool.user());
|
||||
m_password = Env::expand(pool.password());
|
||||
m_rigId = Env::expand(pool.rigId());
|
||||
m_tag = std::string(Tags::network()) + " " CYAN_BOLD_S + m_pool.url().data() + CLEAR;
|
||||
m_tag = fmt::format("{} " CYAN_BOLD("{}"), Tags::network(), m_pool.url().data());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -351,32 +351,6 @@ bool xmrig::Client::close()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::isCriticalError(const char *message)
|
||||
{
|
||||
if (!message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "Unauthenticated", 15) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "your IP is banned", 17) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "IP Address currently banned", 27) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "Invalid job id", 14) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||
{
|
||||
if (!params.IsObject()) {
|
||||
|
@ -467,7 +441,7 @@ bool xmrig::Client::send(BIO *bio)
|
|||
{
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
uv_buf_t buf;
|
||||
buf.len = BIO_get_mem_data(bio, &buf.base);
|
||||
buf.len = BIO_get_mem_data(bio, &buf.base); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
|
||||
|
||||
if (buf.len == 0) {
|
||||
return true;
|
||||
|
@ -961,6 +935,32 @@ void xmrig::Client::startTimeout()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::isCriticalError(const char *message)
|
||||
{
|
||||
if (!message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "Unauthenticated", 15) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "your IP is banned", 17) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "IP Address currently banned", 27) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strncasecmp(message, "Invalid job id", 14) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Client::onClose(uv_handle_t *handle)
|
||||
{
|
||||
auto client = getClient(handle->data);
|
||||
|
|
|
@ -96,7 +96,6 @@ private:
|
|||
class Socks5;
|
||||
class Tls;
|
||||
|
||||
bool isCriticalError(const char *message);
|
||||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
||||
bool send(BIO *bio);
|
||||
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
|
||||
|
@ -119,6 +118,7 @@ private:
|
|||
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
|
||||
static bool isCriticalError(const char *message);
|
||||
static void onClose(uv_handle_t *handle);
|
||||
static void onConnect(uv_connect_t *req, int status);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/net/stratum/DaemonClient.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "3rdparty/rapidjson/error/en.h"
|
||||
|
@ -42,7 +45,6 @@
|
|||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "base/tools/cryptonote/Signatures.h"
|
||||
#include "base/tools/cryptonote/WalletAddress.h"
|
||||
#include "net/JobResult.h"
|
||||
|
||||
|
||||
|
@ -71,7 +73,7 @@ static constexpr size_t kZMQGreetingSize1 = 11;
|
|||
static const char kZMQHandshake[] = "\4\x19\5READY\xbSocket-Type\0\0\0\3SUB";
|
||||
static const char kZMQSubscribe[] = "\0\x18\1json-minimal-chain_main";
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) :
|
||||
|
@ -135,21 +137,21 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
|
||||
memcpy(data + m_job.nonceOffset() * 2, result.nonce, 8);
|
||||
|
||||
if (m_blocktemplate.has_miner_signature && result.sig) {
|
||||
if (m_blocktemplate.hasMinerSignature() && result.sig) {
|
||||
memcpy(data + sig_offset * 2, result.sig, 64 * 2);
|
||||
memcpy(data + m_blocktemplate.tx_pubkey_index * 2, result.sig_data, 32 * 2);
|
||||
memcpy(data + m_blocktemplate.eph_public_key_index * 2, result.sig_data + 32 * 2, 32 * 2);
|
||||
memcpy(data + m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) * 2, result.sig_data, 32 * 2);
|
||||
memcpy(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2, result.sig_data + 32 * 2, 32 * 2);
|
||||
}
|
||||
|
||||
if (result.extra_nonce >= 0) {
|
||||
Cvt::toHex(data + m_blocktemplate.tx_extra_nonce_index * 2, 8, reinterpret_cast<const uint8_t*>(&result.extra_nonce), 4);
|
||||
Cvt::toHex(data + m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) * 2, 8, reinterpret_cast<const uint8_t*>(&result.extra_nonce), 4);
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
Cvt::toHex(data + m_job.nonceOffset() * 2, 8, reinterpret_cast<const uint8_t*>(&result.nonce), 4);
|
||||
|
||||
if (m_blocktemplate.has_miner_signature) {
|
||||
if (m_blocktemplate.hasMinerSignature()) {
|
||||
Cvt::toHex(data + sig_offset * 2, 128, result.minerSignature(), 64);
|
||||
}
|
||||
|
||||
|
@ -181,12 +183,28 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
|
||||
void xmrig::DaemonClient::connect()
|
||||
{
|
||||
if ((m_pool.algorithm() == Algorithm::ASTROBWT_DERO) || (m_pool.coin() == Coin::DERO)) {
|
||||
m_apiVersion = API_DERO;
|
||||
}
|
||||
auto connectError = [this](const char *message) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("%s " RED("connect error: ") RED_BOLD("\"%s\""), tag(), message);
|
||||
}
|
||||
|
||||
retry();
|
||||
};
|
||||
|
||||
setState(ConnectingState);
|
||||
|
||||
if (!m_walletAddress.isValid()) {
|
||||
return connectError("Invalid wallet address.");
|
||||
}
|
||||
|
||||
if (!m_coin.isValid() && !m_pool.algorithm().isValid()) {
|
||||
return connectError("Invalid algorithm.");
|
||||
}
|
||||
|
||||
if ((m_pool.algorithm() == Algorithm::ASTROBWT_DERO) || (m_coin == Coin::DERO)) {
|
||||
m_apiVersion = API_DERO;
|
||||
}
|
||||
|
||||
if (m_pool.zmq_port() >= 0) {
|
||||
m_dns = Dns::resolve(m_pool.host(), this);
|
||||
}
|
||||
|
@ -203,6 +221,20 @@ void xmrig::DaemonClient::connect(const Pool &pool)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::setPool(const Pool &pool)
|
||||
{
|
||||
BaseClient::setPool(pool);
|
||||
|
||||
m_walletAddress.decode(m_user);
|
||||
|
||||
m_coin = pool.coin().isValid() ? pool.coin() : m_walletAddress.coin();
|
||||
|
||||
if (!m_coin.isValid() && pool.algorithm() == Algorithm::RX_WOW) {
|
||||
m_coin = Coin::WOWNERO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
||||
{
|
||||
if (data.status != 200) {
|
||||
|
@ -219,7 +251,7 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
|||
rapidjson::Document doc;
|
||||
if (doc.Parse(data.body.c_str()).HasParseError()) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("[%s:%d] JSON decode failed: \"%s\"", m_pool.host().data(), m_pool.port(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
LOG_ERR("%s " RED("JSON decode failed: ") RED_BOLD("\"%s\""), tag(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
}
|
||||
|
||||
return retry();
|
||||
|
@ -284,7 +316,7 @@ void xmrig::DaemonClient::onTimer(const Timer *)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::DaemonClient::onResolved(const DnsRecords& records, int status, const char* error)
|
||||
void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, const char* error)
|
||||
{
|
||||
m_dns.reset();
|
||||
|
||||
|
@ -297,14 +329,14 @@ void xmrig::DaemonClient::onResolved(const DnsRecords& records, int status, cons
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_ZMQSocket) {
|
||||
delete m_ZMQSocket;
|
||||
}
|
||||
|
||||
const auto& record = records.get();
|
||||
delete m_ZMQSocket;
|
||||
|
||||
|
||||
const auto &record = records.get();
|
||||
m_ip = record.ip();
|
||||
|
||||
uv_connect_t* req = new uv_connect_t;
|
||||
auto req = new uv_connect_t;
|
||||
req->data = m_storage.ptr(m_key);
|
||||
|
||||
m_ZMQSocket = new uv_tcp_t;
|
||||
|
@ -329,68 +361,60 @@ bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
|
|||
|
||||
bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||
{
|
||||
auto jobError = [this, code](const char *message) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("%s " RED("job error: ") RED_BOLD("\"%s\""), tag(), message);
|
||||
}
|
||||
|
||||
*code = 1;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Job job(false, m_pool.algorithm(), String());
|
||||
|
||||
String blocktemplate = Json::getString(params, kBlocktemplateBlob);
|
||||
|
||||
if (blocktemplate.isNull()) {
|
||||
LOG_ERR("Empty block template received from daemon");
|
||||
*code = 1;
|
||||
return false;
|
||||
return jobError("Empty block template received from daemon."); // FIXME
|
||||
}
|
||||
|
||||
Coin pool_coin = m_pool.coin();
|
||||
|
||||
if (!pool_coin.isValid() && (m_pool.algorithm() == Algorithm::RX_WOW)) {
|
||||
pool_coin = Coin::WOWNERO;
|
||||
}
|
||||
|
||||
if (!m_blocktemplate.Init(blocktemplate, pool_coin)) {
|
||||
LOG_ERR("Invalid block template received from daemon");
|
||||
*code = 2;
|
||||
return false;
|
||||
if (!m_blocktemplate.parse(blocktemplate, m_coin)) {
|
||||
return jobError("Invalid block template received from daemon.");
|
||||
}
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
const size_t k = m_blocktemplate.miner_tx_prefix_begin_index;
|
||||
const size_t k = m_blocktemplate.offset(BlockTemplate::MINER_TX_PREFIX_OFFSET);
|
||||
job.setMinerTx(
|
||||
m_blocktemplate.raw_blob.data() + k,
|
||||
m_blocktemplate.raw_blob.data() + m_blocktemplate.miner_tx_prefix_end_index,
|
||||
m_blocktemplate.eph_public_key_index - k,
|
||||
m_blocktemplate.tx_pubkey_index - k,
|
||||
m_blocktemplate.tx_extra_nonce_index - k,
|
||||
m_blocktemplate.tx_extra_nonce_size,
|
||||
m_blocktemplate.miner_tx_merkle_tree_branch
|
||||
m_blocktemplate.blob() + k,
|
||||
m_blocktemplate.blob() + m_blocktemplate.offset(BlockTemplate::MINER_TX_PREFIX_END_OFFSET),
|
||||
m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) - k,
|
||||
m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) - k,
|
||||
m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) - k,
|
||||
m_blocktemplate.txExtraNonce().size(),
|
||||
m_blocktemplate.minerTxMerkleTreeBranch()
|
||||
);
|
||||
# endif
|
||||
|
||||
m_blockhashingblob = Json::getString(params, "blockhashing_blob");
|
||||
|
||||
if (m_blocktemplate.has_miner_signature) {
|
||||
if (m_blocktemplate.hasMinerSignature()) {
|
||||
if (m_pool.spendSecretKey().isEmpty()) {
|
||||
LOG_ERR("Secret spend key is not set");
|
||||
*code = 4;
|
||||
return false;
|
||||
return jobError("Secret spend key is not set.");
|
||||
}
|
||||
|
||||
if (m_pool.spendSecretKey().size() != 64) {
|
||||
LOG_ERR("Secret spend key has invalid length. It must be 64 hex characters.");
|
||||
*code = 5;
|
||||
return false;
|
||||
return jobError("Secret spend key has invalid length. It must be 64 hex characters.");
|
||||
}
|
||||
|
||||
uint8_t secret_spendkey[32];
|
||||
if (!Cvt::fromHex(secret_spendkey, 32, m_pool.spendSecretKey(), 64)) {
|
||||
LOG_ERR("Secret spend key is not a valid hex data.");
|
||||
*code = 6;
|
||||
return false;
|
||||
return jobError("Secret spend key is not a valid hex data.");
|
||||
}
|
||||
|
||||
uint8_t public_spendkey[32];
|
||||
if (!secret_key_to_public_key(secret_spendkey, public_spendkey)) {
|
||||
LOG_ERR("Secret spend key is invalid.");
|
||||
*code = 7;
|
||||
return false;
|
||||
return jobError("Secret spend key is invalid.");
|
||||
}
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
|
@ -401,41 +425,30 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
|
||||
uint8_t public_viewkey[32];
|
||||
if (!secret_key_to_public_key(secret_viewkey, public_viewkey)) {
|
||||
LOG_ERR("Secret view key is invalid.");
|
||||
*code = 8;
|
||||
return false;
|
||||
return jobError("Secret view key is invalid.");
|
||||
}
|
||||
|
||||
uint8_t derivation[32];
|
||||
if (!generate_key_derivation(m_blocktemplate.raw_blob.data() + m_blocktemplate.tx_pubkey_index, secret_viewkey, derivation)) {
|
||||
LOG_ERR("Failed to generate key derivation for miner signature.");
|
||||
*code = 9;
|
||||
return false;
|
||||
if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation)) {
|
||||
return jobError("Failed to generate key derivation for miner signature.");
|
||||
}
|
||||
|
||||
WalletAddress user_address;
|
||||
if (!user_address.Decode(m_pool.user())) {
|
||||
LOG_ERR("Invalid wallet address.");
|
||||
*code = 10;
|
||||
return false;
|
||||
if (!m_walletAddress.decode(m_pool.user())) {
|
||||
return jobError("Invalid wallet address.");
|
||||
}
|
||||
|
||||
if (memcmp(user_address.public_spend_key, public_spendkey, sizeof(public_spendkey)) != 0) {
|
||||
LOG_ERR("Wallet address and spend key don't match.");
|
||||
*code = 11;
|
||||
return false;
|
||||
if (memcmp(m_walletAddress.spendKey(), public_spendkey, sizeof(public_spendkey)) != 0) {
|
||||
return jobError("Wallet address and spend key don't match.");
|
||||
}
|
||||
|
||||
if (memcmp(user_address.public_view_key, public_viewkey, sizeof(public_viewkey)) != 0) {
|
||||
LOG_ERR("Wallet address and view key don't match.");
|
||||
*code = 12;
|
||||
return false;
|
||||
if (memcmp(m_walletAddress.viewKey(), public_viewkey, sizeof(public_viewkey)) != 0) {
|
||||
return jobError("Wallet address and view key don't match.");
|
||||
}
|
||||
|
||||
uint8_t eph_secret_key[32];
|
||||
derive_secret_key(derivation, 0, secret_spendkey, eph_secret_key);
|
||||
|
||||
job.setEphemeralKeys(m_blocktemplate.raw_blob.data() + m_blocktemplate.eph_public_key_index, eph_secret_key);
|
||||
job.setEphemeralKeys(m_blocktemplate.blob(BlockTemplate::EPH_PUBLIC_KEY_OFFSET), eph_secret_key);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -444,8 +457,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
|
||||
}
|
||||
|
||||
if (pool_coin.isValid()) {
|
||||
job.setAlgorithm(pool_coin.algorithm(m_blocktemplate.major_version));
|
||||
if (m_coin.isValid()) {
|
||||
job.setAlgorithm(m_coin.algorithm(m_blocktemplate.majorVersion()));
|
||||
}
|
||||
|
||||
if (!job.setBlob(m_blockhashingblob)) {
|
||||
|
@ -594,7 +607,6 @@ void xmrig::DaemonClient::send(const char *path)
|
|||
|
||||
void xmrig::DaemonClient::setState(SocketState state)
|
||||
{
|
||||
assert(m_state != state);
|
||||
if (m_state == state) {
|
||||
return;
|
||||
}
|
||||
|
@ -735,10 +747,9 @@ void xmrig::DaemonClient::ZMQRead(ssize_t nread, const uv_buf_t* buf)
|
|||
m_ZMQConnectionState = ZMQ_GREETING_2;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format"), tag());
|
||||
ZMQClose();
|
||||
}
|
||||
|
||||
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format"), tag());
|
||||
ZMQClose();
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -751,10 +762,10 @@ void xmrig::DaemonClient::ZMQRead(ssize_t nread, const uv_buf_t* buf)
|
|||
ZMQWrite(kZMQHandshake, sizeof(kZMQHandshake) - 1);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format 2"), tag());
|
||||
ZMQClose();
|
||||
}
|
||||
|
||||
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format 2"), tag());
|
||||
ZMQClose();
|
||||
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -812,9 +823,9 @@ void xmrig::DaemonClient::ZMQParse()
|
|||
|
||||
size_t msg_size = 0;
|
||||
|
||||
char* data = m_ZMQRecvBuf.data();
|
||||
char *data = m_ZMQRecvBuf.data();
|
||||
size_t avail = m_ZMQRecvBuf.size();
|
||||
bool more;
|
||||
bool more = false;
|
||||
|
||||
do {
|
||||
if (avail < 1) {
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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,21 +21,25 @@
|
|||
#define XMRIG_DAEMONCLIENT_H
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IDnsListener.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "base/net/stratum/BaseClient.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/tools/cryptonote/BlockTemplate.h"
|
||||
#include "base/net/tools/Storage.h"
|
||||
#include "base/tools/cryptonote/BlockTemplate.h"
|
||||
#include "base/tools/cryptonote/WalletAddress.h"
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
using uv_buf_t = struct uv_buf_t;
|
||||
using uv_connect_t = struct uv_connect_s;
|
||||
using uv_handle_t = struct uv_handle_s;
|
||||
using uv_stream_t = struct uv_stream_s;
|
||||
using uv_tcp_t = struct uv_tcp_s;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
@ -62,10 +60,11 @@ protected:
|
|||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void connect(const Pool &pool) override;
|
||||
void setPool(const Pool &pool) override;
|
||||
|
||||
void onHttpData(const HttpData &data) override;
|
||||
void onTimer(const Timer *timer) override;
|
||||
void onResolved(const DnsRecords& records, int status, const char* error) override;
|
||||
void onResolved(const DnsRecords &records, int status, const char* error) override;
|
||||
|
||||
inline bool hasExtension(Extension) const noexcept override { return false; }
|
||||
inline const char *mode() const override { return "daemon"; }
|
||||
|
@ -92,18 +91,19 @@ private:
|
|||
API_DERO,
|
||||
} m_apiVersion = API_MONERO;
|
||||
|
||||
BlockTemplate m_blocktemplate;
|
||||
Coin m_coin;
|
||||
std::shared_ptr<IHttpListener> m_httpListener;
|
||||
String m_currentJobId;
|
||||
String m_blocktemplateStr;
|
||||
String m_blockhashingblob;
|
||||
String m_blocktemplateRequestHash;
|
||||
String m_blocktemplateStr;
|
||||
String m_currentJobId;
|
||||
String m_prevHash;
|
||||
String m_tlsFingerprint;
|
||||
String m_tlsVersion;
|
||||
Timer *m_timer;
|
||||
uint64_t m_blocktemplateRequestHeight = 0;
|
||||
String m_blocktemplateRequestHash;
|
||||
|
||||
BlockTemplate m_blocktemplate;
|
||||
WalletAddress m_walletAddress;
|
||||
|
||||
private:
|
||||
static inline DaemonClient* getClient(void* data) { return m_storage.get(data); }
|
||||
|
|
|
@ -272,7 +272,7 @@ void xmrig::EthStratumClient::setExtraNonce(const rapidjson::Value &nonce)
|
|||
}
|
||||
|
||||
|
||||
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error) const
|
||||
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error)
|
||||
{
|
||||
if (error.IsArray() && error.GetArray().Size() > 1) {
|
||||
auto &value = error.GetArray()[1];
|
||||
|
|
|
@ -48,7 +48,8 @@ protected:
|
|||
void setExtraNonce(const rapidjson::Value &nonce);
|
||||
|
||||
private:
|
||||
const char *errorMessage(const rapidjson::Value &error) const;
|
||||
static const char *errorMessage(const rapidjson::Value &error);
|
||||
|
||||
void authorize();
|
||||
void onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
|
||||
void onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
|
||||
|
|
|
@ -352,16 +352,16 @@ void xmrig::Job::generateHashingBlob(String &blob) const
|
|||
{
|
||||
uint8_t root_hash[32];
|
||||
const uint8_t* p = m_minerTxPrefix.data();
|
||||
BlockTemplate::CalculateRootHash(p, p + m_minerTxPrefix.size(), m_minerTxMerkleTreeBranch, root_hash);
|
||||
BlockTemplate::calculateRootHash(p, p + m_minerTxPrefix.size(), m_minerTxMerkleTreeBranch, root_hash);
|
||||
|
||||
uint64_t root_hash_offset = nonceOffset() + nonceSize();
|
||||
|
||||
if (m_hasMinerSignature) {
|
||||
root_hash_offset += BlockTemplate::SIGNATURE_SIZE + 2 /* vote */;
|
||||
root_hash_offset += BlockTemplate::kSignatureSize + 2 /* vote */;
|
||||
}
|
||||
|
||||
blob = rawBlob();
|
||||
Cvt::toHex(blob.data() + root_hash_offset * 2, 64, root_hash, BlockTemplate::HASH_SIZE);
|
||||
Cvt::toHex(blob.data() + root_hash_offset * 2, 64, root_hash, BlockTemplate::kHashSize);
|
||||
}
|
||||
|
||||
|
||||
|
@ -374,7 +374,7 @@ void xmrig::Job::generateMinerSignature(const uint8_t* blob, size_t size, uint8_
|
|||
memcpy(tmp, blob, size);
|
||||
|
||||
// Fill signature with zeros
|
||||
memset(tmp + nonceOffset() + nonceSize(), 0, BlockTemplate::SIGNATURE_SIZE);
|
||||
memset(tmp + nonceOffset() + nonceSize(), 0, BlockTemplate::kSignatureSize);
|
||||
|
||||
uint8_t prefix_hash[32];
|
||||
xmrig::keccak(tmp, static_cast<int>(size), prefix_hash, sizeof(prefix_hash));
|
||||
|
|
|
@ -82,7 +82,7 @@ const char *Pool::kSpendSecretKey = "spend-secret-key";
|
|||
const char *Pool::kNicehashHost = "nicehash.com";
|
||||
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Pool::Pool(const char *url) :
|
||||
|
@ -190,10 +190,6 @@ bool xmrig::Pool::isEnabled() const
|
|||
}
|
||||
# endif
|
||||
|
||||
if (m_mode == MODE_DAEMON && (!algorithm().isValid() && !coin().isValid())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_flags.test(FLAG_ENABLED) && isValid();
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,9 @@ void xmrig::Pools::setProxyDonate(int value)
|
|||
case PROXY_DONATE_AUTO:
|
||||
case PROXY_DONATE_ALWAYS:
|
||||
m_proxyDonate = static_cast<ProxyDonate>(value);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ void xmrig::Client::Socks5::handshake()
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr) const
|
||||
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr)
|
||||
{
|
||||
return uv_ip4_addr(host.data(), 0, reinterpret_cast<sockaddr_in *>(addr)) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr) const
|
||||
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr)
|
||||
{
|
||||
return uv_ip6_addr(host.data(), 0, reinterpret_cast<sockaddr_in6 *>(addr)) == 0;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,9 @@ private:
|
|||
Ready
|
||||
};
|
||||
|
||||
bool isIPv4(const String &host, sockaddr_storage *addr) const;
|
||||
bool isIPv6(const String &host, sockaddr_storage *addr) const;
|
||||
static bool isIPv4(const String &host, sockaddr_storage *addr);
|
||||
static bool isIPv6(const String &host, sockaddr_storage *addr);
|
||||
|
||||
void connect();
|
||||
|
||||
Client *m_client;
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/Tls.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
|
@ -177,7 +170,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
|
|||
}
|
||||
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen;
|
||||
unsigned int dlen = 0;
|
||||
|
||||
if (X509_digest(cert, digest, md, &dlen) != 1) {
|
||||
return false;
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/stratum/Url.h"
|
||||
|
||||
|
||||
|
@ -49,7 +41,7 @@ static const char kDaemonHttp[] = "daemon+http://";
|
|||
static const char kDaemonHttps[] = "daemon+https://";
|
||||
#endif
|
||||
|
||||
}
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Url::Url(const char *url)
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -249,7 +249,7 @@ uint64_t xmrig::BenchClient::referenceHash() const
|
|||
}
|
||||
|
||||
|
||||
void xmrig::BenchClient::printExit()
|
||||
void xmrig::BenchClient::printExit() const
|
||||
{
|
||||
LOG_INFO("%s " WHITE_BOLD("press ") MAGENTA_BOLD("Ctrl+C") WHITE_BOLD(" to exit"), tag());
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ private:
|
|||
|
||||
bool setSeed(const char *seed);
|
||||
uint64_t referenceHash() const;
|
||||
void printExit();
|
||||
void printExit() const;
|
||||
void start();
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsConfig.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -54,7 +48,7 @@ public:
|
|||
};
|
||||
|
||||
TlsConfig() = default;
|
||||
TlsConfig(const rapidjson::Value &object);
|
||||
TlsConfig(const rapidjson::Value &value);
|
||||
|
||||
inline bool isEnabled() const { return m_enabled && isValid(); }
|
||||
inline bool isValid() const { return !m_cert.isEmpty() && !m_key.isEmpty(); }
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
@ -223,7 +216,7 @@ bool xmrig::TlsContext::setDH(const char *dhparam)
|
|||
dh = get_dh2048();
|
||||
}
|
||||
|
||||
const int rc = SSL_CTX_set_tmp_dh(m_ctx, dh);
|
||||
const int rc = SSL_CTX_set_tmp_dh(m_ctx, dh); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
|
||||
|
||||
DH_free(dh);
|
||||
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsGen.h"
|
||||
|
||||
|
||||
|
@ -41,6 +40,8 @@ static EVP_PKEY *generate_pkey()
|
|||
|
||||
auto exponent = BN_new();
|
||||
auto rsa = RSA_new();
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
|
||||
if (!exponent || !rsa || !BN_set_word(exponent, RSA_F4) || !RSA_generate_key_ex(rsa, 2048, exponent, nullptr) || !EVP_PKEY_assign_RSA(pkey, rsa)) {
|
||||
EVP_PKEY_free(pkey);
|
||||
BN_free(exponent);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
|
||||
|
@ -37,9 +36,9 @@ namespace xmrig {
|
|||
static char *cvt_bin2hex(char *const hex, const size_t hex_maxlen, const unsigned char *const bin, const size_t bin_len)
|
||||
{
|
||||
size_t i = 0U;
|
||||
unsigned int x;
|
||||
int b;
|
||||
int c;
|
||||
unsigned int x = 0U;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
|
||||
if (bin_len >= SIZE_MAX / 2 || hex_maxlen < bin_len * 2U) {
|
||||
return nullptr; /* LCOV_EXCL_LINE */
|
||||
|
@ -71,17 +70,17 @@ static std::mt19937 randomEngine(randomDevice());
|
|||
|
||||
static int cvt_hex2bin(unsigned char *const bin, const size_t bin_maxlen, const char *const hex, const size_t hex_len, const char *const ignore, size_t *const bin_len, const char **const hex_end)
|
||||
{
|
||||
size_t bin_pos = 0U;
|
||||
size_t hex_pos = 0U;
|
||||
int ret = 0;
|
||||
unsigned char c;
|
||||
unsigned char c_acc = 0U;
|
||||
unsigned char c_alpha0;
|
||||
unsigned char c_alpha;
|
||||
unsigned char c_num0;
|
||||
unsigned char c_num;
|
||||
unsigned char c_val;
|
||||
unsigned char state = 0U;
|
||||
size_t bin_pos = 0U;
|
||||
size_t hex_pos = 0U;
|
||||
int ret = 0;
|
||||
unsigned char c = 0U;
|
||||
unsigned char c_acc = 0U;
|
||||
unsigned char c_alpha0 = 0U;
|
||||
unsigned char c_alpha = 0U;
|
||||
unsigned char c_num0 = 0U;
|
||||
unsigned char c_num = 0U;
|
||||
unsigned char c_val = 0U;
|
||||
unsigned char state = 0U;
|
||||
|
||||
while (hex_pos < hex_len) {
|
||||
c = (unsigned char) hex[hex_pos];
|
||||
|
@ -194,13 +193,13 @@ bool xmrig::Cvt::fromHex(uint8_t *bin, size_t bin_maxlen, const char *hex, size_
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Cvt::fromHex(uint8_t *bin, size_t max, const rapidjson::Value &value)
|
||||
bool xmrig::Cvt::fromHex(uint8_t *bin, size_t bin_maxlen, const rapidjson::Value &value)
|
||||
{
|
||||
if (!value.IsString()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fromHex(bin, max, value.GetString(), value.GetStringLength());
|
||||
return fromHex(bin, bin_maxlen, value.GetString(), value.GetStringLength());
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,6 +244,12 @@ rapidjson::Value xmrig::Cvt::toHex(const Buffer &data, rapidjson::Document &doc)
|
|||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Cvt::toHex(const Span &data, rapidjson::Document &doc)
|
||||
{
|
||||
return toHex(data.data(), data.size(), doc);
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Cvt::toHex(const std::string &data, rapidjson::Document &doc)
|
||||
{
|
||||
return toHex(reinterpret_cast<const uint8_t *>(data.data()), data.size(), doc);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Span.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
|
@ -37,9 +38,11 @@ public:
|
|||
inline static bool fromHex(Buffer &buf, const String &hex) { return fromHex(buf, hex.data(), hex.size()); }
|
||||
inline static Buffer fromHex(const std::string &hex) { return fromHex(hex.data(), hex.size()); }
|
||||
inline static Buffer fromHex(const String &hex) { return fromHex(hex.data(), hex.size()); }
|
||||
inline static String toHex(const Buffer &data) { return toHex(data.data(), data.size()); }
|
||||
inline static String toHex(const std::string &data) { return toHex(reinterpret_cast<const uint8_t *>(data.data()), data.size()); }
|
||||
|
||||
template<typename T>
|
||||
inline static String toHex(const T &data) { return toHex(data.data(), data.size()); }
|
||||
|
||||
static bool fromHex(Buffer &buf, const char *in, size_t size);
|
||||
static bool fromHex(Buffer &buf, const rapidjson::Value &value);
|
||||
static bool fromHex(std::string &buf, const char *in, size_t size);
|
||||
|
@ -49,6 +52,7 @@ public:
|
|||
static Buffer fromHex(const char *in, size_t size);
|
||||
static Buffer randomBytes(size_t size);
|
||||
static rapidjson::Value toHex(const Buffer &data, rapidjson::Document &doc);
|
||||
static rapidjson::Value toHex(const Span &data, rapidjson::Document &doc);
|
||||
static rapidjson::Value toHex(const std::string &data, rapidjson::Document &doc);
|
||||
static rapidjson::Value toHex(const uint8_t *in, size_t size, rapidjson::Document &doc);
|
||||
static String toHex(const uint8_t *in, size_t size);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
35
src/base/tools/Span.h
Normal file
35
src/base/tools/Span.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_SPAN_H
|
||||
#define XMRIG_SPAN_H
|
||||
|
||||
|
||||
#include "3rdparty/epee/span.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
using Span = epee::span<const uint8_t>;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_SPAN_H */
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -16,7 +16,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* XMRig
|
||||
* Copyright 2012-2013 The Cryptonote developers
|
||||
* Copyright 2014-2021 The Monero Project
|
||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2012-2013 The Cryptonote developers
|
||||
* Copyright (c) 2014-2021 The Monero Project
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,58 +23,77 @@
|
|||
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CBlobReader
|
||||
template<bool EXCEPTIONS>
|
||||
class BlobReader
|
||||
{
|
||||
public:
|
||||
inline CBlobReader(const void* data, size_t size)
|
||||
: m_data(reinterpret_cast<const uint8_t*>(data))
|
||||
, m_size(size)
|
||||
, m_index(0)
|
||||
inline BlobReader(const uint8_t *data, size_t size) :
|
||||
m_size(size),
|
||||
m_data(data)
|
||||
{}
|
||||
|
||||
inline bool operator()(uint8_t& data) { return getByte(data); }
|
||||
inline bool operator()(uint64_t& data) { return getVarint(data); }
|
||||
inline bool operator()(uint64_t &data) { return getVarint(data); }
|
||||
inline bool operator()(uint8_t &data) { return getByte(data); }
|
||||
inline size_t index() const { return m_index; }
|
||||
inline size_t remaining() const { return m_size - m_index; }
|
||||
|
||||
inline bool skip(size_t n)
|
||||
{
|
||||
if (m_index + n > m_size) {
|
||||
return outOfRange();
|
||||
}
|
||||
|
||||
m_index += n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
inline bool operator()(uint8_t(&data)[N])
|
||||
{
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (!getByte(data[i])) {
|
||||
return false;
|
||||
}
|
||||
if (m_index + N > m_size) {
|
||||
return outOfRange();
|
||||
}
|
||||
|
||||
memcpy(data, m_data + m_index, N);
|
||||
m_index += N;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void readItems(T& data, size_t count)
|
||||
inline bool operator()(T &data, size_t n)
|
||||
{
|
||||
data.resize(count);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
operator()(data[i]);
|
||||
}
|
||||
|
||||
inline size_t index() const { return m_index; }
|
||||
|
||||
inline void skip(size_t N) { m_index += N; }
|
||||
|
||||
private:
|
||||
inline bool getByte(uint8_t& data)
|
||||
{
|
||||
if (m_index >= m_size) {
|
||||
return false;
|
||||
if (m_index + n > m_size) {
|
||||
return outOfRange();
|
||||
}
|
||||
|
||||
data = m_data[m_index++];
|
||||
data = { m_data + m_index, n };
|
||||
m_index += n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool getVarint(uint64_t& data)
|
||||
private:
|
||||
inline bool getByte(uint8_t &data)
|
||||
{
|
||||
if (m_index >= m_size) {
|
||||
return outOfRange();
|
||||
}
|
||||
|
||||
data = m_data[m_index++];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool getVarint(uint64_t &data)
|
||||
{
|
||||
uint64_t result = 0;
|
||||
uint8_t t;
|
||||
|
@ -82,19 +101,30 @@ private:
|
|||
|
||||
do {
|
||||
if (!getByte(t)) {
|
||||
return false;
|
||||
return outOfRange();
|
||||
}
|
||||
|
||||
result |= static_cast<uint64_t>(t & 0x7F) << shift;
|
||||
shift += 7;
|
||||
} while (t & 0x80);
|
||||
|
||||
data = result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const uint8_t* m_data;
|
||||
size_t m_size;
|
||||
size_t m_index;
|
||||
inline bool outOfRange()
|
||||
{
|
||||
if (EXCEPTIONS) {
|
||||
throw std::out_of_range("Blob read out of range");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t m_size;
|
||||
const uint8_t *m_data;
|
||||
size_t m_index = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* XMRig
|
||||
* Copyright 2012-2013 The Cryptonote developers
|
||||
* Copyright 2014-2021 The Monero Project
|
||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2012-2013 The Cryptonote developers
|
||||
* Copyright (c) 2014-2021 The Monero Project
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -18,243 +18,290 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/cryptonote/BlobReader.h"
|
||||
#include "base/tools/cryptonote/BlockTemplate.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/tools/cryptonote/BlobReader.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
bool BlockTemplate::Init(const String& blockTemplate, Coin coin)
|
||||
void xmrig::BlockTemplate::calculateMinerTxHash(const uint8_t *prefix_begin, const uint8_t *prefix_end, uint8_t *hash)
|
||||
{
|
||||
raw_blob = Cvt::fromHex(blockTemplate);
|
||||
|
||||
CBlobReader ar(raw_blob.data(), raw_blob.size());
|
||||
|
||||
// Block header
|
||||
ar(major_version);
|
||||
ar(minor_version);
|
||||
ar(timestamp);
|
||||
ar(prev_id);
|
||||
ar(nonce);
|
||||
|
||||
// Wownero block template has miner signature starting from version 18
|
||||
has_miner_signature = (coin == Coin::WOWNERO) && (major_version >= 18);
|
||||
if (has_miner_signature) {
|
||||
ar(miner_signature);
|
||||
ar(vote);
|
||||
}
|
||||
|
||||
// Miner transaction begin
|
||||
// Prefix begin
|
||||
miner_tx_prefix_begin_index = ar.index();
|
||||
|
||||
ar(tx_version);
|
||||
ar(unlock_time);
|
||||
ar(num_inputs);
|
||||
|
||||
// must be 1 input
|
||||
if (num_inputs != 1)
|
||||
return false;
|
||||
|
||||
ar(input_type);
|
||||
|
||||
// input type must be txin_gen (0xFF)
|
||||
if (input_type != 0xFF)
|
||||
return false;
|
||||
|
||||
ar(height);
|
||||
|
||||
ar(num_outputs);
|
||||
|
||||
// must be 1 output
|
||||
if (num_outputs != 1)
|
||||
return false;
|
||||
|
||||
ar(amount);
|
||||
ar(output_type);
|
||||
|
||||
// output type must be txout_to_key (2)
|
||||
if (output_type != 2)
|
||||
return false;
|
||||
|
||||
eph_public_key_index = ar.index();
|
||||
|
||||
ar(eph_public_key);
|
||||
ar(extra_size);
|
||||
|
||||
const uint64_t tx_extra_index = ar.index();
|
||||
|
||||
ar.readItems(extra, extra_size);
|
||||
|
||||
CBlobReader ar_extra(extra.data(), extra_size);
|
||||
|
||||
tx_extra_nonce_size = 0;
|
||||
tx_extra_nonce_index = 0;
|
||||
|
||||
while (ar_extra.index() < extra_size) {
|
||||
uint64_t extra_tag = 0;
|
||||
ar_extra(extra_tag);
|
||||
|
||||
switch (extra_tag) {
|
||||
case 0x01: // TX_EXTRA_TAG_PUBKEY
|
||||
tx_pubkey_index = tx_extra_index + ar_extra.index();
|
||||
ar_extra.skip(KEY_SIZE);
|
||||
break;
|
||||
|
||||
case 0x02: // TX_EXTRA_NONCE
|
||||
ar_extra(tx_extra_nonce_size);
|
||||
tx_extra_nonce_index = tx_extra_index + ar_extra.index();
|
||||
ar_extra.skip(tx_extra_nonce_size);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false; // TODO: handle other tags
|
||||
}
|
||||
}
|
||||
|
||||
miner_tx_prefix_end_index = ar.index();
|
||||
// Prefix end
|
||||
|
||||
// RCT signatures (empty in miner transaction)
|
||||
ar(vin_rct_type);
|
||||
|
||||
// must be RCTTypeNull (0)
|
||||
if (vin_rct_type != 0)
|
||||
return false;
|
||||
|
||||
const size_t miner_tx_end = ar.index();
|
||||
// Miner transaction end
|
||||
|
||||
// Miner transaction must have exactly 1 byte with value 0 after the prefix
|
||||
if ((miner_tx_end != miner_tx_prefix_end_index + 1) || (raw_blob[miner_tx_prefix_end_index] != 0))
|
||||
return false;
|
||||
|
||||
// Other transaction hashes
|
||||
ar(num_hashes);
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
hashes.resize((num_hashes + 1) * HASH_SIZE);
|
||||
CalculateMinerTxHash(raw_blob.data() + miner_tx_prefix_begin_index, raw_blob.data() + miner_tx_prefix_end_index, hashes.data());
|
||||
|
||||
for (uint64_t i = 1; i <= num_hashes; ++i) {
|
||||
uint8_t h[HASH_SIZE];
|
||||
ar(h);
|
||||
memcpy(hashes.data() + i * HASH_SIZE, h, HASH_SIZE);
|
||||
}
|
||||
|
||||
CalculateMerkleTreeHash();
|
||||
# endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void BlockTemplate::CalculateMinerTxHash(const uint8_t* prefix_begin, const uint8_t* prefix_end, uint8_t* hash)
|
||||
{
|
||||
uint8_t hashes[HASH_SIZE * 3];
|
||||
uint8_t hashes[kHashSize * 3];
|
||||
|
||||
// Calculate 3 partial hashes
|
||||
|
||||
// 1. Prefix
|
||||
keccak(prefix_begin, static_cast<int>(prefix_end - prefix_begin), hashes, HASH_SIZE);
|
||||
keccak(prefix_begin, static_cast<int>(prefix_end - prefix_begin), hashes, kHashSize);
|
||||
|
||||
// 2. Base RCT, single 0 byte in miner tx
|
||||
static const uint8_t known_second_hash[HASH_SIZE] = {
|
||||
static const uint8_t known_second_hash[kHashSize] = {
|
||||
188,54,120,158,122,30,40,20,54,70,66,41,130,143,129,125,102,18,247,180,119,214,101,145,255,150,169,224,100,188,201,138
|
||||
};
|
||||
memcpy(hashes + HASH_SIZE, known_second_hash, HASH_SIZE);
|
||||
memcpy(hashes + kHashSize, known_second_hash, kHashSize);
|
||||
|
||||
// 3. Prunable RCT, empty in miner tx
|
||||
memset(hashes + HASH_SIZE * 2, 0, HASH_SIZE);
|
||||
memset(hashes + kHashSize * 2, 0, kHashSize);
|
||||
|
||||
// Calculate miner transaction hash
|
||||
keccak(hashes, sizeof(hashes), hash, HASH_SIZE);
|
||||
keccak(hashes, sizeof(hashes), hash, kHashSize);
|
||||
}
|
||||
|
||||
|
||||
void BlockTemplate::CalculateMerkleTreeHash()
|
||||
void xmrig::BlockTemplate::calculateRootHash(const uint8_t *prefix_begin, const uint8_t *prefix_end, const Buffer &miner_tx_merkle_tree_branch, uint8_t *root_hash)
|
||||
{
|
||||
miner_tx_merkle_tree_branch.clear();
|
||||
calculateMinerTxHash(prefix_begin, prefix_end, root_hash);
|
||||
|
||||
const uint64_t count = num_hashes + 1;
|
||||
uint8_t* h = hashes.data();
|
||||
for (size_t i = 0; i < miner_tx_merkle_tree_branch.size(); i += kHashSize) {
|
||||
uint8_t h[kHashSize * 2];
|
||||
|
||||
memcpy(h, root_hash, kHashSize);
|
||||
memcpy(h + kHashSize, miner_tx_merkle_tree_branch.data() + i, kHashSize);
|
||||
|
||||
keccak(h, kHashSize * 2, root_hash, kHashSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BlockTemplate::calculateMerkleTreeHash()
|
||||
{
|
||||
m_minerTxMerkleTreeBranch.clear();
|
||||
|
||||
const uint64_t count = m_numHashes + 1;
|
||||
const uint8_t *h = m_hashes.data();
|
||||
|
||||
if (count == 1) {
|
||||
memcpy(root_hash, h, HASH_SIZE);
|
||||
memcpy(m_rootHash, h, kHashSize);
|
||||
}
|
||||
else if (count == 2) {
|
||||
miner_tx_merkle_tree_branch.insert(miner_tx_merkle_tree_branch.end(), h + HASH_SIZE, h + HASH_SIZE * 2);
|
||||
keccak(h, HASH_SIZE * 2, root_hash, HASH_SIZE);
|
||||
m_minerTxMerkleTreeBranch.insert(m_minerTxMerkleTreeBranch.end(), h + kHashSize, h + kHashSize * 2);
|
||||
keccak(h, kHashSize * 2, m_rootHash, kHashSize);
|
||||
}
|
||||
else {
|
||||
size_t i, j, cnt;
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
size_t cnt = 0;
|
||||
|
||||
for (i = 0, cnt = 1; cnt <= count; ++i, cnt <<= 1) {}
|
||||
|
||||
cnt >>= 1;
|
||||
|
||||
miner_tx_merkle_tree_branch.reserve(HASH_SIZE * (i - 1));
|
||||
m_minerTxMerkleTreeBranch.reserve(kHashSize * (i - 1));
|
||||
|
||||
Buffer ints(cnt * HASH_SIZE);
|
||||
memcpy(ints.data(), h, (cnt * 2 - count) * HASH_SIZE);
|
||||
Buffer ints(cnt * kHashSize);
|
||||
memcpy(ints.data(), h, (cnt * 2 - count) * kHashSize);
|
||||
|
||||
for (i = cnt * 2 - count, j = cnt * 2 - count; j < cnt; i += 2, ++j) {
|
||||
if (i == 0) {
|
||||
miner_tx_merkle_tree_branch.insert(miner_tx_merkle_tree_branch.end(), h + HASH_SIZE, h + HASH_SIZE * 2);
|
||||
m_minerTxMerkleTreeBranch.insert(m_minerTxMerkleTreeBranch.end(), h + kHashSize, h + kHashSize * 2);
|
||||
}
|
||||
keccak(h + i * HASH_SIZE, HASH_SIZE * 2, ints.data() + j * HASH_SIZE, HASH_SIZE);
|
||||
keccak(h + i * kHashSize, kHashSize * 2, ints.data() + j * kHashSize, kHashSize);
|
||||
}
|
||||
|
||||
while (cnt > 2) {
|
||||
cnt >>= 1;
|
||||
for (i = 0, j = 0; j < cnt; i += 2, ++j) {
|
||||
if (i == 0) {
|
||||
miner_tx_merkle_tree_branch.insert(miner_tx_merkle_tree_branch.end(), ints.data() + HASH_SIZE, ints.data() + HASH_SIZE * 2);
|
||||
m_minerTxMerkleTreeBranch.insert(m_minerTxMerkleTreeBranch.end(), ints.data() + kHashSize, ints.data() + kHashSize * 2);
|
||||
}
|
||||
keccak(ints.data() + i * HASH_SIZE, HASH_SIZE * 2, ints.data() + j * HASH_SIZE, HASH_SIZE);
|
||||
keccak(ints.data() + i * kHashSize, kHashSize * 2, ints.data() + j * kHashSize, kHashSize);
|
||||
}
|
||||
}
|
||||
|
||||
miner_tx_merkle_tree_branch.insert(miner_tx_merkle_tree_branch.end(), ints.data() + HASH_SIZE, ints.data() + HASH_SIZE * 2);
|
||||
keccak(ints.data(), HASH_SIZE * 2, root_hash, HASH_SIZE);
|
||||
m_minerTxMerkleTreeBranch.insert(m_minerTxMerkleTreeBranch.end(), ints.data() + kHashSize, ints.data() + kHashSize * 2);
|
||||
keccak(ints.data(), kHashSize * 2, m_rootHash, kHashSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlockTemplate::CalculateRootHash(const uint8_t* prefix_begin, const uint8_t* prefix_end, const Buffer& miner_tx_merkle_tree_branch, uint8_t* root_hash)
|
||||
bool xmrig::BlockTemplate::parse(const Buffer &blocktemplate, const Coin &coin, bool hashes)
|
||||
{
|
||||
CalculateMinerTxHash(prefix_begin, prefix_end, root_hash);
|
||||
|
||||
for (size_t i = 0; i < miner_tx_merkle_tree_branch.size(); i += HASH_SIZE) {
|
||||
uint8_t h[HASH_SIZE * 2];
|
||||
|
||||
memcpy(h, root_hash, HASH_SIZE);
|
||||
memcpy(h + HASH_SIZE, miner_tx_merkle_tree_branch.data() + i, HASH_SIZE);
|
||||
|
||||
keccak(h, HASH_SIZE * 2, root_hash, HASH_SIZE);
|
||||
if (blocktemplate.size() < kMinSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_blob = blocktemplate;
|
||||
m_coin = coin;
|
||||
bool rc = false;
|
||||
|
||||
try {
|
||||
rc = parse(hashes);
|
||||
} catch (...) {}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void BlockTemplate::GenerateHashingBlob()
|
||||
bool xmrig::BlockTemplate::parse(const char *blocktemplate, size_t size, const Coin &coin, bool hashes)
|
||||
{
|
||||
hashingBlob.clear();
|
||||
hashingBlob.reserve(miner_tx_prefix_begin_index + HASH_SIZE + 3);
|
||||
if (size < (kMinSize * 2) || !Cvt::fromHex(m_blob, blocktemplate, size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hashingBlob.assign(raw_blob.begin(), raw_blob.begin() + miner_tx_prefix_begin_index);
|
||||
hashingBlob.insert(hashingBlob.end(), root_hash, root_hash + HASH_SIZE);
|
||||
m_coin = coin;
|
||||
bool rc = false;
|
||||
|
||||
uint64_t k = num_hashes + 1;
|
||||
try {
|
||||
rc = parse(hashes);
|
||||
} catch (...) {}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::BlockTemplate::parse(const rapidjson::Value &blocktemplate, const Coin &coin, bool hashes)
|
||||
{
|
||||
return blocktemplate.IsString() && parse(blocktemplate.GetString(), blocktemplate.GetStringLength(), coin, hashes);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::BlockTemplate::parse(const String &blocktemplate, const Coin &coin, bool hashes)
|
||||
{
|
||||
return parse(blocktemplate.data(), blocktemplate.size(), coin, hashes);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BlockTemplate::generateHashingBlob(Buffer &out) const
|
||||
{
|
||||
out.clear();
|
||||
out.reserve(offset(MINER_TX_PREFIX_OFFSET) + kHashSize + 3);
|
||||
|
||||
out.assign(m_blob.begin(), m_blob.begin() + offset(MINER_TX_PREFIX_OFFSET));
|
||||
out.insert(out.end(), m_rootHash, m_rootHash + kHashSize);
|
||||
|
||||
uint64_t k = m_numHashes + 1;
|
||||
while (k >= 0x80) {
|
||||
hashingBlob.emplace_back((static_cast<uint8_t>(k) & 0x7F) | 0x80);
|
||||
out.emplace_back((static_cast<uint8_t>(k) & 0x7F) | 0x80);
|
||||
k >>= 7;
|
||||
}
|
||||
hashingBlob.emplace_back(static_cast<uint8_t>(k));
|
||||
out.emplace_back(static_cast<uint8_t>(k));
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
bool xmrig::BlockTemplate::parse(bool hashes)
|
||||
{
|
||||
BlobReader<true> ar(m_blob.data(), m_blob.size());
|
||||
|
||||
// Block header
|
||||
ar(m_version.first);
|
||||
ar(m_version.second);
|
||||
ar(m_timestamp);
|
||||
ar(m_prevId, kHashSize);
|
||||
|
||||
setOffset(NONCE_OFFSET, ar.index());
|
||||
ar.skip(kNonceSize);
|
||||
|
||||
// Wownero block template has miner signature starting from version 18
|
||||
if (m_coin == Coin::WOWNERO && majorVersion() >= 18) {
|
||||
ar(m_minerSignature, kSignatureSize);
|
||||
ar(m_vote);
|
||||
}
|
||||
|
||||
// Miner transaction begin
|
||||
// Prefix begin
|
||||
setOffset(MINER_TX_PREFIX_OFFSET, ar.index());
|
||||
|
||||
ar(m_txVersion);
|
||||
ar(m_unlockTime);
|
||||
ar(m_numInputs);
|
||||
|
||||
// must be 1 input
|
||||
if (m_numInputs != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ar(m_inputType);
|
||||
|
||||
// input type must be txin_gen (0xFF)
|
||||
if (m_inputType != 0xFF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ar(m_height);
|
||||
ar(m_numOutputs);
|
||||
|
||||
// must be 1 output
|
||||
if (m_numOutputs != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ar(m_amount);
|
||||
ar(m_outputType);
|
||||
|
||||
// output type must be txout_to_key (2)
|
||||
if (m_outputType != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setOffset(EPH_PUBLIC_KEY_OFFSET, ar.index());
|
||||
|
||||
ar(m_ephPublicKey, kKeySize);
|
||||
ar(m_extraSize);
|
||||
|
||||
setOffset(TX_EXTRA_OFFSET, ar.index());
|
||||
|
||||
BlobReader<true> ar_extra(blob(TX_EXTRA_OFFSET), m_extraSize);
|
||||
ar.skip(m_extraSize);
|
||||
|
||||
while (ar_extra.index() < m_extraSize) {
|
||||
uint64_t extra_tag = 0;
|
||||
ar_extra(extra_tag);
|
||||
|
||||
switch (extra_tag) {
|
||||
case 0x01: // TX_EXTRA_TAG_PUBKEY
|
||||
setOffset(TX_PUBKEY_OFFSET, offset(TX_EXTRA_OFFSET) + ar_extra.index());
|
||||
ar_extra.skip(kKeySize);
|
||||
break;
|
||||
|
||||
case 0x02: // TX_EXTRA_NONCE
|
||||
{
|
||||
uint64_t size = 0;
|
||||
ar_extra(size);
|
||||
setOffset(TX_EXTRA_NONCE_OFFSET, offset(TX_EXTRA_OFFSET) + ar_extra.index());
|
||||
ar_extra(m_txExtraNonce, size);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false; // TODO(SChernykh): handle other tags
|
||||
}
|
||||
}
|
||||
|
||||
setOffset(MINER_TX_PREFIX_END_OFFSET, ar.index());
|
||||
// Prefix end
|
||||
|
||||
// RCT signatures (empty in miner transaction)
|
||||
uint8_t vin_rct_type = 0;
|
||||
ar(vin_rct_type);
|
||||
|
||||
// must be RCTTypeNull (0)
|
||||
if (vin_rct_type != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t miner_tx_end = ar.index();
|
||||
// Miner transaction end
|
||||
|
||||
// Miner transaction must have exactly 1 byte with value 0 after the prefix
|
||||
if ((miner_tx_end != offset(MINER_TX_PREFIX_END_OFFSET) + 1) || (*blob(MINER_TX_PREFIX_END_OFFSET) != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Other transaction hashes
|
||||
ar(m_numHashes);
|
||||
|
||||
if (hashes) {
|
||||
m_hashes.resize((m_numHashes + 1) * kHashSize);
|
||||
calculateMinerTxHash(blob(MINER_TX_PREFIX_OFFSET), blob(MINER_TX_PREFIX_END_OFFSET), m_hashes.data());
|
||||
|
||||
for (uint64_t i = 1; i <= m_numHashes; ++i) {
|
||||
Span h;
|
||||
ar(h, kHashSize);
|
||||
memcpy(m_hashes.data() + i * kHashSize, h.data(), kHashSize);
|
||||
}
|
||||
|
||||
calculateMerkleTreeHash();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* XMRig
|
||||
* Copyright 2012-2013 The Cryptonote developers
|
||||
* Copyright 2014-2021 The Monero Project
|
||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2012-2013 The Cryptonote developers
|
||||
* Copyright (c) 2014-2021 The Monero Project
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -22,71 +22,129 @@
|
|||
#define XMRIG_BLOCKTEMPLATE_H
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/crypto/Coin.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "base/tools/Span.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
struct BlockTemplate
|
||||
class BlockTemplate
|
||||
{
|
||||
enum {
|
||||
HASH_SIZE = 32,
|
||||
KEY_SIZE = 32,
|
||||
SIGNATURE_SIZE = 64,
|
||||
NONCE_SIZE = 4,
|
||||
public:
|
||||
static constexpr size_t kHashSize = 32;
|
||||
static constexpr size_t kKeySize = 32;
|
||||
static constexpr size_t kNonceSize = 4;
|
||||
static constexpr size_t kSignatureSize = 64;
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
static constexpr bool kCalcHashes = true;
|
||||
# else
|
||||
static constexpr bool kCalcHashes = false;
|
||||
# endif
|
||||
|
||||
enum Offset : uint32_t {
|
||||
NONCE_OFFSET,
|
||||
MINER_TX_PREFIX_OFFSET,
|
||||
MINER_TX_PREFIX_END_OFFSET,
|
||||
EPH_PUBLIC_KEY_OFFSET,
|
||||
TX_EXTRA_OFFSET,
|
||||
TX_PUBKEY_OFFSET,
|
||||
TX_EXTRA_NONCE_OFFSET,
|
||||
OFFSET_COUNT
|
||||
};
|
||||
|
||||
Buffer raw_blob;
|
||||
size_t eph_public_key_index;
|
||||
size_t tx_pubkey_index;
|
||||
uint64_t tx_extra_nonce_size;
|
||||
size_t tx_extra_nonce_index;
|
||||
size_t miner_tx_prefix_begin_index;
|
||||
size_t miner_tx_prefix_end_index;
|
||||
inline const Coin &coin() const { return m_coin; }
|
||||
inline const uint8_t *blob() const { return m_blob.data(); }
|
||||
inline const uint8_t *blob(Offset offset) const { return m_blob.data() + m_offsets[offset]; }
|
||||
inline size_t offset(Offset offset) const { return m_offsets[offset]; }
|
||||
inline size_t size() const { return m_blob.size(); }
|
||||
|
||||
// Block header
|
||||
uint8_t major_version;
|
||||
uint8_t minor_version;
|
||||
uint64_t timestamp;
|
||||
uint8_t prev_id[HASH_SIZE];
|
||||
uint8_t nonce[NONCE_SIZE];
|
||||
inline uint8_t majorVersion() const { return m_version.first; }
|
||||
inline uint8_t minorVersion() const { return m_version.second; }
|
||||
inline uint64_t timestamp() const { return m_timestamp; }
|
||||
inline const Span &prevId() const { return m_prevId; }
|
||||
inline const uint8_t *nonce() const { return blob(NONCE_OFFSET); }
|
||||
|
||||
bool has_miner_signature;
|
||||
uint8_t miner_signature[SIGNATURE_SIZE];
|
||||
uint8_t vote[2];
|
||||
// Wownero miner signature
|
||||
inline bool hasMinerSignature() const { return !m_minerSignature.empty(); }
|
||||
inline const Span &minerSignature() const { return m_minerSignature; }
|
||||
inline const uint8_t *vote() const { return m_vote; }
|
||||
|
||||
// Miner tx
|
||||
uint64_t tx_version;
|
||||
uint64_t unlock_time;
|
||||
uint64_t num_inputs;
|
||||
uint8_t input_type;
|
||||
uint64_t height;
|
||||
uint64_t num_outputs;
|
||||
uint64_t amount;
|
||||
uint8_t output_type;
|
||||
uint8_t eph_public_key[KEY_SIZE];
|
||||
uint64_t extra_size;
|
||||
Buffer extra;
|
||||
uint8_t vin_rct_type;
|
||||
inline uint64_t txVersion() const { return m_txVersion; }
|
||||
inline uint64_t unlockTime() const { return m_unlockTime; }
|
||||
inline uint64_t numInputs() const { return m_numInputs; }
|
||||
inline uint8_t inputType() const { return m_inputType; }
|
||||
inline uint64_t height() const { return m_height; }
|
||||
inline uint64_t numOutputs() const { return m_numOutputs; }
|
||||
inline uint64_t amount() const { return m_amount; }
|
||||
inline uint64_t outputType() const { return m_outputType; }
|
||||
inline const Span &ephPublicKey() const { return m_ephPublicKey; }
|
||||
inline const Span &txExtraNonce() const { return m_txExtraNonce; }
|
||||
|
||||
// Transaction hashes
|
||||
uint64_t num_hashes;
|
||||
Buffer hashes;
|
||||
inline uint64_t numHashes() const { return m_numHashes; }
|
||||
inline const Buffer &hashes() const { return m_hashes; }
|
||||
inline const Buffer &minerTxMerkleTreeBranch() const { return m_minerTxMerkleTreeBranch; }
|
||||
inline const uint8_t *rootHash() const { return m_rootHash; }
|
||||
|
||||
Buffer miner_tx_merkle_tree_branch;
|
||||
uint8_t root_hash[HASH_SIZE];
|
||||
inline Buffer generateHashingBlob() const
|
||||
{
|
||||
Buffer out;
|
||||
generateHashingBlob(out);
|
||||
|
||||
Buffer hashingBlob;
|
||||
return out;
|
||||
}
|
||||
|
||||
bool Init(const String& blockTemplate, Coin coin);
|
||||
static void calculateMinerTxHash(const uint8_t *prefix_begin, const uint8_t *prefix_end, uint8_t *hash);
|
||||
static void calculateRootHash(const uint8_t *prefix_begin, const uint8_t *prefix_end, const Buffer &miner_tx_merkle_tree_branch, uint8_t *root_hash);
|
||||
|
||||
static void CalculateMinerTxHash(const uint8_t* prefix_begin, const uint8_t* prefix_end, uint8_t* hash);
|
||||
static void CalculateRootHash(const uint8_t* prefix_begin, const uint8_t* prefix_end, const Buffer& miner_tx_merkle_tree_branch, uint8_t* root_hash);
|
||||
void CalculateMerkleTreeHash();
|
||||
void GenerateHashingBlob();
|
||||
bool parse(const Buffer &blocktemplate, const Coin &coin, bool hashes = kCalcHashes);
|
||||
bool parse(const char *blocktemplate, size_t size, const Coin &coin, bool hashes);
|
||||
bool parse(const rapidjson::Value &blocktemplate, const Coin &coin, bool hashes = kCalcHashes);
|
||||
bool parse(const String &blocktemplate, const Coin &coin, bool hashes = kCalcHashes);
|
||||
void calculateMerkleTreeHash();
|
||||
void generateHashingBlob(Buffer &out) const;
|
||||
|
||||
private:
|
||||
static constexpr size_t kMinSize = 76;
|
||||
|
||||
inline void setOffset(Offset offset, size_t value) { m_offsets[offset] = static_cast<uint32_t>(value); }
|
||||
|
||||
bool parse(bool hashes);
|
||||
|
||||
Buffer m_blob;
|
||||
Coin m_coin;
|
||||
uint32_t m_offsets[OFFSET_COUNT]{};
|
||||
|
||||
std::pair<uint8_t, uint8_t> m_version;
|
||||
uint64_t m_timestamp = 0;
|
||||
Span m_prevId;
|
||||
|
||||
Span m_minerSignature;
|
||||
uint8_t m_vote[2]{};
|
||||
|
||||
uint64_t m_txVersion = 0;
|
||||
uint64_t m_unlockTime = 0;
|
||||
uint64_t m_numInputs = 0;
|
||||
uint8_t m_inputType = 0;
|
||||
uint64_t m_height = 0;
|
||||
uint64_t m_numOutputs = 0;
|
||||
uint64_t m_amount = 0;
|
||||
uint8_t m_outputType = 0;
|
||||
Span m_ephPublicKey;
|
||||
uint64_t m_extraSize = 0;
|
||||
Span m_txExtraNonce;
|
||||
|
||||
uint64_t m_numHashes = 0;
|
||||
Buffer m_hashes;
|
||||
Buffer m_minerTxMerkleTreeBranch;
|
||||
uint8_t m_rootHash[kHashSize]{};
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* XMRig
|
||||
* Copyright 2012-2013 The Cryptonote developers
|
||||
* Copyright 2014-2021 The Monero Project
|
||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2012-2013 The Cryptonote developers
|
||||
* Copyright (c) 2014-2021 The Monero Project
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -18,24 +18,29 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/tools/cryptonote/BlobReader.h"
|
||||
#include "base/tools/cryptonote/WalletAddress.h"
|
||||
#include "base/tools/cryptonote/umul128.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/cryptonote/BlobReader.h"
|
||||
#include "base/tools/cryptonote/umul128.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
bool WalletAddress::Decode(const String& address)
|
||||
bool xmrig::WalletAddress::decode(const char *address, size_t size)
|
||||
{
|
||||
static constexpr std::array<int, 9> block_sizes{ 0, 2, 3, 5, 6, 7, 9, 10, 11 };
|
||||
static constexpr char alphabet[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
constexpr size_t alphabet_size = sizeof(alphabet) - 1;
|
||||
|
||||
if (size < kMinSize || size > kMaxSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int8_t reverse_alphabet[256];
|
||||
memset(reverse_alphabet, -1, sizeof(reverse_alphabet));
|
||||
|
||||
|
@ -43,7 +48,7 @@ bool WalletAddress::Decode(const String& address)
|
|||
reverse_alphabet[static_cast<int>(alphabet[i])] = i;
|
||||
}
|
||||
|
||||
const int len = static_cast<int>(address.size());
|
||||
const int len = static_cast<int>(size);
|
||||
const int num_full_blocks = len / block_sizes.back();
|
||||
const int last_block_size = len % block_sizes.back();
|
||||
|
||||
|
@ -60,10 +65,15 @@ bool WalletAddress::Decode(const String& address)
|
|||
return false;
|
||||
}
|
||||
|
||||
Buffer data;
|
||||
data.reserve(static_cast<size_t>(num_full_blocks) * sizeof(uint64_t) + last_block_size_index);
|
||||
const size_t data_size = static_cast<size_t>(num_full_blocks) * sizeof(uint64_t) + last_block_size_index;
|
||||
if (data_size < kMinDataSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* address_data = address.data();
|
||||
Buffer data;
|
||||
data.reserve(data_size);
|
||||
|
||||
const char *address_data = address;
|
||||
|
||||
for (int i = 0; i <= num_full_blocks; ++i) {
|
||||
uint64_t num = 0;
|
||||
|
@ -87,28 +97,146 @@ bool WalletAddress::Decode(const String& address)
|
|||
|
||||
address_data += block_sizes.back();
|
||||
|
||||
uint8_t* p = reinterpret_cast<uint8_t*>(&num);
|
||||
for (int j = ((i < num_full_blocks) ? sizeof(num) : last_block_size_index) - 1; j >= 0; --j) {
|
||||
auto p = reinterpret_cast<const uint8_t*>(&num);
|
||||
for (int j = ((i < num_full_blocks) ? static_cast<int>(sizeof(num)) : last_block_size_index) - 1; j >= 0; --j) {
|
||||
data.emplace_back(p[j]);
|
||||
}
|
||||
}
|
||||
|
||||
CBlobReader ar(data.data(), data.size());
|
||||
assert(data.size() == data_size);
|
||||
|
||||
ar(tag);
|
||||
ar(public_spend_key);
|
||||
ar(public_view_key);
|
||||
ar(checksum);
|
||||
BlobReader<false> ar(data.data(), data_size);
|
||||
|
||||
uint8_t md[200];
|
||||
keccak(data.data(), data.size() - sizeof(checksum), md);
|
||||
if (ar(m_tag) && ar(m_publicSpendKey) && ar(m_publicViewKey) && ar.skip(ar.remaining() - sizeof(m_checksum)) && ar(m_checksum)) {
|
||||
uint8_t md[200];
|
||||
keccak(data.data(), data_size - sizeof(m_checksum), md);
|
||||
|
||||
if (memcmp(checksum, md, sizeof(checksum)) != 0) {
|
||||
return false;
|
||||
if (memcmp(m_checksum, md, sizeof(m_checksum)) == 0) {
|
||||
m_data = { address, size };
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
m_tag = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
bool xmrig::WalletAddress::decode(const rapidjson::Value &address)
|
||||
{
|
||||
return address.IsString() && decode(address.GetString(), address.GetStringLength());
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::WalletAddress::netName() const
|
||||
{
|
||||
static const std::array<const char *, 3> names = { "mainnet", "testnet", "stagenet" };
|
||||
|
||||
return names[net()];
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::WalletAddress::typeName() const
|
||||
{
|
||||
static const std::array<const char *, 3> names = { "public", "integrated", "subaddress" };
|
||||
|
||||
return names[type()];
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::WalletAddress::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
return isValid() ? m_data.toJSON(doc) : Value(kNullType);
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
rapidjson::Value xmrig::WalletAddress::toAPI(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
if (!isValid()) {
|
||||
return Value(kNullType);
|
||||
}
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
Value out(kObjectType);
|
||||
out.AddMember(StringRef(Coin::kField), coin().toJSON(), allocator);
|
||||
out.AddMember("address", m_data.toJSON(doc), allocator);
|
||||
out.AddMember("type", StringRef(typeName()), allocator);
|
||||
out.AddMember("net", StringRef(netName()), allocator);
|
||||
out.AddMember("rpc_port", rpcPort(), allocator);
|
||||
out.AddMember("zmq_port", zmqPort(), allocator);
|
||||
out.AddMember("tag", m_tag, allocator);
|
||||
out.AddMember("view_key", Cvt::toHex(m_publicViewKey, kKeySize, doc), allocator);
|
||||
out.AddMember("spend_key", Cvt::toHex(m_publicSpendKey, kKeySize, doc), allocator);
|
||||
out.AddMember("checksum", Cvt::toHex(m_checksum, sizeof(m_checksum), doc), allocator);
|
||||
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
const xmrig::WalletAddress::TagInfo &xmrig::WalletAddress::tagInfo(uint64_t tag)
|
||||
{
|
||||
static TagInfo dummy = { Coin::INVALID, MAINNET, PUBLIC, 0, 0 };
|
||||
static const std::map<uint64_t, TagInfo> tags = {
|
||||
{ 0x12, { Coin::MONERO, MAINNET, PUBLIC, 18081, 18082 } },
|
||||
{ 0x13, { Coin::MONERO, MAINNET, INTEGRATED, 18081, 18082 } },
|
||||
{ 0x2a, { Coin::MONERO, MAINNET, SUBADDRESS, 18081, 18082 } },
|
||||
|
||||
{ 0x35, { Coin::MONERO, TESTNET, PUBLIC, 28081, 28082 } },
|
||||
{ 0x36, { Coin::MONERO, TESTNET, INTEGRATED, 28081, 28082 } },
|
||||
{ 0x3f, { Coin::MONERO, TESTNET, SUBADDRESS, 28081, 28082 } },
|
||||
|
||||
{ 0x18, { Coin::MONERO, STAGENET, PUBLIC, 38081, 38082 } },
|
||||
{ 0x19, { Coin::MONERO, STAGENET, INTEGRATED, 38081, 38082 } },
|
||||
{ 0x24, { Coin::MONERO, STAGENET, SUBADDRESS, 38081, 38082 } },
|
||||
|
||||
{ 0x2bb39a, { Coin::SUMO, MAINNET, PUBLIC, 19734, 19735 } },
|
||||
{ 0x29339a, { Coin::SUMO, MAINNET, INTEGRATED, 19734, 19735 } },
|
||||
{ 0x8319a, { Coin::SUMO, MAINNET, SUBADDRESS, 19734, 19735 } },
|
||||
|
||||
{ 0x37751a, { Coin::SUMO, TESTNET, PUBLIC, 29734, 29735 } },
|
||||
{ 0x34f51a, { Coin::SUMO, TESTNET, INTEGRATED, 29734, 29735 } },
|
||||
{ 0x1d351a, { Coin::SUMO, TESTNET, SUBADDRESS, 29734, 29735 } },
|
||||
|
||||
{ 0x2cca, { Coin::ARQMA, MAINNET, PUBLIC, 19994, 19995 } },
|
||||
{ 0x116bc7, { Coin::ARQMA, MAINNET, INTEGRATED, 19994, 19995 } },
|
||||
{ 0x6847, { Coin::ARQMA, MAINNET, SUBADDRESS, 19994, 19995 } },
|
||||
|
||||
{ 0x53ca, { Coin::ARQMA, TESTNET, PUBLIC, 29994, 29995 } },
|
||||
{ 0x504a, { Coin::ARQMA, TESTNET, INTEGRATED, 29994, 29995 } },
|
||||
{ 0x524a, { Coin::ARQMA, TESTNET, SUBADDRESS, 29994, 29995 } },
|
||||
|
||||
{ 0x39ca, { Coin::ARQMA, STAGENET, PUBLIC, 39994, 39995 } },
|
||||
{ 0x1742ca, { Coin::ARQMA, STAGENET, INTEGRATED, 39994, 39995 } },
|
||||
{ 0x1d84ca, { Coin::ARQMA, STAGENET, SUBADDRESS, 39994, 39995 } },
|
||||
|
||||
{ 0xc8ed8, { Coin::DERO, MAINNET, PUBLIC, 20206, 0 } },
|
||||
{ 0xa0ed8, { Coin::DERO, MAINNET, INTEGRATED, 20206, 0 } },
|
||||
|
||||
{ 0x6cf58, { Coin::DERO, TESTNET, PUBLIC, 30306, 0 } },
|
||||
{ 0x44f58, { Coin::DERO, TESTNET, INTEGRATED, 30306, 0 } },
|
||||
|
||||
{ 0x1032, { Coin::WOWNERO, MAINNET, PUBLIC, 34568, 34569 } },
|
||||
{ 0x1a9a, { Coin::WOWNERO, MAINNET, INTEGRATED, 34568, 34569 } },
|
||||
{ 0x2fb0, { Coin::WOWNERO, MAINNET, SUBADDRESS, 34568, 34569 } },
|
||||
|
||||
{ 0x5a, { Coin::GRAFT, MAINNET, PUBLIC, 18981, 18982 } },
|
||||
{ 0x5b, { Coin::GRAFT, MAINNET, INTEGRATED, 18981, 18982 } },
|
||||
{ 0x66, { Coin::GRAFT, MAINNET, SUBADDRESS, 18981, 18982 } },
|
||||
|
||||
{ 0x54, { Coin::GRAFT, TESTNET, PUBLIC, 28881, 28882 } },
|
||||
{ 0x55, { Coin::GRAFT, TESTNET, INTEGRATED, 28881, 28882 } },
|
||||
{ 0x70, { Coin::GRAFT, TESTNET, SUBADDRESS, 28881, 28882 } },
|
||||
};
|
||||
|
||||
const auto it = tags.find(tag);
|
||||
|
||||
return it == tags.end() ? dummy : it->second;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* XMRig
|
||||
* Copyright 2012-2013 The Cryptonote developers
|
||||
* Copyright 2014-2021 The Monero Project
|
||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2012-2013 The Cryptonote developers
|
||||
* Copyright (c) 2014-2021 The Monero Project
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -23,19 +23,78 @@
|
|||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
#include "base/crypto/Coin.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
struct WalletAddress
|
||||
class WalletAddress
|
||||
{
|
||||
uint64_t tag;
|
||||
uint8_t public_spend_key[32];
|
||||
uint8_t public_view_key[32];
|
||||
uint8_t checksum[4];
|
||||
public:
|
||||
enum Net : uint32_t {
|
||||
MAINNET,
|
||||
TESTNET,
|
||||
STAGENET
|
||||
};
|
||||
|
||||
bool Decode(const String& address);
|
||||
enum Type : uint32_t {
|
||||
PUBLIC,
|
||||
INTEGRATED,
|
||||
SUBADDRESS
|
||||
};
|
||||
|
||||
constexpr static size_t kKeySize = 32;
|
||||
constexpr static size_t kMaxSize = 256;
|
||||
constexpr static size_t kMinDataSize = 69;
|
||||
constexpr static size_t kMinSize = 95;
|
||||
|
||||
WalletAddress() = default;
|
||||
inline WalletAddress(const char *address, size_t size) { decode(address, size); }
|
||||
inline WalletAddress(const char *address) { decode(address); }
|
||||
inline WalletAddress(const rapidjson::Value &address) { decode(address); }
|
||||
inline WalletAddress(const String &address) { decode(address); }
|
||||
|
||||
inline bool decode(const char *address) { return decode(address, strlen(address)); }
|
||||
inline bool decode(const String &address) { return decode(address, address.size()); }
|
||||
inline bool isValid() const { return m_tag > 0 && m_data.size() >= kMinSize; }
|
||||
inline const char *data() const { return m_data; }
|
||||
inline const Coin &coin() const { return tagInfo(m_tag).coin; }
|
||||
inline const uint8_t *spendKey() const { return m_publicSpendKey; }
|
||||
inline const uint8_t *viewKey() const { return m_publicViewKey; }
|
||||
inline Net net() const { return tagInfo(m_tag).net; }
|
||||
inline Type type() const { return tagInfo(m_tag).type; }
|
||||
inline uint16_t rpcPort() const { return tagInfo(m_tag).rpcPort; }
|
||||
inline uint16_t zmqPort() const { return tagInfo(m_tag).zmqPort; }
|
||||
inline uint64_t tag() const { return m_tag; }
|
||||
|
||||
bool decode(const char *address, size_t size);
|
||||
bool decode(const rapidjson::Value &address);
|
||||
const char *netName() const;
|
||||
const char *typeName() const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
rapidjson::Value toAPI(rapidjson::Document &doc) const;
|
||||
# endif
|
||||
|
||||
private:
|
||||
struct TagInfo
|
||||
{
|
||||
const Coin coin;
|
||||
const Net net;
|
||||
const Type type;
|
||||
const uint16_t rpcPort;
|
||||
const uint16_t zmqPort;
|
||||
};
|
||||
|
||||
static const TagInfo &tagInfo(uint64_t tag);
|
||||
|
||||
String m_data;
|
||||
uint64_t m_tag = 0;
|
||||
uint8_t m_checksum[4]{};
|
||||
uint8_t m_publicSpendKey[kKeySize]{};
|
||||
uint8_t m_publicViewKey[kKeySize]{};
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue