From 0c8f4d4e1109751fa5b89c3afd23abf2d0fa3125 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 29 Jul 2015 15:44:53 +0200 Subject: [PATCH] Store the response as a string. --- libjsconsole/JSV8Connector.cpp | 2 +- libjsconsole/JSV8Connector.h | 17 +++++++++------ libjsconsole/JSV8RemoteConnector.cpp | 29 +++++++++++++++++++------ libjsconsole/JSV8RemoteConnector.h | 32 ++++++++++++++++++++++------ libjsengine/JSEngine.h | 2 ++ libjsengine/JSPrinter.h | 2 ++ libjsengine/JSV8Engine.h | 2 ++ libjsengine/JSV8Printer.h | 2 ++ libjsengine/JSV8RPC.cpp | 8 ------- libjsengine/JSV8RPC.h | 8 +++---- 10 files changed, 72 insertions(+), 32 deletions(-) diff --git a/libjsconsole/JSV8Connector.cpp b/libjsconsole/JSV8Connector.cpp index ed560a368..12fbe0bae 100644 --- a/libjsconsole/JSV8Connector.cpp +++ b/libjsconsole/JSV8Connector.cpp @@ -39,7 +39,7 @@ bool JSV8Connector::StopListening() bool JSV8Connector::SendResponse(std::string const& _response, void* _addInfo) { (void)_addInfo; - m_lastResponse = _response.c_str(); + m_lastResponse = _response; return true; } diff --git a/libjsconsole/JSV8Connector.h b/libjsconsole/JSV8Connector.h index 34c38fed1..1a908e885 100644 --- a/libjsconsole/JSV8Connector.h +++ b/libjsconsole/JSV8Connector.h @@ -22,6 +22,7 @@ #pragma once +#include #include #include @@ -30,20 +31,24 @@ namespace dev namespace eth { -class JSV8Connector: public jsonrpc::AbstractServerConnector, public JSV8RPC +class JSV8Connector: public jsonrpc::AbstractServerConnector, private JSV8RPC { - public: JSV8Connector(JSV8Engine const& _engine): JSV8RPC(_engine) {} virtual ~JSV8Connector(); // implement AbstractServerConnector interface - bool StartListening(); - bool StopListening(); - bool SendResponse(std::string const& _response, void* _addInfo = nullptr); + bool StartListening() override; + bool StopListening() override; + bool SendResponse(std::string const& _response, void* _addInfo = nullptr) override; +private: // implement JSV8RPC interface - void onSend(char const* _payload); + void onSend(char const* _payload) override; + + char const* lastResponse() const override { return m_lastResponse.c_str(); } + + std::string m_lastResponse = R"({"id": 1, "jsonrpc": "2.0", "error": "Uninitalized JSV8RPC!"})"; }; } diff --git a/libjsconsole/JSV8RemoteConnector.cpp b/libjsconsole/JSV8RemoteConnector.cpp index 72e64faae..55bda4e72 100644 --- a/libjsconsole/JSV8RemoteConnector.cpp +++ b/libjsconsole/JSV8RemoteConnector.cpp @@ -1,10 +1,27 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSV8RemoteConnector.cpp + * @author Marek Kotewicz + * @date 2015 + * Connector from the standalone javascript console to a remote RPC node. + */ #include "JSV8RemoteConnector.h" -using namespace std; using namespace dev; using namespace dev::eth; @@ -13,8 +30,6 @@ void JSV8RemoteConnector::onSend(char const* _payload) m_request.setUrl(m_url); m_request.setBody(_payload); long code; - string response; - tie(code, response) = m_request.post(); + tie(code, m_lastResponse) = m_request.post(); (void)code; - m_lastResponse = response.c_str(); } diff --git a/libjsconsole/JSV8RemoteConnector.h b/libjsconsole/JSV8RemoteConnector.h index 5d28094ad..d765f13da 100644 --- a/libjsconsole/JSV8RemoteConnector.h +++ b/libjsconsole/JSV8RemoteConnector.h @@ -1,10 +1,27 @@ -// -// Created by Marek Kotewicz on 15/06/15. -// +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file JSV8RemoteConnector.cpp + * @author Marek Kotewicz + * @date 2015 + * Connector from the standalone javascript console to a remote RPC node. + */ #pragma once -#include #include #include "CURLRequest.h" @@ -13,18 +30,21 @@ namespace dev namespace eth { -class JSV8RemoteConnector : public JSV8RPC +class JSV8RemoteConnector: private JSV8RPC { public: JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {} virtual ~JSV8RemoteConnector() {} +private: // implement JSV8RPC interface - void onSend(char const* _payload); + void onSend(char const* _payload) override; + const char* lastResponse() const override { return m_lastResponse.c_str(); } private: std::string m_url; + std::string m_lastResponse = R"({"id": 1, "jsonrpc": "2.0", "error": "Uninitalized JSV8RPC!"})"; CURLRequest m_request; }; diff --git a/libjsengine/JSEngine.h b/libjsengine/JSEngine.h index d44fc7828..adebfdd13 100644 --- a/libjsengine/JSEngine.h +++ b/libjsengine/JSEngine.h @@ -23,6 +23,8 @@ #pragma once #include +/// Do not use libstd headers here, it will break on MacOS. + namespace dev { namespace eth diff --git a/libjsengine/JSPrinter.h b/libjsengine/JSPrinter.h index bf13fcea7..6ced09eff 100644 --- a/libjsengine/JSPrinter.h +++ b/libjsengine/JSPrinter.h @@ -24,6 +24,8 @@ #include "JSEngine.h" +/// Do not use libstd headers here, it will break on MacOS. + namespace dev { namespace eth diff --git a/libjsengine/JSV8Engine.h b/libjsengine/JSV8Engine.h index db75cafbc..9d08d9b43 100644 --- a/libjsengine/JSV8Engine.h +++ b/libjsengine/JSV8Engine.h @@ -28,6 +28,8 @@ #pragma clang diagnostic pop #include "JSEngine.h" +/// Do not use libstd headers here, it will break on MacOS. + namespace dev { namespace eth diff --git a/libjsengine/JSV8Printer.h b/libjsengine/JSV8Printer.h index 2ec9c78b6..ec2f2aac1 100644 --- a/libjsengine/JSV8Printer.h +++ b/libjsengine/JSV8Printer.h @@ -25,6 +25,8 @@ #include "JSPrinter.h" #include "JSV8Engine.h" +/// Do not use libstd headers here, it will break on MacOS. + namespace dev { namespace eth diff --git a/libjsengine/JSV8RPC.cpp b/libjsengine/JSV8RPC.cpp index 0c61eb37c..a24420d43 100644 --- a/libjsengine/JSV8RPC.cpp +++ b/libjsengine/JSV8RPC.cpp @@ -89,12 +89,4 @@ JSV8RPC::JSV8RPC(JSV8Engine const& _engine): m_engine(_engine) v8::Handle func = v8::Handle::Cast(web3object->Get(setProvider)); v8::Local values[1] = {obj}; func->Call(func, 1, values); - - m_lastResponse = R"( - { - "id": 1, - "jsonrpc": "2.0", - "error": "Uninitalized JSV8RPC!" - } - )"; } diff --git a/libjsengine/JSV8RPC.h b/libjsengine/JSV8RPC.h index a2180ef51..13e225e93 100644 --- a/libjsengine/JSV8RPC.h +++ b/libjsengine/JSV8RPC.h @@ -24,6 +24,8 @@ #include +/// Do not use libstd headers here, it will break on MacOS. + namespace dev { namespace eth @@ -33,14 +35,12 @@ class JSV8RPC { public: JSV8RPC(JSV8Engine const& _engine); + virtual ~JSV8RPC() { } virtual void onSend(char const* _payload) = 0; - char const* lastResponse() const { return m_lastResponse; } + virtual char const* lastResponse() const = 0; private: JSV8Engine const& m_engine; - -protected: - char const* m_lastResponse; }; }