This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
forked from ethereum-mining/ethminer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding claymore compatible json-rpc api. supporting miner_getstat1 and miner_restart commands
- Loading branch information
Showing
13 changed files
with
211 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
hunter_config(CURL VERSION ${HUNTER_CURL_VERSION} CMAKE_ARGS HTTP_ONLY=ON CMAKE_USE_OPENSSL=OFF CMAKE_USE_LIBSSH2=OFF) | ||
hunter_config(CURL VERSION ${HUNTER_CURL_VERSION} CMAKE_ARGS HTTP_ONLY=ON CMAKE_USE_OPENSSL=OFF CMAKE_USE_LIBSSH2=OFF) | ||
hunter_config(libjson-rpc-cpp VERSION ${HUNTER_libjson-rpc-cpp_VERSION} CMAKE_ARGS TCP_SOCKET_SERVER=ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "Api.h" | ||
|
||
Api::Api(const int &port, Farm &farm): m_farm(farm) | ||
{ | ||
int portNumber = port; | ||
bool readonly = true; | ||
|
||
// > 0 = rw, < 0 = ro, 0 = disabled | ||
if (portNumber > 0) { | ||
readonly = false; | ||
} else if(portNumber < 0) { | ||
portNumber = -portNumber; | ||
} | ||
|
||
if (portNumber > 0) { | ||
TcpSocketServer *conn = new TcpSocketServer("0.0.0.0", portNumber); | ||
this->m_server = new ApiServer(conn, JSONRPC_SERVER_V2, this->m_farm, readonly); | ||
this->m_server->StartListening(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef _API_H_ | ||
#define _API_H_ | ||
|
||
#include "ApiServer.h" | ||
#include <libethcore/Farm.h> | ||
#include <libethcore/Miner.h> | ||
#include <jsonrpccpp/server/connectors/tcpsocketserver.h> | ||
|
||
using namespace jsonrpc; | ||
using namespace dev; | ||
using namespace dev::eth; | ||
|
||
class Api | ||
{ | ||
public: | ||
Api(const int &port, Farm &farm); | ||
private: | ||
ApiServer *m_server; | ||
Farm &m_farm; | ||
}; | ||
|
||
#endif //_API_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "ApiServer.h" | ||
#include "BuildInfo.h" | ||
|
||
ApiServer::ApiServer(AbstractServerConnector *conn, serverVersion_t type, Farm &farm, bool &readonly) : AbstractServer(*conn, type), m_farm(farm) | ||
{ | ||
this->bindAndAddMethod(Procedure("miner_getstat1", PARAMS_BY_NAME, JSON_OBJECT, NULL), &ApiServer::getMinerStat1); | ||
if (!readonly) { | ||
this->bindAndAddMethod(Procedure("miner_restart", PARAMS_BY_NAME, JSON_OBJECT, NULL), &ApiServer::doMinerRestart); | ||
this->bindAndAddMethod(Procedure("miner_reboot", PARAMS_BY_NAME, JSON_OBJECT, NULL), &ApiServer::doMinerReboot); | ||
} | ||
} | ||
|
||
void ApiServer::getMinerStat1(const Json::Value& request, Json::Value& response) | ||
{ | ||
(void) request; // unused | ||
|
||
auto runningTime = std::chrono::duration_cast<std::chrono::minutes>(steady_clock::now() - this->m_started); | ||
|
||
SolutionStats s = this->m_farm.getSolutionStats(); | ||
WorkingProgress p = this->m_farm.miningProgress(); | ||
|
||
ostringstream totalMhEth; | ||
ostringstream totalMhDcr; | ||
ostringstream detailedMhEth; | ||
ostringstream detailedMhDcr; | ||
ostringstream tempAndFans; | ||
ostringstream invalidStats; | ||
|
||
totalMhEth << std::fixed << std::setprecision(0) << (p.rate() / 1000.0f) << ";" << s.getAccepts() << ";" << s.getRejects(); | ||
totalMhDcr << "0;0;0"; // DualMining not supported | ||
invalidStats << s.getFailures() << ";0"; // Invalid + Pool switches | ||
invalidStats << ";0;0"; // DualMining not supported | ||
|
||
int gpuIndex = 0; | ||
int numGpus = p.minersHashes.size(); | ||
for (auto const& i: p.minersHashes) | ||
{ | ||
detailedMhEth << std::fixed << std::setprecision(0) << (p.minerRate(i) / 1000.0f) << (((numGpus -1) > gpuIndex) ? ";" : ""); | ||
detailedMhDcr << "off" << (((numGpus -1) > gpuIndex) ? ";" : ""); // DualMining not supported | ||
tempAndFans << "50;50" <<(((numGpus -1) > gpuIndex) ? ";" : ""); // Fetching Temp and Fans not supported | ||
gpuIndex++; | ||
} | ||
|
||
response[0] = ETH_PROJECT_VERSION; //miner version. | ||
response[1] = toString(runningTime.count()); // running time, in minutes. | ||
response[2] = totalMhEth.str(); // total ETH hashrate in MH/s, number of ETH shares, number of ETH rejected shares. | ||
response[3] = detailedMhEth.str(); // detailed ETH hashrate for all GPUs. | ||
response[4] = totalMhDcr.str(); // total DCR hashrate in MH/s, number of DCR shares, number of DCR rejected shares. | ||
response[5] = detailedMhDcr.str(); // detailed DCR hashrate for all GPUs. | ||
response[6] = tempAndFans.str(); // Temperature and Fan speed(%) pairs for all GPUs. | ||
response[7] = ""; // current mining pool. For dual mode, there will be two pools here. | ||
response[8] = invalidStats.str(); // number of ETH invalid shares, number of ETH pool switches, number of DCR invalid shares, number of DCR pool switches. | ||
} | ||
|
||
void ApiServer::doMinerRestart(const Json::Value& request, Json::Value& response) | ||
{ | ||
(void) request; // unused | ||
(void) response; // unused | ||
|
||
this->m_farm.restart(); | ||
} | ||
|
||
void ApiServer::doMinerReboot(const Json::Value& request, Json::Value& response) | ||
{ | ||
(void) request; // unused | ||
(void) response; // unused | ||
|
||
// Not supported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef _APISERVER_H_ | ||
#define _APISERVER_H_ | ||
|
||
#include <libethcore/Farm.h> | ||
#include <libethcore/Miner.h> | ||
#include <jsonrpccpp/server.h> | ||
|
||
using namespace jsonrpc; | ||
using namespace dev; | ||
using namespace dev::eth; | ||
using namespace std::chrono; | ||
|
||
class ApiServer : public AbstractServer<ApiServer> | ||
{ | ||
public: | ||
ApiServer(AbstractServerConnector *conn, serverVersion_t type, Farm &farm, bool &readonly); | ||
private: | ||
steady_clock::time_point m_started = steady_clock::now(); | ||
Farm &m_farm; | ||
void getMinerStat1(const Json::Value& request, Json::Value& response); | ||
void doMinerRestart(const Json::Value& request, Json::Value& response); | ||
void doMinerReboot(const Json::Value& request, Json::Value& response); | ||
}; | ||
|
||
#endif //_APISERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(SOURCES | ||
Api.h Api.cpp | ||
ApiServer.h ApiServer.cpp | ||
) | ||
|
||
add_library(apicore ${SOURCES}) | ||
target_link_libraries(apicore devcore libjson-rpc-cpp::server) | ||
target_include_directories(apicore PRIVATE ..) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters