Browse Source

jsonrpc api changes in progress4

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
f3e7ab987c
  1. 193
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 19
      libweb3jsonrpc/WebThreeStubServerBase.h
  3. 48
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 16
      libweb3jsonrpc/spec.json
  5. 33
      test/webthreestubclient.h

193
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -368,6 +368,7 @@ string WebThreeStubServerBase::eth_getTransactionCount(string const& _address, s
string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(std::string const& _blockHash) string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(std::string const& _blockHash)
{ {
h256 hash; h256 hash;
try try
{ {
hash = jsToFixed<32>(_blockHash); hash = jsToFixed<32>(_blockHash);
@ -397,21 +398,54 @@ string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const
return toJS(client()->transactionCount(client()->hashFromNumber(number))); return toJS(client()->transactionCount(client()->hashFromNumber(number)));
} }
std::string WebThreeStubServerBase::shh_addToGroup(std::string const& _group, std::string const& _who) string WebThreeStubServerBase::eth_getUncleCountByBlockHash(std::string const& _blockHash)
{ {
(void)_group; h256 hash;
(void)_who;
return ""; try
{
hash = jsToFixed<32>(_blockHash);
} }
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->uncleCount(hash));
}
string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber)
{
int number;
Json::Value WebThreeStubServerBase::eth_blockByHash(std::string const& _hash) try
{
number = jsToInt(_blockNumber);
}
catch (...)
{ {
return toJson(client()->blockInfo(jsToFixed<32>(_hash))); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->uncleCount(client()->hashFromNumber(number)));
} }
Json::Value WebThreeStubServerBase::eth_blockByNumber(int _number) std::string WebThreeStubServerBase::eth_getData(string const& _address, string const& _blockNumber)
{ {
return toJson(client()->blockInfo(client()->hashFromNumber(_number))); Address address;
int number;
try
{
address = jsToAddress(_address);
number = jsToInt(_blockNumber);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return jsFromBinary(client()->codeAt(address, number));
} }
static TransactionSkeleton toTransaction(Json::Value const& _json) static TransactionSkeleton toTransaction(Json::Value const& _json)
@ -426,51 +460,70 @@ static TransactionSkeleton toTransaction(Json::Value const& _json)
ret.to = jsToAddress(_json["to"].asString()); ret.to = jsToAddress(_json["to"].asString());
else else
ret.creation = true; ret.creation = true;
if (!_json["value"].empty())
{
if (_json["value"].isString()) if (_json["value"].isString())
ret.value = jsToU256(_json["value"].asString()); ret.value = jsToU256(_json["value"].asString());
else if (_json["value"].isInt())
ret.value = u256(_json["value"].asInt());
}
if (!_json["gas"].empty())
{
if (_json["gas"].isString()) if (_json["gas"].isString())
ret.gas = jsToU256(_json["gas"].asString()); ret.gas = jsToU256(_json["gas"].asString());
else if (_json["gas"].isInt())
ret.gas = u256(_json["gas"].asInt());
}
if (!_json["gasPrice"].empty())
{
if (_json["gasPrice"].isString()) if (_json["gasPrice"].isString())
ret.gasPrice = jsToU256(_json["gasPrice"].asString()); ret.gasPrice = jsToU256(_json["gasPrice"].asString());
else if (_json["gasPrice"].isInt())
ret.gas = u256(_json["gas"].asInt());
}
if (!_json["data"].empty())
{
if (_json["data"].isString()) // ethereum.js has preconstructed the data array if (_json["data"].isString()) // ethereum.js has preconstructed the data array
ret.data = jsToBytes(_json["data"].asString()); ret.data = jsToBytes(_json["data"].asString());
else if (_json["data"].isArray()) // old style: array of 32-byte-padded values. TODO: remove PoC-8
for (auto i: _json["data"])
dev::operator +=(ret.data, padded(jsToBytes(i.asString()), 32));
}
if (_json["code"].isString()) if (_json["code"].isString())
ret.data = jsToBytes(_json["code"].asString()); ret.data = jsToBytes(_json["code"].asString());
return ret; return ret;
} }
bool WebThreeStubServerBase::eth_flush() std::string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json)
{ {
client()->flushTransactions(); TransactionSkeleton t;
return true;
try
{
t = toTransaction(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
std::string ret;
if (!t.from)
t.from = m_accounts->getDefaultTransactAccount();
if (t.creation)
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));;
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
if (m_accounts->isRealAccount(t.from))
authenticate(t, false);
else if (m_accounts->isProxyAccount(t.from))
authenticate(t, true);
return ret;
} }
std::string WebThreeStubServerBase::eth_call(Json::Value const& _json) std::string WebThreeStubServerBase::eth_call(Json::Value const& _json)
{ {
TransactionSkeleton t;
try
{
t = toTransaction(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
std::string ret; std::string ret;
TransactionSkeleton t = toTransaction(_json);
if (!t.from) if (!t.from)
t.from = m_accounts->getDefaultTransactAccount(); t.from = m_accounts->getDefaultTransactAccount();
if (!m_accounts->isRealAccount(t.from)) if (!m_accounts->isRealAccount(t.from))
@ -480,30 +533,61 @@ std::string WebThreeStubServerBase::eth_call(Json::Value const& _json)
if (!t.gas) if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice); t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
ret = toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice)); ret = toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice));
return ret; return ret;
} }
Json::Value WebThreeStubServerBase::eth_changed(int _id) bool WebThreeStubServerBase::eth_flush()
{ {
auto entries = client()->checkWatch(_id); client()->flushTransactions();
if (entries.size()) return true;
cnote << "FIRING WATCH" << _id << entries.size();
return toJson(entries);
} }
std::string WebThreeStubServerBase::eth_codeAt(string const& _address) Json::Value WebThreeStubServerBase::eth_getBlockByHash(string const& _blockHash)
{
h256 hash;
try
{
hash = jsToFixed<32>(_blockHash);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJson(client()->blockInfo(hash));
}
Json::Value WebThreeStubServerBase::eth_getBlockByNumber(string const& _blockNumber)
{
int number;
try
{
number = jsToInt(_blockNumber);
}
catch (...)
{ {
return jsFromBinary(client()->codeAt(jsToAddress(_address), client()->getDefault())); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJson(client()->blockInfo(client()->hashFromNumber(number)));
} }
double WebThreeStubServerBase::eth_uncleCountByHash(std::string const& _hash) std::string WebThreeStubServerBase::shh_addToGroup(std::string const& _group, std::string const& _who)
{ {
return client()->transactionCount(jsToFixed<32>(_hash)); (void)_group;
(void)_who;
return "";
} }
double WebThreeStubServerBase::eth_uncleCountByNumber(int _number) Json::Value WebThreeStubServerBase::eth_changed(int _id)
{ {
return client()->transactionCount(client()->hashFromNumber(_number)); auto entries = client()->checkWatch(_id);
if (entries.size())
cnote << "FIRING WATCH" << _id << entries.size();
return toJson(entries);
} }
std::string WebThreeStubServerBase::db_get(std::string const& _name, std::string const& _key) std::string WebThreeStubServerBase::db_get(std::string const& _name, std::string const& _key)
@ -748,27 +832,6 @@ bool WebThreeStubServerBase::shh_uninstallFilter(int _id)
return true; return true;
} }
std::string WebThreeStubServerBase::eth_transact(Json::Value const& _json)
{
std::string ret;
TransactionSkeleton t = toTransaction(_json);
if (!t.from)
t.from = m_accounts->getDefaultTransactAccount();
if (t.creation)
ret = toJS(right160(sha3(rlpList(t.from, client()->countAt(t.from)))));;
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
if (m_accounts->isRealAccount(t.from))
authenticate(t, false);
else if (m_accounts->isProxyAccount(t.from))
authenticate(t, true);
return ret;
}
void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _toProxy) void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _toProxy)
{ {
if (_toProxy) if (_toProxy)

19
libweb3jsonrpc/WebThreeStubServerBase.h

@ -83,21 +83,21 @@ public:
virtual std::string eth_getTransactionCount(std::string const& _address, 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_getBlockTransactionCountByHash(std::string const& _blockHash);
virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber); virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber);
virtual std::string eth_getUncleCountByBlockHash(std::string const& _blockHash);
virtual std::string eth_getUncleCountByBlockNumber(std::string const& _blockNumber);
virtual std::string eth_getData(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_sendTransaction(Json::Value const& _json);
virtual std::string eth_call(Json::Value const& _json);
virtual bool eth_flush();
virtual Json::Value eth_getBlockByHash(std::string const& _blockHash);
virtual Json::Value eth_getBlockByNumber(std::string const& _blockNumber);
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);
virtual Json::Value eth_changed(int _id);
virtual std::string eth_codeAt(std::string const& _address);
virtual Json::Value eth_changed(int _id);
virtual Json::Value eth_compilers(); virtual Json::Value eth_compilers();
virtual double eth_uncleCountByHash(std::string const& _hash);
virtual double eth_uncleCountByNumber(int _number);
virtual Json::Value eth_filterLogs(int _id); virtual Json::Value eth_filterLogs(int _id);
virtual bool eth_flush();
virtual Json::Value eth_logs(Json::Value const& _json); virtual Json::Value eth_logs(Json::Value const& _json);
@ -106,7 +106,6 @@ public:
virtual std::string eth_lll(std::string const& _s); virtual std::string eth_lll(std::string const& _s);
virtual std::string eth_serpent(std::string const& _s); virtual std::string eth_serpent(std::string const& _s);
virtual std::string eth_solidity(std::string const& _code); virtual std::string eth_solidity(std::string const& _code);
virtual std::string eth_transact(Json::Value const& _json);
virtual Json::Value eth_transactionByHash(std::string const& _hash, int _i); virtual Json::Value eth_transactionByHash(std::string const& _hash, int _i);
virtual Json::Value eth_transactionByNumber(int _number, int _i); virtual Json::Value eth_transactionByNumber(int _number, int _i);
virtual Json::Value eth_uncleByHash(std::string const& _hash, int _i); virtual Json::Value eth_uncleByHash(std::string const& _hash, int _i);

48
libweb3jsonrpc/abstractwebthreestubserver.h

@ -26,14 +26,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
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_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_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_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_getUncleCountByBlockHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockHashI);
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_getUncleCountByBlockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_codeAtI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getData", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getDataI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_transact", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_transactI); this->bindAndAddMethod(jsonrpc::Procedure("eth_sendTransaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_sendTransactionI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_callI); this->bindAndAddMethod(jsonrpc::Procedure("eth_call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_callI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_flush", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_flushI); this->bindAndAddMethod(jsonrpc::Procedure("eth_flush", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_flushI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_blockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_blockByHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockByHashI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_blockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_blockByNumberI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockByNumberI);
this->bindAndAddMethod(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(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(jsonrpc::Procedure("eth_transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByNumberI); this->bindAndAddMethod(jsonrpc::Procedure("eth_transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_transactionByNumberI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_uncleByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_uncleByHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_uncleByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_uncleByHashI);
@ -131,21 +131,21 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{ {
response = this->eth_getBlockTransactionCountByNumber(request[0u].asString()); response = this->eth_getBlockTransactionCountByNumber(request[0u].asString());
} }
inline virtual void eth_uncleCountByHashI(const Json::Value &request, Json::Value &response) inline virtual void eth_getUncleCountByBlockHashI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_uncleCountByHash(request[0u].asString()); response = this->eth_getUncleCountByBlockHash(request[0u].asString());
} }
inline virtual void eth_uncleCountByNumberI(const Json::Value &request, Json::Value &response) inline virtual void eth_getUncleCountByBlockNumberI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_uncleCountByNumber(request[0u].asInt()); response = this->eth_getUncleCountByBlockNumber(request[0u].asString());
} }
inline virtual void eth_codeAtI(const Json::Value &request, Json::Value &response) inline virtual void eth_getDataI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_codeAt(request[0u].asString()); response = this->eth_getData(request[0u].asString(), request[1u].asString());
} }
inline virtual void eth_transactI(const Json::Value &request, Json::Value &response) inline virtual void eth_sendTransactionI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_transact(request[0u]); response = this->eth_sendTransaction(request[0u]);
} }
inline virtual void eth_callI(const Json::Value &request, Json::Value &response) inline virtual void eth_callI(const Json::Value &request, Json::Value &response)
{ {
@ -156,13 +156,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
(void)request; (void)request;
response = this->eth_flush(); response = this->eth_flush();
} }
inline virtual void eth_blockByHashI(const Json::Value &request, Json::Value &response) inline virtual void eth_getBlockByHashI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_blockByHash(request[0u].asString()); response = this->eth_getBlockByHash(request[0u].asString());
} }
inline virtual void eth_blockByNumberI(const Json::Value &request, Json::Value &response) inline virtual void eth_getBlockByNumberI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_blockByNumber(request[0u].asInt()); response = this->eth_getBlockByNumber(request[0u].asString());
} }
inline virtual void eth_transactionByHashI(const Json::Value &request, Json::Value &response) inline virtual void eth_transactionByHashI(const Json::Value &request, Json::Value &response)
{ {
@ -309,14 +309,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) = 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_getBlockTransactionCountByHash(const std::string& param1) = 0;
virtual std::string eth_getBlockTransactionCountByNumber(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 std::string eth_getUncleCountByBlockHash(const std::string& param1) = 0;
virtual double eth_uncleCountByNumber(int param1) = 0; virtual std::string eth_getUncleCountByBlockNumber(const std::string& param1) = 0;
virtual std::string eth_codeAt(const std::string& param1) = 0; virtual std::string eth_getData(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_transact(const Json::Value& param1) = 0; virtual std::string eth_sendTransaction(const Json::Value& param1) = 0;
virtual std::string eth_call(const Json::Value& param1) = 0; virtual std::string eth_call(const Json::Value& param1) = 0;
virtual bool eth_flush() = 0; virtual bool eth_flush() = 0;
virtual Json::Value eth_blockByHash(const std::string& param1) = 0; virtual Json::Value eth_getBlockByHash(const std::string& param1) = 0;
virtual Json::Value eth_blockByNumber(int param1) = 0; virtual Json::Value eth_getBlockByNumber(const std::string& param1) = 0;
virtual Json::Value eth_transactionByHash(const std::string& param1, int param2) = 0; virtual Json::Value eth_transactionByHash(const std::string& param1, int param2) = 0;
virtual Json::Value eth_transactionByNumber(int param1, int param2) = 0; virtual Json::Value eth_transactionByNumber(int param1, int param2) = 0;
virtual Json::Value eth_uncleByHash(const std::string& param1, int param2) = 0; virtual Json::Value eth_uncleByHash(const std::string& param1, int param2) = 0;

16
libweb3jsonrpc/spec.json

@ -15,18 +15,16 @@
{ "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""}, { "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_uncleCountByHash", "params": [""], "order": [], "returns" : 0.0}, { "name": "eth_getData", "params": ["", ""], "order": [], "returns": ""},
{ "name": "eth_uncleCountByNumber", "params": [0], "order": [], "returns" : 0.0}, { "name": "eth_sendTransaction", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_codeAt", "params": [""], "order": [], "returns": ""},
{ "name": "eth_transact", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_call", "params": [{}], "order": [], "returns": ""}, { "name": "eth_call", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_flush", "params": [], "order": [], "returns" : true}, { "name": "eth_flush", "params": [], "order": [], "returns" : true},
{ "name": "eth_getBlockByHash", "params": [""],"order": [], "returns": {}},
{ "name": "eth_getBlockByNumber", "params": [""],"order": [], "returns": {}},
{ "name": "eth_blockByHash", "params": [""],"order": [], "returns": {}},
{ "name": "eth_blockByNumber", "params": [0],"order": [], "returns": {}},
{ "name": "eth_transactionByHash", "params": ["", 0], "order": [], "returns": {}}, { "name": "eth_transactionByHash", "params": ["", 0], "order": [], "returns": {}},
{ "name": "eth_transactionByNumber", "params": [0, 0], "order": [], "returns": {}}, { "name": "eth_transactionByNumber", "params": [0, 0], "order": [], "returns": {}},
{ "name": "eth_uncleByHash", "params": ["", 0], "order": [], "returns": {}}, { "name": "eth_uncleByHash", "params": ["", 0], "order": [], "returns": {}},

33
test/webthreestubclient.h

@ -157,41 +157,42 @@ 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());
} }
double eth_uncleCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) std::string eth_getUncleCountByBlockHash(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_uncleCountByHash",p); Json::Value result = this->CallMethod("eth_getUncleCountByBlockHash",p);
if (result.isDouble()) if (result.isString())
return result.asDouble(); return result.asString();
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
double eth_uncleCountByNumber(int param1) throw (jsonrpc::JsonRpcException) std::string eth_getUncleCountByBlockNumber(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_uncleCountByNumber",p); Json::Value result = this->CallMethod("eth_getUncleCountByBlockNumber",p);
if (result.isDouble()) if (result.isString())
return result.asDouble(); return result.asString();
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_codeAt(const std::string& param1) throw (jsonrpc::JsonRpcException) std::string eth_getData(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p.append(param1); p.append(param1);
Json::Value result = this->CallMethod("eth_codeAt",p); p.append(param2);
Json::Value result = this->CallMethod("eth_getData",p);
if (result.isString()) if (result.isString())
return result.asString(); return result.asString();
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_transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException) std::string eth_sendTransaction(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p.append(param1); p.append(param1);
Json::Value result = this->CallMethod("eth_transact",p); Json::Value result = this->CallMethod("eth_sendTransaction",p);
if (result.isString()) if (result.isString())
return result.asString(); return result.asString();
else else
@ -217,21 +218,21 @@ 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());
} }
Json::Value eth_blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) Json::Value eth_getBlockByHash(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_blockByHash",p); Json::Value result = this->CallMethod("eth_getBlockByHash",p);
if (result.isObject()) if (result.isObject())
return result; 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());
} }
Json::Value eth_blockByNumber(int param1) throw (jsonrpc::JsonRpcException) Json::Value eth_getBlockByNumber(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_blockByNumber",p); Json::Value result = this->CallMethod("eth_getBlockByNumber",p);
if (result.isObject()) if (result.isObject())
return result; return result;
else else

Loading…
Cancel
Save