Browse Source

block, transaction, uncle by hash and number separately

cl-refactor
Marek Kotewicz 11 years ago
parent
commit
d8e132c754
  1. 48
      libethrpc/WebThreeStubServer.cpp
  2. 9
      libethrpc/WebThreeStubServer.h
  3. 45
      libethrpc/abstractwebthreestubserver.h
  4. 9
      libethrpc/spec.json
  5. 56
      test/webthreestubclient.h

48
libethrpc/WebThreeStubServer.cpp

@ -129,18 +129,20 @@ std::string WebThreeStubServer::balanceAt(string const& _address)
return toJS(client()->balanceAt(jsToAddress(_address), block));
}
Json::Value WebThreeStubServer::block(int const& _block, std::string const& _hash)
Json::Value WebThreeStubServer::blockByHash(std::string const& _hash)
{
if (!client())
return "";
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->blockInfo(jsToFixed<32>(_hash)));
}
Json::Value WebThreeStubServer::blockByNumber(int const& _number)
{
if (!client())
return "";
return toJson(client()->blockInfo(blockHash));
return toJson(client()->blockInfo(client()->hashFromNumber(_number)));
}
static TransactionJS toTransaction(Json::Value const& _json)
@ -378,32 +380,36 @@ Json::Value WebThreeStubServer::transact(Json::Value const& _json)
return ret;
}
Json::Value WebThreeStubServer::transaction(int const& _block, std::string const& _hash, int const& _i)
Json::Value WebThreeStubServer::transactionByHash(std::string const& _hash, int const& _i)
{
if (!client())
return "";
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->transaction(jsToFixed<32>(_hash), _i));
}
Json::Value WebThreeStubServer::transactionByNumber(int const& _number, int const& _i)
{
if (!client())
return "";
return toJson(client()->transaction(blockHash, _i));
return toJson(client()->transaction(client()->hashFromNumber(_number), _i));
}
Json::Value WebThreeStubServer::uncle(int const& _block, std::string const& _hash, int const& _i)
Json::Value WebThreeStubServer::uncleByHash(std::string const& _hash, int const& _i)
{
if (!client())
return "";
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->uncle(jsToFixed<32>(_hash), _i));
}
Json::Value WebThreeStubServer::uncleByNumber(int const& _number, int const& _i)
{
if (!client())
return "";
return toJson(client()->uncle(blockHash, _i));
return toJson(client()->uncle(client()->hashFromNumber(_number), _i));
}
int WebThreeStubServer::watch(string const& _json)

9
libethrpc/WebThreeStubServer.h

@ -40,7 +40,8 @@ public:
virtual Json::Value accounts();
virtual std::string balanceAt(std::string const& _address);
virtual Json::Value block(int const& _block, std::string const& _hash);
virtual Json::Value blockByHash(std::string const& _hash);
virtual Json::Value blockByNumber(int const& _number);
virtual std::string call(Json::Value const& _json);
virtual bool check(int const& _id);
virtual std::string codeAt(std::string const& _address);
@ -60,8 +61,10 @@ public:
virtual bool setMining(bool const& _mining);
virtual std::string stateAt(std::string const& _address, std::string const& _storage);
virtual Json::Value transact(Json::Value const& _json);
virtual Json::Value transaction(int const& _block, std::string const& _hash, int const& _i);
virtual Json::Value uncle(int const& _block, std::string const& _hash, int const& _i);
virtual Json::Value transactionByHash(std::string const& _hash, int const& _i);
virtual Json::Value transactionByNumber(int const& _number, int const& _i);
virtual Json::Value uncleByHash(std::string const& _hash, int const& _i);
virtual Json::Value uncleByNumber(int const& _number, int const& _i);
virtual int watch(std::string const& _json);
void setAccounts(std::vector<dev::KeyPair> const& _accounts);

45
libethrpc/abstractwebthreestubserver.h

