Move legacy code to v6 folder.

This commit is contained in:
XMRig 2022-08-04 17:44:37 +07:00
parent 9ad1c02430
commit 04e5ff0349
No known key found for this signature in database
GPG key ID: 446A53638BE94409
13 changed files with 21 additions and 23 deletions

View file

@ -0,0 +1,176 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 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/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include "base/kernel/v6/config/BaseConfig.h"
#include "3rdparty/fmt/core.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "base/kernel/private/DnsConfig.h"
#include "base/kernel/Process.h"
#include "base/kernel/Versions.h"
#include "version.h"
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#ifdef XMRIG_FEATURE_TLS
# include <openssl/opensslv.h>
#endif
#ifdef XMRIG_FEATURE_HWLOC
# include "backend/cpu/Cpu.h"
#endif
namespace xmrig {
const char *BaseConfig::kApi = "api";
const char *BaseConfig::kApiId = "id";
const char *BaseConfig::kApiWorkerId = "worker-id";
const char *BaseConfig::kAutosave = "autosave";
const char *BaseConfig::kBackground = "background";
const char *BaseConfig::kColors = "colors";
const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kTitle = "title";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
#ifdef XMRIG_FEATURE_TLS
const char *BaseConfig::kTls = "tls";
#endif
} // namespace xmrig
bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *path)
{
m_path = path;
if (reader.isEmpty()) {
return false;
}
m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
m_title = reader.getValue(kTitle);
# ifdef XMRIG_FEATURE_TLS
m_tls = reader.getValue(kTls);
# endif
Log::setColors(reader.getBool(kColors, Log::isColors()));
setVerbose(reader.getValue(kVerbose));
const auto &api = reader.getObject(kApi);
if (api.IsObject()) {
m_apiId = Json::getString(api, kApiId);
m_apiWorkerId = Json::getString(api, kApiWorkerId);
}
m_http.load(reader.getObject(kHttp));
m_pools.load(reader);
DnsConfig::set(reader.getObject(DnsConfig::kField));
return m_pools.active() > 0;
}
bool xmrig::BaseConfig::save()
{
rapidjson::Document doc;
return save(doc);
}
bool xmrig::BaseConfig::save(rapidjson::Document &doc)
{
if (m_path.isNull()) {
return false;
}
getJSON(doc);
if (Json::save(m_path, doc)) {
LOG_NOTICE("%s " WHITE_BOLD("configuration saved to: \"%s\""), Tags::config(), m_path.data());
return true;
}
return false;
}
void xmrig::BaseConfig::printVersions()
{
const auto &versions = Process::versions();
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s/%s"), "ABOUT", APP_NAME, APP_VERSION, Versions::kCompiler, versions.get(Versions::kCompiler).data());
# if defined(XMRIG_FEATURE_TLS)
std::string libs = fmt::format("{}/{} ", Versions::kTls, versions.get(Versions::kTls));
# else
std::string libs;
# endif
# if defined(XMRIG_FEATURE_HWLOC)
libs += Cpu::info()->backend();
# endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", versions.get(Versions::kUv).data(), libs.c_str());
}
void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value)
{
if (value.IsBool()) {
Log::setVerbose(value.GetBool() ? 1 : 0);
}
else if (value.IsUint()) {
Log::setVerbose(value.GetUint());
}
}

View file

@ -0,0 +1,129 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 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/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_BASECONFIG_H
#define XMRIG_BASECONFIG_H
#include "base/kernel/private/Title.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/net/http/Http.h"
#include "base/net/stratum/Pools.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
namespace xmrig {
class IJsonReader;
class BaseConfig : public IConfig
{
public:
static const char *kApi;
static const char *kApiId;
static const char *kApiWorkerId;
static const char *kAutosave;
static const char *kBackground;
static const char *kColors;
static const char *kDryRun;
static const char *kHttp;
static const char *kLogFile;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kTitle;
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
# ifdef XMRIG_FEATURE_TLS
static const char *kTls;
# endif
BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const Http &http() const { return m_http; }
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline const Title &title() const { return m_title; }
inline uint32_t printTime() const { return m_printTime; }
# ifdef XMRIG_FEATURE_TLS
inline const TlsConfig &tls() const { return m_tls; }
# endif
inline bool isWatch() const override { return m_watch && !m_path.isNull(); }
inline const String &path() const override { return m_path; }
inline uint32_t id() const override { return 0; }
inline void setPath(const char *path) override { m_path = path; }
bool read(const IJsonReader &reader, const char *path) override;
bool save();
bool save(rapidjson::Document &doc) override;
static void printVersions();
protected:
bool m_autoSave = true;
bool m_background = false;
bool m_dryRun = false;
bool m_syslog = false;
bool m_upgrade = false;
bool m_watch = true;
Http m_http;
Pools m_pools;
String m_apiId;
String m_apiWorkerId;
String m_logFile;
String m_path;
String m_userAgent;
Title m_title;
uint32_t m_printTime = 60;
# ifdef XMRIG_FEATURE_TLS
TlsConfig m_tls;
# endif
private:
static void setVerbose(const rapidjson::Value &value);
};
} // namespace xmrig
#endif /* XMRIG_BASECONFIG_H */

