Update Coin, BlobReader and WalletAddress.

This commit is contained in:
XMRig 2021-08-17 08:17:21 +07:00
parent 9eac9dd30a
commit d1033abbe5
No known key found for this signature in database
GPG key ID: 446A53638BE94409
8 changed files with 369 additions and 165 deletions

View file

@ -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::ARQMA },
{ "arq", Coin::ARQMA },
{ "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_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 ARQMA:
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;
}