Move static algo name conversions to Pool class.

This commit is contained in:
XMRig 2018-04-11 06:39:24 +07:00
parent 36ef254c73
commit 1ebaf677e0
5 changed files with 49 additions and 47 deletions

View file

@ -36,6 +36,20 @@
#endif
static const char *algoNames[] = {
"cryptonight",
"cryptonight-lite",
"cryptonight-heavy"
};
static const char *algoNamesShort[] = {
"cn",
"cn-lite",
"cn-heavy"
};
Pool::Pool() :
m_nicehash(false),
m_keepAlive(0),
@ -89,6 +103,34 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
}
const char *Pool::algoName(xmrig::Algo algorithm)
{
return algoNames[algorithm];
}
xmrig::Algo Pool::algorithm(const char *algo)
{
if (strcasecmp(algo, "cryptonight-light") == 0) {
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
return xmrig::CRYPTONIGHT_LITE;
}
const size_t size = sizeof(algoNames) / sizeof(algoNames[0]);
assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0])));
for (size_t i = 0; i < size; i++) {
if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) {
return static_cast<xmrig::Algo>(i);
}
}
return xmrig::CRYPTONIGHT;
}
bool Pool::parse(const char *url)
{
assert(url != nullptr);

View file

@ -51,6 +51,9 @@ public:
xmrig::Variant variant = xmrig::VARIANT_AUTO
);
static const char *algoName(xmrig::Algo algorithm);
static xmrig::Algo algorithm(const char *algo);
inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
inline const char *host() const { return m_host.data(); }