Added Cvt class.
This commit is contained in:
parent
469b1f08de
commit
63bd45c397
14 changed files with 355 additions and 341 deletions
|
@ -50,7 +50,7 @@
|
|||
#include "base/net/dns/Dns.h"
|
||||
#include "base/net/stratum/Socks5.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "net/JobResult.h"
|
||||
|
||||
|
@ -202,11 +202,8 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
|||
char *nonce = m_sendBuf.data();
|
||||
char *data = m_sendBuf.data() + 16;
|
||||
|
||||
Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
|
||||
nonce[8] = '\0';
|
||||
|
||||
Buffer::toHex(result.result(), 32, data);
|
||||
data[64] = '\0';
|
||||
Cvt::toHex(nonce, sizeof(uint32_t) * 2 + 1, reinterpret_cast<const uint8_t *>(&result.nonce), sizeof(uint32_t));
|
||||
Cvt::toHex(data, 65, result.result(), 32);
|
||||
# endif
|
||||
|
||||
Document doc(kObjectType);
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "net/JobResult.h"
|
||||
|
||||
|
@ -54,7 +54,7 @@ static const char *kHash = "hash";
|
|||
static const char *kHeight = "height";
|
||||
static const char *kJsonRPC = "/json_rpc";
|
||||
|
||||
static const size_t BlobReserveSize = 8;
|
||||
static constexpr size_t kBlobReserveSize = 8;
|
||||
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
|||
# ifdef XMRIG_PROXY_PROJECT
|
||||
memcpy(data + 78, result.nonce, 8);
|
||||
# else
|
||||
Buffer::toHex(reinterpret_cast<const uint8_t *>(&result.nonce), 4, data + 78);
|
||||
Cvt::toHex(data + 78, 9, reinterpret_cast<const uint8_t *>(&result.nonce), 4);
|
||||
# endif
|
||||
|
||||
using namespace rapidjson;
|
||||
|
@ -227,7 +227,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
m_blockhashingblob = Json::getString(params, "blockhashing_blob");
|
||||
if (m_apiVersion == API_DERO) {
|
||||
const uint64_t offset = Json::getUint64(params, "reserved_offset");
|
||||
Buffer::toHex(Buffer::randomBytes(BlobReserveSize).data(), BlobReserveSize, m_blockhashingblob.data() + offset * 2);
|
||||
Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2 + 1, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
|
||||
}
|
||||
|
||||
if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) {
|
||||
|
@ -315,10 +315,10 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
|
|||
Value params(kObjectType);
|
||||
params.AddMember("wallet_address", m_user.toJSON(), allocator);
|
||||
if (m_apiVersion == API_DERO) {
|
||||
params.AddMember("reserve_size", static_cast<uint64_t>(BlobReserveSize), allocator);
|
||||
params.AddMember("reserve_size", static_cast<uint64_t>(kBlobReserveSize), allocator);
|
||||
}
|
||||
else {
|
||||
params.AddMember("extra_nonce", Buffer::randomBytes(BlobReserveSize).toHex().toJSON(doc), allocator);
|
||||
params.AddMember("extra_nonce", Cvt::toHex(Cvt::randomBytes(kBlobReserveSize)).toJSON(doc), allocator);
|
||||
}
|
||||
|
||||
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
|
||||
|
@ -63,7 +64,7 @@ bool xmrig::Job::setBlob(const char *blob)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Buffer::fromHex(blob, m_size * 2, m_blob)) {
|
||||
if (!Cvt::fromHex(m_blob, sizeof(m_blob), blob, m_size * 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -90,9 +91,9 @@ bool xmrig::Job::setSeedHash(const char *hash)
|
|||
m_rawSeedHash = hash;
|
||||
# endif
|
||||
|
||||
m_seed = Buffer::fromHex(hash, kMaxSeedSize * 2);
|
||||
m_seed = Cvt::fromHex(hash, kMaxSeedSize * 2);
|
||||
|
||||
return !m_seed.isEmpty();
|
||||
return !m_seed.empty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,27 +103,14 @@ bool xmrig::Job::setTarget(const char *target)
|
|||
return false;
|
||||
}
|
||||
|
||||
const size_t len = strlen(target);
|
||||
const auto raw = Cvt::fromHex(target, strlen(target));
|
||||
const size_t size = raw.size();
|
||||
|
||||
if (len <= 8) {
|
||||
uint32_t tmp = 0;
|
||||
char str[8];
|
||||
memcpy(str, target, len);
|
||||
|
||||
if (!Buffer::fromHex(str, 8, reinterpret_cast<uint8_t *>(&tmp)) || tmp == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / static_cast<uint64_t>(tmp));
|
||||
if (size == 4) {
|
||||
m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast<const uint32_t *>(raw.data())));
|
||||
}
|
||||
else if (len <= 16) {
|
||||
m_target = 0;
|
||||
char str[16];
|
||||
memcpy(str, target, len);
|
||||
|
||||
if (!Buffer::fromHex(str, 16, reinterpret_cast<uint8_t *>(&m_target)) || m_target == 0) {
|
||||
return false;
|
||||
}
|
||||
else if (size == 8) {
|
||||
m_target = *reinterpret_cast<const uint64_t *>(raw.data());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "base/net/stratum/Tls.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -183,7 +183,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
|
|||
return false;
|
||||
}
|
||||
|
||||
Buffer::toHex(md, 32, m_fingerprint);
|
||||
Cvt::toHex(m_fingerprint, sizeof(m_fingerprint), md, 32);
|
||||
const char *fingerprint = m_client->m_pool.fingerprint();
|
||||
|
||||
return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/benchmark/BenchConfig.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
|
@ -217,7 +218,7 @@ bool xmrig::BenchClient::setSeed(const char *seed)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Buffer::fromHex(seed, size * 2, m_job.blob())) {
|
||||
if (!Cvt::fromHex(m_job.blob(), m_job.size(), seed, size * 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue