mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-11 05:14:40 +00:00
Added JsonRequest.
This commit is contained in:
parent
c0e668f36f
commit
074b3869d2
5 changed files with 94 additions and 24 deletions
|
@ -2,6 +2,7 @@ set(HEADERS_BASE
|
||||||
src/base/io/Console.h
|
src/base/io/Console.h
|
||||||
src/base/io/json/Json.h
|
src/base/io/json/Json.h
|
||||||
src/base/io/json/JsonChain.h
|
src/base/io/json/JsonChain.h
|
||||||
|
src/base/io/json/JsonRequest.h
|
||||||
src/base/io/log/backends/ConsoleLog.h
|
src/base/io/log/backends/ConsoleLog.h
|
||||||
src/base/io/log/backends/FileLog.h
|
src/base/io/log/backends/FileLog.h
|
||||||
src/base/io/log/Log.h
|
src/base/io/log/Log.h
|
||||||
|
@ -53,14 +54,15 @@ set(SOURCES_BASE
|
||||||
src/base/io/Console.cpp
|
src/base/io/Console.cpp
|
||||||
src/base/io/json/Json.cpp
|
src/base/io/json/Json.cpp
|
||||||
src/base/io/json/JsonChain.cpp
|
src/base/io/json/JsonChain.cpp
|
||||||
|
src/base/io/json/JsonRequest.cpp
|
||||||
src/base/io/log/backends/ConsoleLog.cpp
|
src/base/io/log/backends/ConsoleLog.cpp
|
||||||
src/base/io/log/backends/FileLog.cpp
|
src/base/io/log/backends/FileLog.cpp
|
||||||
src/base/io/log/Log.cpp
|
src/base/io/log/Log.cpp
|
||||||
src/base/io/Watcher.cpp
|
src/base/io/Watcher.cpp
|
||||||
|
src/base/kernel/Base.cpp
|
||||||
src/base/kernel/config/BaseConfig.cpp
|
src/base/kernel/config/BaseConfig.cpp
|
||||||
src/base/kernel/config/BaseTransform.cpp
|
src/base/kernel/config/BaseTransform.cpp
|
||||||
src/base/kernel/Entry.cpp
|
src/base/kernel/Entry.cpp
|
||||||
src/base/kernel/Base.cpp
|
|
||||||
src/base/kernel/Process.cpp
|
src/base/kernel/Process.cpp
|
||||||
src/base/kernel/Signals.cpp
|
src/base/kernel/Signals.cpp
|
||||||
src/base/net/dns/Dns.cpp
|
src/base/net/dns/Dns.cpp
|
||||||
|
|
38
src/base/io/json/JsonRequest.cpp
Normal file
38
src/base/io/json/JsonRequest.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* 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-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 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 "base/io/json/JsonRequest.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value ¶ms)
|
||||||
|
{
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
doc.AddMember("id", id, allocator);
|
||||||
|
doc.AddMember("jsonrpc", "2.0", allocator);
|
||||||
|
doc.AddMember("method", rapidjson::StringRef(method), allocator);
|
||||||
|
doc.AddMember("params", params, allocator);
|
||||||
|
}
|
45
src/base/io/json/JsonRequest.h
Normal file
45
src/base/io/json/JsonRequest.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* 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-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 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_JSONREQUEST_H
|
||||||
|
#define XMRIG_JSONREQUEST_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class JsonRequest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value ¶ms);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_JSONREQUEST_H */
|
|
@ -37,6 +37,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/io/json/JsonRequest.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/interfaces/IClientListener.h"
|
#include "base/kernel/interfaces/IClientListener.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
@ -167,10 +168,6 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
||||||
Document doc(kObjectType);
|
Document doc(kObjectType);
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
doc.AddMember("id", m_sequence, allocator);
|
|
||||||
doc.AddMember("jsonrpc", "2.0", allocator);
|
|
||||||
doc.AddMember("method", "submit", allocator);
|
|
||||||
|
|
||||||
Value params(kObjectType);
|
Value params(kObjectType);
|
||||||
params.AddMember("id", StringRef(m_rpcId.data()), allocator);
|
params.AddMember("id", StringRef(m_rpcId.data()), allocator);
|
||||||
params.AddMember("job_id", StringRef(result.jobId.data()), allocator);
|
params.AddMember("job_id", StringRef(result.jobId.data()), allocator);
|
||||||
|
@ -181,7 +178,7 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
||||||
params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator);
|
params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.AddMember("params", params, allocator);
|
JsonRequest::create(doc, m_sequence, "submit", params);
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
||||||
|
@ -584,14 +581,10 @@ void xmrig::Client::login()
|
||||||
Document doc(kObjectType);
|
Document doc(kObjectType);
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
doc.AddMember("id", 1, allocator);
|
|
||||||
doc.AddMember("jsonrpc", "2.0", allocator);
|
|
||||||
doc.AddMember("method", "login", allocator);
|
|
||||||
|
|
||||||
Value params(kObjectType);
|
Value params(kObjectType);
|
||||||
params.AddMember("login", m_pool.user().toJSON(), allocator);
|
params.AddMember("login", m_pool.user().toJSON(), allocator);
|
||||||
params.AddMember("pass", m_pool.password().toJSON(), allocator);
|
params.AddMember("pass", m_pool.password().toJSON(), allocator);
|
||||||
params.AddMember("agent", StringRef(m_agent), allocator);
|
params.AddMember("agent", StringRef(m_agent), allocator);
|
||||||
|
|
||||||
if (!m_pool.rigId().isNull()) {
|
if (!m_pool.rigId().isNull()) {
|
||||||
params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
|
params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
|
||||||
|
@ -612,7 +605,7 @@ void xmrig::Client::login()
|
||||||
|
|
||||||
m_listener->onLogin(this, doc, params);
|
m_listener->onLogin(this, doc, params);
|
||||||
|
|
||||||
doc.AddMember("params", params, allocator);
|
JsonRequest::create(doc, 1, "login", params);
|
||||||
|
|
||||||
send(doc);
|
send(doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/http-parser/http_parser.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
#include "base/io/json/JsonRequest.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/interfaces/IClientListener.h"
|
#include "base/kernel/interfaces/IClientListener.h"
|
||||||
#include "base/net/http/HttpClient.h"
|
#include "base/net/http/HttpClient.h"
|
||||||
|
@ -96,16 +97,11 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
Document doc(kObjectType);
|
Document doc(kObjectType);
|
||||||
auto &allocator = doc.GetAllocator();
|
|
||||||
|
|
||||||
doc.AddMember("id", m_sequence, allocator);
|
|
||||||
doc.AddMember("jsonrpc", "2.0", allocator);
|
|
||||||
doc.AddMember("method", "submitblock", allocator);
|
|
||||||
|
|
||||||
Value params(kArrayType);
|
Value params(kArrayType);
|
||||||
params.PushBack(m_blocktemplate.toJSON(), allocator);
|
params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator());
|
||||||
|
|
||||||
doc.AddMember("params", params, allocator);
|
JsonRequest::create(doc, m_sequence, "submitblock", params);
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
|
||||||
|
@ -251,15 +247,11 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
|
||||||
Document doc(kObjectType);
|
Document doc(kObjectType);
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
doc.AddMember("id", m_sequence, allocator);
|
|
||||||
doc.AddMember("jsonrpc", "2.0", allocator);
|
|
||||||
doc.AddMember("method", "getblocktemplate", allocator);
|
|
||||||
|
|
||||||
Value params(kObjectType);
|
Value params(kObjectType);
|
||||||
params.AddMember("wallet_address", m_pool.user().toJSON(), allocator);
|
params.AddMember("wallet_address", m_pool.user().toJSON(), allocator);
|
||||||
params.AddMember("reserve_size", 8, allocator);
|
params.AddMember("reserve_size", 8, allocator);
|
||||||
|
|
||||||
doc.AddMember("params", params, allocator);
|
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);
|
||||||
|
|
||||||
send(HTTP_POST, "/json_rpc", doc);
|
send(HTTP_POST, "/json_rpc", doc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue