Browse Source

setCoinbase method

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
18ce0e9a87
  1. 14
      libethrpc/EthStubServer.cpp
  2. 5
      libethrpc/EthStubServer.h
  3. 15
      libethrpc/abstractethstubserver.h
  4. 5
      libethrpc/eth.js
  5. 5
      libethrpc/spec.json
  6. 25
      test/ethstubclient.h

14
libethrpc/EthStubServer.cpp

@ -313,7 +313,13 @@ std::string EthStubServer::secretToAddress(const string &s)
return toJS(KeyPair(jsToSecret(s)).address());
}
Json::Value EthStubServer::setListening(const bool &l)
bool EthStubServer::setCoinbase(const std::string &address)
{
client()->setAddress(jsToAddress(address));
return true;
}
bool EthStubServer::setListening(const bool &l)
{
if (!client())
return Json::nullValue;
@ -322,10 +328,10 @@ Json::Value EthStubServer::setListening(const bool &l)
client()->startNetwork();
else
client()->stopNetwork();*/
return Json::nullValue;
return false;
}
Json::Value EthStubServer::setMining(const bool &l)
bool EthStubServer::setMining(const bool &l)
{
if (!client())
return Json::nullValue;
@ -334,7 +340,7 @@ Json::Value EthStubServer::setMining(const bool &l)
client()->startMining();
else
client()->stopMining();
return Json::nullValue;
return true;
}
std::string EthStubServer::sha3(const string &s)

5
libethrpc/EthStubServer.h

@ -55,8 +55,9 @@ public:
virtual int number();
virtual int peerCount();
virtual std::string secretToAddress(const std::string& s);
virtual Json::Value setListening(const bool& l);
virtual Json::Value setMining(const bool& l);
virtual bool setCoinbase(const std::string& address);
virtual bool setListening(const bool& l);
virtual bool setMining(const bool& l);
virtual std::string sha3(const std::string& s);
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s);
virtual std::string toAscii(const std::string& s);

15
libethrpc/abstractethstubserver.h

@ -32,8 +32,9 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
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);
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "address",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setCoinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "l",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toAsciiI);
@ -141,6 +142,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
response = this->secretToAddress(request["s"].asString());
}
inline virtual void setCoinbaseI(const Json::Value& request, Json::Value& response)
{
response = this->setCoinbase(request["address"].asString());
}
inline virtual void setListeningI(const Json::Value& request, Json::Value& response)
{
response = this->setListening(request["l"].asBool());
@ -216,8 +222,9 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual int number() = 0;
virtual int peerCount() = 0;
virtual std::string secretToAddress(const std::string& s) = 0;
virtual Json::Value setListening(const bool& l) = 0;
virtual Json::Value setMining(const bool& l) = 0;
virtual bool setCoinbase(const std::string& address) = 0;
virtual bool setListening(const bool& l) = 0;
virtual bool setMining(const bool& l) = 0;
virtual std::string sha3(const std::string& s) = 0;
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s) = 0;
virtual std::string toAscii(const std::string& s) = 0;

5
libethrpc/eth.js

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

5
libethrpc/spec.json

@ -1,9 +1,10 @@
[
{ "method": "coinbase", "params": null, "order": [], "returns" : "" },
{ "method": "setCoinbase", "params": { "address": "" }, "order": ["address"], "returns" : true },
{ "method": "listening", "params": null, "order": [], "returns" : false },
{ "method": "setListening", "params": { "l": false }, "order" : ["l"], "returns" : []},
{ "method": "setListening", "params": { "l": false }, "order" : ["l"], "returns" : true },
{ "method": "mining", "params": null, "order": [], "returns" : false },
{ "method": "setMining", "params": { "l": false }, "order" : ["l"], "returns" : []},
{ "method": "setMining", "params": { "l": false }, "order" : ["l"], "returns" : true },
{ "method": "gasPrice", "params": null, "order": [], "returns" : "" },
{ "method": "key", "params": null, "order": [], "returns" : "" },
{ "method": "keys", "params": null, "order": [], "returns" : [] },

25
test/ethstubclient.h

@ -261,27 +261,40 @@ p["s"] = s;
}
Json::Value setListening(const bool& l) throw (jsonrpc::JsonRpcException)
bool setCoinbase(const std::string& address) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
Json::Value result = this->client->CallMethod("setCoinbase",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool setListening(const bool& l) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["l"] = l;
Json::Value result = this->client->CallMethod("setListening",p);
if (result.isArray())
return result;
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value setMining(const bool& l) throw (jsonrpc::JsonRpcException)
bool setMining(const bool& l) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["l"] = l;
Json::Value result = this->client->CallMethod("setMining",p);
if (result.isArray())
return result;
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());

Loading…
Cancel
Save