1
0
mirror of https://github.com/xmrig/xmrig.git synced 2026-01-16 20:53:02 -05:00

Update Json.

This commit is contained in:
XMRig
2020-12-03 15:39:33 +07:00
parent 0a27c6d6af
commit 11da7a3155
10 changed files with 179 additions and 87 deletions

View File

@@ -1,12 +1,6 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -30,16 +24,33 @@
namespace xmrig {
static const char *k2_0 = "2.0";
static const char *kId = "id";
static const char *kJsonRPC = "jsonrpc";
static const char *kMethod = "method";
const char *JsonRequest::kParams = "params";
const char *JsonRequest::k2_0 = "2.0";
const char *JsonRequest::kId = "id";
const char *JsonRequest::kJsonRPC = "jsonrpc";
const char *JsonRequest::kMethod = "method";
const char *JsonRequest::kOK = "OK";
const char *JsonRequest::kParams = "params";
const char *JsonRequest::kResult = "result";
const char *JsonRequest::kStatus = "status";
const char *JsonRequest::kParseError = "parse error";
const char *JsonRequest::kInvalidRequest = "invalid request";
const char *JsonRequest::kMethodNotFound = "method not found";
const char *JsonRequest::kInvalidParams = "invalid params";
const char *JsonRequest::kInternalError = "internal error";
static uint64_t nextId = 0;
} // namespace xmrig
rapidjson::Document xmrig::JsonRequest::create(const char *method)
{
return create(++nextId, method);
}
rapidjson::Document xmrig::JsonRequest::create(int64_t id, const char *method)
{
using namespace rapidjson;
@@ -54,7 +65,13 @@ rapidjson::Document xmrig::JsonRequest::create(int64_t id, const char *method)
}
void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value &params)
uint64_t xmrig::JsonRequest::create(rapidjson::Document &doc, const char *method, rapidjson::Value &params)
{
return create(doc, ++nextId, method, params);
}
uint64_t xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value &params)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
@@ -63,4 +80,6 @@ void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char
doc.AddMember(StringRef(kJsonRPC), StringRef(k2_0), allocator);
doc.AddMember(StringRef(kMethod), StringRef(method), allocator);
doc.AddMember(StringRef(kParams), params, allocator);
return id;
}