From c5a1df4700833a5045d1c5f707e96d1dbc338e45 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 27 Oct 2014 17:06:14 +0100 Subject: [PATCH] missing setDefaultBlock method --- libweb3jsonrpc/WebThreeStubServer.cpp | 12 +++++++++++- libweb3jsonrpc/WebThreeStubServer.h | 1 + libweb3jsonrpc/abstractwebthreestubserver.h | 7 +++++++ libweb3jsonrpc/spec.json | 1 + test/webthreestubclient.h | 13 +++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index ba9e5105f..30cdf61d5 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -343,10 +343,20 @@ int WebThreeStubServer::peerCount() bool WebThreeStubServer::setCoinbase(std::string const& _address) { + if (!client()) + return false; client()->setAddress(jsToAddress(_address)); return true; } +bool WebThreeStubServer::setDefaultBlock(int const& _block) +{ + if (!client()) + return false; + client()->setDefault(_block); + return true; +} + bool WebThreeStubServer::setListening(bool const& _listening) { if (_listening) @@ -359,7 +369,7 @@ bool WebThreeStubServer::setListening(bool const& _listening) bool WebThreeStubServer::setMining(bool const& _mining) { if (!client()) - return Json::nullValue; + return false; if (_mining) client()->startMining(); diff --git a/libweb3jsonrpc/WebThreeStubServer.h b/libweb3jsonrpc/WebThreeStubServer.h index b26b161c5..bb6403afe 100644 --- a/libweb3jsonrpc/WebThreeStubServer.h +++ b/libweb3jsonrpc/WebThreeStubServer.h @@ -58,6 +58,7 @@ public: virtual int number(); virtual int peerCount(); virtual bool setCoinbase(std::string const& _address); + virtual bool setDefaultBlock(int const& _block); virtual bool setListening(bool const& _listening); virtual bool setMining(bool const& _mining); virtual std::string stateAt(std::string const& _address, std::string const& _storage); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 417d034cd..226c585d5 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -33,6 +33,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::numberI); this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::peerCountI); this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::setCoinbaseI); + this->bindAndAddMethod(new jsonrpc::Procedure("setDefaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::setDefaultBlockI); this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setListeningI); this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setMiningI); this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::stateAtI); @@ -145,6 +146,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServersetCoinbase(request[0u].asString()); } + inline virtual void setDefaultBlockI(const Json::Value& request, Json::Value& response) + { + response = this->setDefaultBlock(request[0u].asInt()); + } + inline virtual void setListeningI(const Json::Value& request, Json::Value& response) { response = this->setListening(request[0u].asBool()); @@ -211,6 +217,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerclient->CallMethod("setDefaultBlock",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + + } + bool setListening(const bool& param1) throw (jsonrpc::JsonRpcException) { Json::Value p;