Browse Source

isMining changes to mining

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
bfb05d0cd7
  1. 4
      libethrpc/EthStubServer.cpp
  2. 4
      libethrpc/EthStubServer.h
  3. 28
      libethrpc/abstractethstubserver.h
  4. 4
      libethrpc/eth.js
  5. 4
      libethrpc/spec.json
  6. 48
      test/ethstubclient.h
  7. 4
      test/jsonrpc.cpp

4
libethrpc/EthStubServer.cpp

@ -210,12 +210,12 @@ std::string EthStubServer::gasPrice()
}
//TODO
bool EthStubServer::isListening()
bool EthStubServer::listening()
{
return /*client() ? client()->haveNetwork() :*/ false;
}
bool EthStubServer::isMining()
bool EthStubServer::mining()
{
return client() ? client()->isMining() : false;
}

4
libethrpc/EthStubServer.h

@ -46,8 +46,8 @@ public:
virtual std::string fromAscii(const int& padding, const std::string& s);
virtual double fromFixed(const std::string& s);
virtual std::string gasPrice();
virtual bool isListening();
virtual bool isMining();
virtual bool listening();
virtual bool mining();
virtual std::string key();
virtual Json::Value keys();
virtual std::string lll(const std::string& s);

28
libethrpc/abstractethstubserver.h

@ -23,12 +23,12 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "padding",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromFixedI);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::keyI);
this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::keysI);
this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::lllI);
this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "json",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::messagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI);
@ -96,16 +96,6 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
response = this->gasPrice();
}
inline virtual void isListeningI(const Json::Value& request, Json::Value& response)
{
response = this->isListening();
}
inline virtual void isMiningI(const Json::Value& request, Json::Value& response)
{
response = this->isMining();
}
inline virtual void keyI(const Json::Value& request, Json::Value& response)
{
response = this->key();
@ -116,6 +106,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
response = this->keys();
}
inline virtual void listeningI(const Json::Value& request, Json::Value& response)
{
response = this->listening();
}
inline virtual void lllI(const Json::Value& request, Json::Value& response)
{
response = this->lll(request["s"].asString());
@ -126,6 +121,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
response = this->messages(request["json"]);
}
inline virtual void miningI(const Json::Value& request, Json::Value& response)
{
response = this->mining();
}
inline virtual void numberI(const Json::Value& request, Json::Value& response)
{
response = this->number();
@ -207,12 +207,12 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual std::string fromAscii(const int& padding, const std::string& s) = 0;
virtual double fromFixed(const std::string& s) = 0;
virtual std::string gasPrice() = 0;
virtual bool isListening() = 0;
virtual bool isMining() = 0;
virtual std::string key() = 0;
virtual Json::Value keys() = 0;
virtual bool listening() = 0;
virtual std::string lll(const std::string& s) = 0;
virtual Json::Value messages(const Json::Value& json) = 0;
virtual bool mining() = 0;
virtual int number() = 0;
virtual int peerCount() = 0;
virtual std::string secretToAddress(const std::string& s) = 0;

4
libethrpc/eth.js

@ -19,9 +19,9 @@ else if (typeof(String.prototype.pad) === "undefined")
var spec = [
// properties
{ "method": "coinbase", "params": null, "order": [], "returns" : "" },
{ "method": "isListening", "params": null, "order": [], "returns" : false },
{ "method": "listening", "params": null, "order": [], "returns" : false },
{ "method": "setListening", "params": { "l": "" }, "order" : ["l"], "returns" : undefined},
{ "method": "isMining", "params": null, "order": [], "returns" : false },
{ "method": "mining", "params": null, "order": [], "returns" : false },
{ "method": "setMining", "params": { "l": "" }, "order" : ["l"], "returns" : undefined},
{ "method": "gasPrice", "params": null, "order": [], "returns" : "" },
{ "method": "key", "params": null, "order": [], "returns" : "" },

4
libethrpc/spec.json

@ -1,8 +1,8 @@
[
{ "method": "coinbase", "params": null, "order": [], "returns" : "" },
{ "method": "isListening", "params": null, "order": [], "returns" : false },
{ "method": "listening", "params": null, "order": [], "returns" : false },
{ "method": "setListening", "params": { "l": false }, "order" : ["l"], "returns" : []},
{ "method": "isMining", "params": null, "order": [], "returns" : false },
{ "method": "mining", "params": null, "order": [], "returns" : false },
{ "method": "setMining", "params": { "l": false }, "order" : ["l"], "returns" : []},
{ "method": "gasPrice", "params": null, "order": [], "returns" : "" },
{ "method": "key", "params": null, "order": [], "returns" : "" },

48
test/ethstubclient.h

@ -150,30 +150,6 @@ p["s"] = s;
}
bool isListening() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("isListening",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool isMining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("isMining",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string key() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -198,6 +174,18 @@ p["s"] = s;
}
bool listening() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("listening",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string lll(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -224,6 +212,18 @@ p["s"] = s;
}
bool mining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("mining",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int number() throw (jsonrpc::JsonRpcException)
{
Json::Value p;

4
test/jsonrpc.cpp

@ -129,11 +129,11 @@ BOOST_AUTO_TEST_CASE(jsonrpc_isMining)
cnote << "Testing jsonrpc isMining...";
web3.ethereum()->startMining();
bool miningOn = jsonrpcClient->isMining();
bool miningOn = jsonrpcClient->mining();
BOOST_CHECK_EQUAL(miningOn, web3.ethereum()->isMining());
web3.ethereum()->stopMining();
bool miningOff = jsonrpcClient->isMining();
bool miningOff = jsonrpcClient->mining();
BOOST_CHECK_EQUAL(miningOff, web3.ethereum()->isMining());
}

Loading…
Cancel
Save