Skip to content

Commit

Permalink
Improve Nlohmann Json code handling messages from Pool
Browse files Browse the repository at this point in the history
And fix a Segmentation Fault in some platforms

Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
  • Loading branch information
Pttn committed Mar 30, 2022
1 parent a59e56b commit a0707fd
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions StratumClient.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (c) 2018-2021 Pttn (https://riecoin.dev/en/rieMiner)
// (c) 2018-2022 Pttn (https://riecoin.dev/en/rieMiner)

#include <fcntl.h>
#ifdef _WIN32
Expand Down Expand Up @@ -44,25 +44,18 @@ static std::array<uint8_t, 32> merkleRootGen(std::vector<std::array<uint8_t, 32>
}

void StratumClient::_processMessage(const std::string &message) {
bool isRequest(true);
std::string method;
nlohmann::json jsonMessage;
try {
jsonMessage = nlohmann::json::parse(message);
try {
method = jsonMessage["method"];
}
catch (...) {
isRequest = false;
}
}
catch (...) {
std::cout << "Could not parse Json Message!" << std::endl;
std::cout << "Pool message was: " << message << std::endl;
_state = UNSUBSCRIBED;
return;
}
if (isRequest) {
if (jsonMessage.contains("method")) {
const std::string method(jsonMessage["method"]);
if (method == "mining.notify") {
std::string jobId, prevhash, coinbase1, coinbase2, version, nbits, ntime;
std::vector<std::string> merkleBranches;
Expand Down

0 comments on commit a0707fd

Please sign in to comment.