View file

@ -0,0 +1,371 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 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/>.
*/
#include <cstdio>
#ifdef _MSC_VER
# include "getopt/getopt.h"
#else
# include <getopt.h>
#endif
#include "base/kernel/v6/config/BaseTransform.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/kernel/private/DnsConfig.h"
#include "base/kernel/Process.h"
#include "base/kernel/v6/config/BaseConfig.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "base/tools/Arguments.h"
#include "core/config/Config_platform.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
{
using namespace rapidjson;
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); // NOLINT(concurrency-mt-unsafe)
if (key < 0) {
break;
}
if (key == IConfig::ConfigKey) {
chain.add(std::move(doc));
chain.addFile(optarg);
doc = Document(kObjectType);
}
else {
transform.transform(doc, key, optarg);
}
}
if (optind < argc) {
LOG_WARN("%s: unsupported non-option argument '%s'", argv[0], argv[optind]);
}
transform.finalize(doc);
chain.add(std::move(doc));
}
void xmrig::BaseTransform::finalize(rapidjson::Document &doc)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
if (m_algorithm.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(Pool::kAlgo)) {
pool.AddMember(StringRef(Pool::kAlgo), m_algorithm.toJSON(), allocator);
}
}
}
if (m_coin.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(Pool::kCoin)) {
pool.AddMember(StringRef(Pool::kCoin), m_coin.toJSON(), allocator);
}
}
}
if (m_http) {
set(doc, BaseConfig::kHttp, Http::kEnabled, true);
}
}
void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const char *arg)
{
switch (key) {
case IConfig::AlgorithmKey: /* --algo */
if (!doc.HasMember(Pools::kPools)) {
m_algorithm = arg;
}
else {
return add(doc, Pools::kPools, Pool::kAlgo, arg);
}
break;
case IConfig::CoinKey: /* --coin */
if (!doc.HasMember(Pools::kPools)) {
m_coin = arg;
}
else {
return add(doc, Pools::kPools, Pool::kCoin, arg);
}
break;
case IConfig::UserpassKey: /* --userpass */
{
const char *p = strrchr(arg, ':');
if (!p) {
return;
}
char *user = new char[p - arg + 1]();
strncpy(user, arg, static_cast<size_t>(p - arg));
add<const char *>(doc, Pools::kPools, Pool::kUser, user);
add(doc, Pools::kPools, Pool::kPass, p + 1);
delete [] user;
}
break;
case IConfig::UrlKey: /* --url */
case IConfig::StressKey: /* --stress */
{
if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
}
rapidjson::Value &array = doc[Pools::kPools];
if (array.Size() == 0 || Pool(array[array.Size() - 1]).isValid()) {
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
}
# ifdef XMRIG_FEATURE_BENCHMARK
if (key != IConfig::UrlKey) {
set(doc, array[array.Size() - 1], Pool::kUrl,
# ifdef XMRIG_FEATURE_TLS
"stratum+ssl://randomx.xmrig.com:443"
# else
"randomx.xmrig.com:3333"
# endif
);
} else
# endif
{
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
}
break;
}
case IConfig::UserKey: /* --user */
return add(doc, Pools::kPools, Pool::kUser, arg);
case IConfig::PasswordKey: /* --pass */
return add(doc, Pools::kPools, Pool::kPass, arg);
case IConfig::SpendSecretKey: /* --spend-secret-key */
return add(doc, Pools::kPools, Pool::kSpendSecretKey, arg);
case IConfig::RigIdKey: /* --rig-id */
return add(doc, Pools::kPools, Pool::kRigId, arg);
case IConfig::FingerprintKey: /* --tls-fingerprint */
return add(doc, Pools::kPools, Pool::kFingerprint, arg);
case IConfig::SelfSelectKey: /* --self-select */
return add(doc, Pools::kPools, Pool::kSelfSelect, arg);
case IConfig::ProxyKey: /* --proxy */
return add(doc, Pools::kPools, Pool::kSOCKS5, arg);
case IConfig::LogFileKey: /* --log-file */
return set(doc, BaseConfig::kLogFile, arg);
case IConfig::HttpAccessTokenKey: /* --http-access-token */
m_http = true;
return set(doc, BaseConfig::kHttp, Http::kToken, arg);
case IConfig::HttpHostKey: /* --http-host */
m_http = true;
return set(doc, BaseConfig::kHttp, Http::kHost, arg);
case IConfig::ApiWorkerIdKey: /* --api-worker-id */
return set(doc, BaseConfig::kApi, BaseConfig::kApiWorkerId, arg);
case IConfig::ApiIdKey: /* --api-id */
return set(doc, BaseConfig::kApi, BaseConfig::kApiId, arg);
case IConfig::UserAgentKey: /* --user-agent */
return set(doc, BaseConfig::kUserAgent, arg);
case IConfig::TitleKey: /* --title */
return set(doc, BaseConfig::kTitle, arg);
# ifdef XMRIG_FEATURE_TLS
case IConfig::TlsCertKey: /* --tls-cert */
return set(doc, BaseConfig::kTls, TlsConfig::kCert, arg);
case IConfig::TlsCertKeyKey: /* --tls-cert-key */
return set(doc, BaseConfig::kTls, TlsConfig::kCertKey, arg);
case IConfig::TlsDHparamKey: /* --tls-dhparam */
return set(doc, BaseConfig::kTls, TlsConfig::kDhparam, arg);
case IConfig::TlsCiphersKey: /* --tls-ciphers */
return set(doc, BaseConfig::kTls, TlsConfig::kCiphers, arg);
case IConfig::TlsCipherSuitesKey: /* --tls-ciphersuites */
return set(doc, BaseConfig::kTls, TlsConfig::kCipherSuites, arg);
case IConfig::TlsProtocolsKey: /* --tls-protocols */
return set(doc, BaseConfig::kTls, TlsConfig::kProtocols, arg);
case IConfig::TlsGenKey: /* --tls-gen */
return set(doc, BaseConfig::kTls, TlsConfig::kGen, arg);
# endif
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
case IConfig::PrintTimeKey: /* --print-time */
case IConfig::HttpPort: /* --http-port */
case IConfig::DonateLevelKey: /* --donate-level */
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
case IConfig::DnsTtlKey: /* --dns-ttl */
case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return transformUint64(doc, key, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::BackgroundKey: /* --background */
case IConfig::SyslogKey: /* --syslog */
case IConfig::KeepAliveKey: /* --keepalive */
case IConfig::NicehashKey: /* --nicehash */
case IConfig::TlsKey: /* --tls */
case IConfig::DryRunKey: /* --dry-run */
case IConfig::HttpEnabledKey: /* --http-enabled */
case IConfig::DaemonKey: /* --daemon */
case IConfig::SubmitToOriginKey: /* --submit-to-origin */
case IConfig::VerboseKey: /* --verbose */
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
case IConfig::NoTitleKey: /* --no-title */
return transformBoolean(doc, key, false);
default:
break;
}
}
void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, bool enable)
{
switch (key) {
case IConfig::BackgroundKey: /* --background */
return set(doc, BaseConfig::kBackground, enable);
case IConfig::SyslogKey: /* --syslog */
return set(doc, BaseConfig::kSyslog, enable);
case IConfig::KeepAliveKey: /* --keepalive */
return add(doc, Pools::kPools, Pool::kKeepalive, enable);
case IConfig::TlsKey: /* --tls */
return add(doc, Pools::kPools, Pool::kTls, enable);
case IConfig::SubmitToOriginKey: /* --submit-to-origin */
return add(doc, Pools::kPools, Pool::kSubmitToOrigin, enable);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */
return add(doc, Pools::kPools, Pool::kDaemon, enable);
# endif
# ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */
return add<bool>(doc, Pools::kPools, Pool::kNicehash, enable);
# endif
case IConfig::ColorKey: /* --no-color */
return set(doc, BaseConfig::kColors, enable);
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
m_http = true;
return set(doc, BaseConfig::kHttp, Http::kRestricted, enable);
case IConfig::HttpEnabledKey: /* --http-enabled */
m_http = true;
break;
case IConfig::DryRunKey: /* --dry-run */
return set(doc, BaseConfig::kDryRun, enable);
case IConfig::VerboseKey: /* --verbose */
return set(doc, BaseConfig::kVerbose, enable);
case IConfig::NoTitleKey: /* --no-title */
return set(doc, BaseConfig::kTitle, enable);
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
return set(doc, DnsConfig::kField, DnsConfig::kIPv6, enable);
default:
break;
}
}
void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, uint64_t arg)
{
switch (key) {
case IConfig::RetriesKey: /* --retries */
return set(doc, Pools::kRetries, arg);
case IConfig::RetryPauseKey: /* --retry-pause */
return set(doc, Pools::kRetryPause, arg);
case IConfig::DonateLevelKey: /* --donate-level */
return set(doc, Pools::kDonateLevel, arg);
case IConfig::ProxyDonateKey: /* --donate-over-proxy */
return set(doc, Pools::kDonateOverProxy, arg);
case IConfig::HttpPort: /* --http-port */
m_http = true;
return set(doc, BaseConfig::kHttp, Http::kPort, arg);
case IConfig::PrintTimeKey: /* --print-time */
return set(doc, BaseConfig::kPrintTime, arg);
case IConfig::DnsTtlKey: /* --dns-ttl */
return set(doc, DnsConfig::kField, DnsConfig::kTTL, arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);
case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return add(doc, Pools::kPools, Pool::kDaemonZMQPort, arg);
# endif
default:
break;
}
}

View file

@ -0,0 +1,123 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 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_BASETRANSFORM_H
#define XMRIG_BASETRANSFORM_H
#include "3rdparty/rapidjson/document.h"
#include "base/crypto/Coin.h"
#include "base/kernel/interfaces/IConfigTransform.h"
struct option;
namespace xmrig {
class IConfigTransform;
class JsonChain;
class Process;
class BaseTransform : public IConfigTransform
{
public:
static void load(JsonChain &chain, Process *process, IConfigTransform &transform);
protected:
void finalize(rapidjson::Document &doc) override;
void transform(rapidjson::Document &doc, int key, const char *arg) override;
template<typename T>
inline void set(rapidjson::Document &doc, const char *key, T value) { set<T>(doc, doc, key, value); }
template<typename T>
inline void set(rapidjson::Document &doc, const char *objKey, const char *key, T value)
{
if (!doc.HasMember(objKey)) {
doc.AddMember(rapidjson::StringRef(objKey), rapidjson::kObjectType, doc.GetAllocator());
}
set<T>(doc, doc[objKey], key, value);
}
template<typename T>
inline void add(rapidjson::Document &doc, const char *arrayKey, const char *key, T value, bool force = false)
{
auto &allocator = doc.GetAllocator();
if (!doc.HasMember(arrayKey)) {
doc.AddMember(rapidjson::StringRef(arrayKey), rapidjson::kArrayType, allocator);
}
rapidjson::Value &array = doc[arrayKey];
if (force || array.Size() == 0) {
array.PushBack(rapidjson::kObjectType, allocator);
}
set<T>(doc, array[array.Size() - 1], key, value);
}
template<typename T>
inline void set(rapidjson::Document &doc, rapidjson::Value &obj, const char *key, T value)
{
if (obj.HasMember(key)) {
obj[key] = value;
}
else {
obj.AddMember(rapidjson::StringRef(key), value, doc.GetAllocator());
}
}
protected:
Algorithm m_algorithm;
Coin m_coin;
private:
void transformBoolean(rapidjson::Document &doc, int key, bool enable);
void transformUint64(rapidjson::Document &doc, int key, uint64_t arg);
bool m_http = false;
};
template<>
inline void BaseTransform::set(rapidjson::Document &doc, rapidjson::Value &obj, const char *key, const char *value)
{
auto &allocator = doc.GetAllocator();
if (obj.HasMember(key)) {
obj[key] = rapidjson::Value(value, allocator);
}
else {
obj.AddMember(rapidjson::StringRef(key), rapidjson::Value(value, allocator), allocator);
}
}
} // namespace xmrig
#endif /* XMRIG_BASETRANSFORM_H */