From 42e934baf4a44689740a5f03259965b317ebefb5 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 9 Jun 2015 13:21:56 +0200 Subject: [PATCH] udpated eth_compileSolidity --- libweb3jsonrpc/WebThreeStubServerBase.cpp | 38 ++++++++++++++++----- libweb3jsonrpc/WebThreeStubServerBase.h | 2 +- libweb3jsonrpc/abstractwebthreestubserver.h | 4 +-- libweb3jsonrpc/spec.json | 2 +- test/libweb3jsonrpc/webthreestubclient.h | 6 ++-- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 0f8181cac..3c03bd378 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -761,25 +761,25 @@ Json::Value WebThreeStubServerBase::eth_getCompilers() } -string WebThreeStubServerBase::eth_compileLLL(string const& _code) +string WebThreeStubServerBase::eth_compileLLL(string const& _source) { // TODO throw here jsonrpc errors string res; vector errors; - res = toJS(dev::eth::compileLLL(_code, true, &errors)); + res = toJS(dev::eth::compileLLL(_source, true, &errors)); cwarn << "LLL compilation errors: " << errors; return res; } -string WebThreeStubServerBase::eth_compileSerpent(string const& _code) +string WebThreeStubServerBase::eth_compileSerpent(string const& _source) { // TODO throw here jsonrpc errors string res; - (void)_code; + (void)_source; #if ETH_SERPENT || !ETH_TRUE try { - res = toJS(dev::asBytes(::compile(_code))); + res = toJS(dev::asBytes(::compile(_source))); } catch (string err) { @@ -793,26 +793,46 @@ string WebThreeStubServerBase::eth_compileSerpent(string const& _code) return res; } -string WebThreeStubServerBase::eth_compileSolidity(string const& _code) +Json::Value WebThreeStubServerBase::eth_compileSolidity(string const& _source) { // TOOD throw here jsonrpc errors - (void)_code; - string res; + Json::Value res(Json::objectValue); #if ETH_SOLIDITY || !ETH_TRUE dev::solidity::CompilerStack compiler; try { - res = toJS(compiler.compile(_code, true)); + compiler.addSource("source", _source); + compiler.compile(); + + for (string const& name: compiler.getContractNames()) + { + Json::Value contract(Json::objectValue); + contract["code"] = toJS(compiler.getBytecode(name)); + + Json::Value info(Json::objectValue); + info["source"] = _source; + info["language"] = ""; + info["languageVersion"] = ""; + info["compilerVersion"] = ""; + info["abiDefinition"] = compiler.getInterface(name); + info["userDoc"] = compiler.getMetadata(name, dev::solidity::DocumentationType::NatspecUser); + info["developerDoc"] = compiler.getMetadata(name, dev::solidity::DocumentationType::NatspecDev); + contract["info"] = info; + + res[name] = contract; + } } catch (dev::Exception const& exception) { ostringstream error; solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler); cwarn << "Solidity compilation error: " << error.str(); + return Json::Value(Json::objectValue); } catch (...) { cwarn << "Uncought solidity compilation exception"; + return Json::Value(Json::objectValue); } #endif return res; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 7cdc96682..031e62746 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -103,7 +103,7 @@ public: virtual Json::Value eth_getCompilers(); virtual std::string eth_compileLLL(std::string const& _s); virtual std::string eth_compileSerpent(std::string const& _s); - virtual std::string eth_compileSolidity(std::string const& _code); + virtual Json::Value eth_compileSolidity(std::string const& _code); virtual std::string eth_newFilter(Json::Value const& _json); virtual std::string eth_newFilterEx(Json::Value const& _json); virtual std::string eth_newBlockFilter(std::string const& _filter); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index c7306af3f..c6076bcbc 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -45,7 +45,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("eth_getCompilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getCompilersI); this->bindAndAddMethod(jsonrpc::Procedure("eth_compileLLL", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileLLLI); this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSerpent", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSerpentI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSolidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSolidityI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSolidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSolidityI); this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilterEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterExI); this->bindAndAddMethod(jsonrpc::Procedure("eth_newBlockFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newBlockFilterI); @@ -372,7 +372,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("eth_compileSolidity",p); - if (result.isString()) - return result.asString(); + if (result.isObject()) + return result; else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); }