From 18ce0e9a876c2a54bedefbca649b3f65a28c1291 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 14 Oct 2014 21:53:11 +0200 Subject: [PATCH] setCoinbase method --- libethrpc/EthStubServer.cpp | 14 ++++++++++---- libethrpc/EthStubServer.h | 5 +++-- libethrpc/abstractethstubserver.h | 15 +++++++++++---- libethrpc/eth.js | 5 +++-- libethrpc/spec.json | 5 +++-- test/ethstubclient.h | 25 +++++++++++++++++++------ 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/libethrpc/EthStubServer.cpp b/libethrpc/EthStubServer.cpp index 42c1096dc..f2f83ddb0 100644 --- a/libethrpc/EthStubServer.cpp +++ b/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) diff --git a/libethrpc/EthStubServer.h b/libethrpc/EthStubServer.h index 37d20a0f3..d1ba16ada 100644 --- a/libethrpc/EthStubServer.h +++ b/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); diff --git a/libethrpc/abstractethstubserver.h b/libethrpc/abstractethstubserver.h index 4595ea9df..02234e393 100644 --- a/libethrpc/abstractethstubserver.h +++ b/libethrpc/abstractethstubserver.h @@ -32,8 +32,9 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerbindAndAddMethod(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::AbstractServersecretToAddress(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::AbstractServerclient->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());