Browse Source

jsonrpc api changes in progress3

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
32d404a32b
  1. 93
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 10
      libweb3jsonrpc/WebThreeStubServerBase.h
  3. 32
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 9
      libweb3jsonrpc/spec.json
  5. 30
      test/webthreestubclient.h

93
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -307,7 +307,7 @@ std::string WebThreeStubServerBase::eth_getBalance(string const& _address, strin
}
Json::Value WebThreeStubServerBase::eth_getStorage(string const& _address, std::string const& _blockNumber)
Json::Value WebThreeStubServerBase::eth_getStorage(string const& _address, string const& _blockNumber)
{
Address address;
int number;
@ -326,6 +326,77 @@ Json::Value WebThreeStubServerBase::eth_getStorage(string const& _address, std::
return toJson(client()->storageAt(address, number));
}
std::string WebThreeStubServerBase::eth_getStorageAt(string const& _address, string const& _position, string const& _blockNumber)
{
Address address;
u256 position;
int number;
try
{
address = jsToAddress(_address);
position = jsToU256(_position);
number = jsToInt(_blockNumber);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
//TODO: fix this naming !
return toJS(client()->stateAt(address, position, number));
}
string WebThreeStubServerBase::eth_getTransactionCount(string const& _address, string const& _blockNumber)
{
Address address;
int number;
try
{
address = jsToAddress(_address);
number = jsToInt(_blockNumber);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->countAt(address, number));
}
string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(std::string const& _blockHash)
{
h256 hash;
try
{
hash = jsToFixed<32>(_blockHash);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->transactionCount(hash));
}
string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber)
{
int number;
try
{
number = jsToInt(_blockNumber);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->transactionCount(client()->hashFromNumber(number)));
}
std::string WebThreeStubServerBase::shh_addToGroup(std::string const& _group, std::string const& _who)
{
(void)_group;
@ -425,21 +496,6 @@ std::string WebThreeStubServerBase::eth_codeAt(string const& _address)
return jsFromBinary(client()->codeAt(jsToAddress(_address), client()->getDefault()));
}
double WebThreeStubServerBase::eth_countAt(string const& _address)
{
return (double)(uint64_t)client()->countAt(jsToAddress(_address), client()->getDefault());
}
double WebThreeStubServerBase::eth_transactionCountByHash(std::string const& _hash)
{
return client()->transactionCount(jsToFixed<32>(_hash));
}
double WebThreeStubServerBase::eth_transactionCountByNumber(int _number)
{
return client()->transactionCount(client()->hashFromNumber(_number));
}
double WebThreeStubServerBase::eth_uncleCountByHash(std::string const& _hash)
{
return client()->transactionCount(jsToFixed<32>(_hash));
@ -692,11 +748,6 @@ bool WebThreeStubServerBase::shh_uninstallFilter(int _id)
return true;
}
std::string WebThreeStubServerBase::eth_stateAt(string const& _address, string const& _storage)
{
return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), client()->getDefault()));
}
std::string WebThreeStubServerBase::eth_transact(Json::Value const& _json)
{
std::string ret;

10
libweb3jsonrpc/WebThreeStubServerBase.h

@ -79,10 +79,12 @@ public:
virtual std::string eth_blockNumber();
virtual std::string eth_getBalance(std::string const& _address, std::string const& _blockNumber);
virtual Json::Value eth_getStorage(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_getStorageAt(std::string const& _address, std::string const& _position, std::string const& _blockNumber);
virtual std::string eth_getTransactionCount(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_getBlockTransactionCountByHash(std::string const& _blockHash);
virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber);
virtual std::string eth_stateAt(std::string const& _address, std::string const& _storage);
virtual Json::Value eth_blockByHash(std::string const& _hash);
virtual Json::Value eth_blockByNumber(int _number);
virtual std::string eth_call(Json::Value const& _json);
@ -90,9 +92,7 @@ public:
virtual std::string eth_codeAt(std::string const& _address);
virtual Json::Value eth_compilers();
virtual double eth_countAt(std::string const& _address);
virtual double eth_transactionCountByHash(std::string const& _hash);
virtual double eth_transactionCountByNumber(int _number);
virtual double eth_uncleCountByHash(std::string const& _hash);
virtual double eth_uncleCountByNumber(int _number);

32
libweb3jsonrpc/abstractwebthreestubserver.h

@ -22,10 +22,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_blockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_blockNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBalance", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBalanceI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getStorage", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getStorageI);
this->bindAndAddMethod(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(jsonrpc::Procedure("eth_countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_countAtI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_transactionCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_transactionCountByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_transactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionCountByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getStorageAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getStorageAtI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getTransactionCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getTransactionCountI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_uncleCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_uncleCountByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_uncleCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_uncleCountByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_codeAtI);
@ -115,21 +115,21 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{
response = this->eth_getStorage(request[0u].asString(), request[1u].asString());
}
inline virtual void eth_stateAtI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getStorageAtI(const Json::Value &request, Json::Value &response)
{
response = this->eth_stateAt(request[0u].asString(), request[1u].asString());
response = this->eth_getStorageAt(request[0u].asString(), request[1u].asString(), request[2u].asString());
}
inline virtual void eth_countAtI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getTransactionCountI(const Json::Value &request, Json::Value &response)
{
response = this->eth_countAt(request[0u].asString());
response = this->eth_getTransactionCount(request[0u].asString(), request[1u].asString());
}
inline virtual void eth_transactionCountByHashI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getBlockTransactionCountByHashI(const Json::Value &request, Json::Value &response)
{
response = this->eth_transactionCountByHash(request[0u].asString());
response = this->eth_getBlockTransactionCountByHash(request[0u].asString());
}
inline virtual void eth_transactionCountByNumberI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getBlockTransactionCountByNumberI(const Json::Value &request, Json::Value &response)
{
response = this->eth_transactionCountByNumber(request[0u].asInt());
response = this->eth_getBlockTransactionCountByNumber(request[0u].asString());
}
inline virtual void eth_uncleCountByHashI(const Json::Value &request, Json::Value &response)
{
@ -305,10 +305,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_blockNumber() = 0;
virtual std::string eth_getBalance(const std::string& param1, const std::string& param2) = 0;
virtual Json::Value eth_getStorage(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_stateAt(const std::string& param1, const std::string& param2) = 0;
virtual double eth_countAt(const std::string& param1) = 0;
virtual double eth_transactionCountByHash(const std::string& param1) = 0;
virtual double eth_transactionCountByNumber(int param1) = 0;
virtual std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_getBlockTransactionCountByHash(const std::string& param1) = 0;
virtual std::string eth_getBlockTransactionCountByNumber(const std::string& param1) = 0;
virtual double eth_uncleCountByHash(const std::string& param1) = 0;
virtual double eth_uncleCountByNumber(int param1) = 0;
virtual std::string eth_codeAt(const std::string& param1) = 0;

9
libweb3jsonrpc/spec.json

@ -11,11 +11,12 @@
{ "name": "eth_blockNumber", "params": [], "order": [], "returns" : ""},
{ "name": "eth_getBalance", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getStorage", "params": ["", ""], "order": [], "returns": {}},
{ "name": "eth_getStorageAt", "params": ["", "", ""], "order": [], "returns": ""},
{ "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_stateAt", "params": ["", ""], "order": [], "returns": ""},
{ "name": "eth_countAt", "params": [""], "order": [], "returns" : 0.0},
{ "name": "eth_transactionCountByHash", "params": [""], "order": [], "returns" : 0.0},
{ "name": "eth_transactionCountByNumber", "params": [0], "order": [], "returns" : 0.0},
{ "name": "eth_uncleCountByHash", "params": [""], "order": [], "returns" : 0.0},
{ "name": "eth_uncleCountByNumber", "params": [0], "order": [], "returns" : 0.0},
{ "name": "eth_codeAt", "params": [""], "order": [], "returns": ""},

30
test/webthreestubclient.h

@ -114,44 +114,46 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
Json::Value result = this->CallMethod("eth_stateAt",p);
p.append(param3);
Json::Value result = this->CallMethod("eth_getStorageAt",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
double eth_countAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_countAt",p);
if (result.isDouble())
return result.asDouble();
p.append(param2);
Json::Value result = this->CallMethod("eth_getTransactionCount",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
double eth_transactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
std::string eth_getBlockTransactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_transactionCountByHash",p);
if (result.isDouble())
return result.asDouble();
Json::Value result = this->CallMethod("eth_getBlockTransactionCountByHash",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
double eth_transactionCountByNumber(int param1) throw (jsonrpc::JsonRpcException)
std::string eth_getBlockTransactionCountByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_transactionCountByNumber",p);
if (result.isDouble())
return result.asDouble();
Json::Value result = this->CallMethod("eth_getBlockTransactionCountByNumber",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}

Loading…
Cancel
Save