Browse Source

added storageAt which dumps contract storage

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
47434e62c3
  1. 2
      libjsqrc/ethereum.min.js
  2. 15
      libweb3jsonrpc/WebThreeStubServer.cpp
  3. 1
      libweb3jsonrpc/WebThreeStubServer.h
  4. 7
      libweb3jsonrpc/abstractwebthreestubserver.h
  5. 1
      libweb3jsonrpc/spec.json
  6. 13
      test/webthreestubclient.h

2
libjsqrc/ethereum.min.js

File diff suppressed because one or more lines are too long

15
libweb3jsonrpc/WebThreeStubServer.cpp

@ -109,6 +109,14 @@ static Json::Value toJson(dev::eth::LogEntry const& _e)
return res;
}
static Json::Value toJson(std::map<u256, u256> const& _storage)
{
Json::Value res(Json::objectValue);
for (auto i: _storage)
res[toJS(i.first)] = toJS(i.second);
return res;
}
/*static*/ Json::Value toJson(dev::eth::LogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7.
{
Json::Value res;
@ -651,6 +659,13 @@ std::string WebThreeStubServer::eth_stateAt(string const& _address, string const
return client() ? toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)) : "";
}
Json::Value WebThreeStubServer::eth_storageAt(string const& _address)
{
if (!client())
return Json::Value(Json::objectValue);
return toJson(client()->storageAt(jsToAddress(_address)));
}
std::string WebThreeStubServer::eth_transact(Json::Value const& _json)
{
std::string ret;

1
libweb3jsonrpc/WebThreeStubServer.h

@ -90,6 +90,7 @@ public:
virtual bool eth_setMining(bool const& _mining);
virtual std::string eth_solidity(std::string const& _code);
virtual std::string eth_stateAt(std::string const& _address, std::string const& _storage);
virtual Json::Value eth_storageAt(std::string const& _address);
virtual std::string eth_transact(Json::Value const& _json);
virtual Json::Value eth_transactionByHash(std::string const& _hash, int const& _i);
virtual Json::Value eth_transactionByNumber(int const& _number, int const& _i);

7
libweb3jsonrpc/abstractwebthreestubserver.h

@ -43,6 +43,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("eth_setMining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_solidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_solidityI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_stateAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_storageAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_storageAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transact", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transactionByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByNumberI);
@ -210,6 +211,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_stateAt(request[0u].asString(), request[1u].asString());
}
inline virtual void eth_storageAtI(const Json::Value& request, Json::Value& response)
{
response = this->eth_storageAt(request[0u].asString());
}
inline virtual void eth_transactI(const Json::Value& request, Json::Value& response)
{
response = this->eth_transact(request[0u]);
@ -311,6 +317,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual bool eth_setMining(const bool& param1) = 0;
virtual std::string eth_solidity(const std::string& param1) = 0;
virtual std::string eth_stateAt(const std::string& param1, const std::string& param2) = 0;
virtual Json::Value eth_storageAt(const std::string& param1) = 0;
virtual std::string eth_transact(const Json::Value& param1) = 0;
virtual Json::Value eth_transactionByHash(const std::string& param1, const int& param2) = 0;
virtual Json::Value eth_transactionByNumber(const int& param1, const int& param2) = 0;

1
libweb3jsonrpc/spec.json

@ -16,6 +16,7 @@
{ "method": "eth_stateAt", "params": ["", ""], "order": [], "returns": ""},
{ "method": "eth_countAt", "params": [""], "order": [], "returns" : 0.0},
{ "method": "eth_codeAt", "params": [""], "order": [], "returns": ""},
{ "method": "eth_storageAt", "params": [""], "order": [], "returns": {}},
{ "method": "eth_transact", "params": [{}], "order": [], "returns": ""},
{ "method": "eth_call", "params": [{}], "order": [], "returns": ""},

13
test/webthreestubclient.h

@ -407,6 +407,19 @@ p.append(param2);
}
Json::Value eth_storageAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_storageAt",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;

Loading…
Cancel
Save