Browse Source

udpated eth_compileSolidity

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
42e934baf4
  1. 38
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 2
      libweb3jsonrpc/WebThreeStubServerBase.h
  3. 4
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 2
      libweb3jsonrpc/spec.json
  5. 6
      test/libweb3jsonrpc/webthreestubclient.h

38
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 // TODO throw here jsonrpc errors
string res; string res;
vector<string> errors; vector<string> errors;
res = toJS(dev::eth::compileLLL(_code, true, &errors)); res = toJS(dev::eth::compileLLL(_source, true, &errors));
cwarn << "LLL compilation errors: " << errors; cwarn << "LLL compilation errors: " << errors;
return res; return res;
} }
string WebThreeStubServerBase::eth_compileSerpent(string const& _code) string WebThreeStubServerBase::eth_compileSerpent(string const& _source)
{ {
// TODO throw here jsonrpc errors // TODO throw here jsonrpc errors
string res; string res;
(void)_code; (void)_source;
#if ETH_SERPENT || !ETH_TRUE #if ETH_SERPENT || !ETH_TRUE
try try
{ {
res = toJS(dev::asBytes(::compile(_code))); res = toJS(dev::asBytes(::compile(_source)));
} }
catch (string err) catch (string err)
{ {
@ -793,26 +793,46 @@ string WebThreeStubServerBase::eth_compileSerpent(string const& _code)
return res; return res;
} }
string WebThreeStubServerBase::eth_compileSolidity(string const& _code) Json::Value WebThreeStubServerBase::eth_compileSolidity(string const& _source)
{ {
// TOOD throw here jsonrpc errors // TOOD throw here jsonrpc errors
(void)_code; Json::Value res(Json::objectValue);
string res;
#if ETH_SOLIDITY || !ETH_TRUE #if ETH_SOLIDITY || !ETH_TRUE
dev::solidity::CompilerStack compiler; dev::solidity::CompilerStack compiler;
try 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) catch (dev::Exception const& exception)
{ {
ostringstream error; ostringstream error;
solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler); solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler);
cwarn << "Solidity compilation error: " << error.str(); cwarn << "Solidity compilation error: " << error.str();
return Json::Value(Json::objectValue);
} }
catch (...) catch (...)
{ {
cwarn << "Uncought solidity compilation exception"; cwarn << "Uncought solidity compilation exception";
return Json::Value(Json::objectValue);
} }
#endif #endif
return res; return res;

2
libweb3jsonrpc/WebThreeStubServerBase.h

@ -103,7 +103,7 @@ public:
virtual Json::Value eth_getCompilers(); virtual Json::Value eth_getCompilers();
virtual std::string eth_compileLLL(std::string const& _s); virtual std::string eth_compileLLL(std::string const& _s);
virtual std::string eth_compileSerpent(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_newFilter(Json::Value const& _json);
virtual std::string eth_newFilterEx(Json::Value const& _json); virtual std::string eth_newFilterEx(Json::Value const& _json);
virtual std::string eth_newBlockFilter(std::string const& _filter); virtual std::string eth_newBlockFilter(std::string const& _filter);

4
libweb3jsonrpc/abstractwebthreestubserver.h

@ -45,7 +45,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_getCompilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getCompilersI); this->bindAndAddMethod(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_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_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_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_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); 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::AbstractServer<AbstractWebThr
virtual Json::Value eth_getCompilers() = 0; virtual Json::Value eth_getCompilers() = 0;
virtual std::string eth_compileLLL(const std::string& param1) = 0; virtual std::string eth_compileLLL(const std::string& param1) = 0;
virtual std::string eth_compileSerpent(const std::string& param1) = 0; virtual std::string eth_compileSerpent(const std::string& param1) = 0;
virtual std::string eth_compileSolidity(const std::string& param1) = 0; virtual Json::Value eth_compileSolidity(const std::string& param1) = 0;
virtual std::string eth_newFilter(const Json::Value& param1) = 0; virtual std::string eth_newFilter(const Json::Value& param1) = 0;
virtual std::string eth_newFilterEx(const Json::Value& param1) = 0; virtual std::string eth_newFilterEx(const Json::Value& param1) = 0;
virtual std::string eth_newBlockFilter(const std::string& param1) = 0; virtual std::string eth_newBlockFilter(const std::string& param1) = 0;

2
libweb3jsonrpc/spec.json

@ -34,7 +34,7 @@
{ "name": "eth_getCompilers", "params": [], "order": [], "returns": []}, { "name": "eth_getCompilers", "params": [], "order": [], "returns": []},
{ "name": "eth_compileLLL", "params": [""], "order": [], "returns": ""}, { "name": "eth_compileLLL", "params": [""], "order": [], "returns": ""},
{ "name": "eth_compileSerpent", "params": [""], "order": [], "returns": ""}, { "name": "eth_compileSerpent", "params": [""], "order": [], "returns": ""},
{ "name": "eth_compileSolidity", "params": [""], "order": [], "returns": ""}, { "name": "eth_compileSolidity", "params": [""], "order": [], "returns": {}},
{ "name": "eth_newFilter", "params": [{}], "order": [], "returns": ""}, { "name": "eth_newFilter", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_newFilterEx", "params": [{}], "order": [], "returns": ""}, { "name": "eth_newFilterEx", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_newBlockFilter", "params": [""], "order": [], "returns": ""}, { "name": "eth_newBlockFilter", "params": [""], "order": [], "returns": ""},

6
test/libweb3jsonrpc/webthreestubclient.h

@ -354,13 +354,13 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
std::string eth_compileSolidity(const std::string& param1) throw (jsonrpc::JsonRpcException) Json::Value eth_compileSolidity(const std::string& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p.append(param1); p.append(param1);
Json::Value result = this->CallMethod("eth_compileSolidity",p); Json::Value result = this->CallMethod("eth_compileSolidity",p);
if (result.isString()) if (result.isObject())
return result.asString(); return result;
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }

Loading…
Cancel
Save