@ -15,7 +15,8 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{
this->bindAndAddMethod(new jsonrpc::Procedure("accounts", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::accountsI);
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::balanceAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::blockI);
this->bindAndAddMethod(new jsonrpc::Procedure("blockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::blockByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("blockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::blockByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::callI);
this->bindAndAddMethod(new jsonrpc::Procedure("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::checkI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::codeAtI);
@ -35,8 +36,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::transactionI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleI);
this->bindAndAddMethod(new jsonrpc::Procedure("transactionByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::transactionByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::transactionByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncleByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncleByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "params",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::watchI);
}
@ -51,9 +54,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->balanceAt(request[0u].asString());
}
inline virtual void blockI(const Json::Value& request, Json::Value& response)
inline virtual void blockByHashI(const Json::Value& request, Json::Value& response)
{
response = this->block(request[0u].asInt(), request[1u].asString());
response = this->blockByHash(request[0u].asString());
}
inline virtual void blockByNumberI(const Json::Value& request, Json::Value& response)
{
response = this->blockByNumber(request[0u].asInt());
}
inline virtual void callI(const Json::Value& request, Json::Value& response)
@ -151,14 +159,24 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->transact(request[0u]);
}
inline virtual void transactionI(const Json::Value& request, Json::Value& response)
inline virtual void transactionByHashI(const Json::Value& request, Json::Value& response)
{
response = this->transactionByHash(request[0u].asString(), request[1u].asInt());
}
inline virtual void transactionByNumberI(const Json::Value& request, Json::Value& response)
{
response = this->transactionByNumber(request[0u].asInt(), request[1u].asInt());
}
inline virtual void uncleByHashI(const Json::Value& request, Json::Value& response)
{
response = this->transaction(request[0u].asInt(), request[1u].asString(), request[2u].asInt());
response = this->uncleByHash(request[0u].asString(), request[1u].asInt());
}
inline virtual void uncleI(const Json::Value& request, Json::Value& response)
inline virtual void uncleByNumberI(const Json::Value& request, Json::Value& response)
{
response = this->uncle(request[0u].asInt(), request[1u].asString(), request[2u].asInt());
response = this->uncleByNumber(request[0u].asInt(), request[1u].asInt());
}
inline virtual void watchI(const Json::Value& request, Json::Value& response)
@ -169,7 +187,8 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value accounts() = 0;
virtual std::string balanceAt(const std::string& param1) = 0;
virtual Json::Value block(const int& param1, const std::string& param2) = 0;
virtual Json::Value blockByHash(const std::string& param1) = 0;
virtual Json::Value blockByNumber(const int& param1) = 0;
virtual std::string call(const Json::Value& param1) = 0;
virtual bool check(const int& id) = 0;
virtual std::string codeAt(const std::string& param1) = 0;
@ -189,8 +208,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual bool setMining(const bool& param1) = 0;
virtual std::string stateAt(const std::string& param1, const std::string& param2) = 0;
virtual Json::Value transact(const Json::Value& param1) = 0;
virtual Json::Value transaction(const int& param1, const std::string& param2, const int& param3) = 0;
virtual Json::Value uncle(const int& param1, const std::string& param2, const int& param3) = 0;
virtual Json::Value transactionByHash(const std::string& param1, const int& param2) = 0;
virtual Json::Value transactionByNumber(const int& param1, const int& param2) = 0;
virtual Json::Value uncleByHash(const std::string& param1, const int& param2) = 0;
virtual Json::Value uncleByNumber(const int& param1, const int& param2) = 0;
virtual int watch(const std::string& params) = 0;
};

9
libethrpc/spec.json

@ -19,9 +19,12 @@
{ "method": "transact", "params": [{}], "order": [], "returns": []},
{ "method": "call", "params": [{}], "order": [], "returns": ""},
{ "method": "block", "params": [0, ""],"order": [], "returns": {}},
{ "method": "transaction", "params": [0, "", 0], "order": [], "returns": {}},
{ "method": "uncle", "params": [0, "", 0], "order": [], "returns": {}},
{ "method": "blockByHash", "params": [""],"order": [], "returns": {}},
{ "method": "blockByNumber", "params": [0],"order": [], "returns": {}},
{ "method": "transactionByHash", "params": ["", 0], "order": [], "returns": {}},
{ "method": "transactionByNumber", "params": [0, 0], "order": [], "returns": {}},
{ "method": "uncleByHash", "params": ["", 0], "order": [], "returns": {}},
{ "method": "uncleByNumber", "params": [0, 0], "order": [], "returns": {}},
{ "method": "compile", "params": [""], "order": [], "returns": ""},

56
test/webthreestubclient.h

@ -44,13 +44,25 @@ class WebThreeStubClient
}
Json::Value block(const int& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
Json::Value blockByHash(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("blockByHash",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value blockByNumber(const int& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
Json::Value result = this->client->CallMethod("block",p);
Json::Value result = this->client->CallMethod("blockByNumber",p);
if (result.isObject())
return result;
else
@ -299,14 +311,41 @@ p.append(param2);
}
Json::Value transaction(const int& param1, const std::string& param2, const int& param3) throw (jsonrpc::JsonRpcException)
Json::Value transactionByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
Json::Value result = this->client->CallMethod("transactionByHash",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value transactionByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
Json::Value result = this->client->CallMethod("transactionByNumber",p);
if (result.isObject())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value uncleByHash(const std::string& param1, const int& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->client->CallMethod("transaction",p);
Json::Value result = this->client->CallMethod("uncleByHash",p);
if (result.isObject())
return result;
else
@ -314,14 +353,13 @@ p.append(param3);
}
Json::Value uncle(const int& param1, const std::string& param2, const int& param3) throw (jsonrpc::JsonRpcException)
Json::Value uncleByNumber(const int& param1, const int& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->client->CallMethod("uncle",p);
Json::Value result = this->client->CallMethod("uncleByNumber",p);
if (result.isObject())
return result;
else

Loading…
Cancel
Save