Browse Source

jsonrpc renaming properties in request

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
fbd70ac939
  1. 16
      libethrpc/EthStubServer.cpp
  2. 8
      libethrpc/EthStubServer.h
  3. 24
      libethrpc/abstractethstubserver.h
  4. 9
      libethrpc/eth.js
  5. 8
      libethrpc/spec.json
  6. 18
      test/ethstubclient.h

16
libethrpc/EthStubServer.cpp

@ -105,9 +105,9 @@ dev::eth::Interface* EthStubServer::client() const
return &(*m_web3.ethereum());
}
std::string EthStubServer::balanceAt(const string &a, const int& block)
std::string EthStubServer::balanceAt(const string &address, const int& block)
{
return jsToDecimal(toJS(client()->balanceAt(jsToAddress(a), block)));
return jsToDecimal(toJS(client()->balanceAt(jsToAddress(address), block)));
}
//TODO BlockDetails?
@ -174,9 +174,9 @@ std::string EthStubServer::call(const Json::Value &json)
return ret;
}
std::string EthStubServer::codeAt(const string &a, const int& block)
std::string EthStubServer::codeAt(const string &address, const int& block)
{
return client() ? jsFromBinary(client()->codeAt(jsToAddress(a), block)) : "";
return client() ? jsFromBinary(client()->codeAt(jsToAddress(address), block)) : "";
}
std::string EthStubServer::coinbase()
@ -184,9 +184,9 @@ std::string EthStubServer::coinbase()
return client() ? toJS(client()->address()) : "";
}
double EthStubServer::countAt(const string &a, const int& block)
double EthStubServer::countAt(const string &address, const int& block)
{
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(a), block) : 0;
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(address), block) : 0;
}
int EthStubServer::defaultBlock()
@ -348,9 +348,9 @@ std::string EthStubServer::sha3(const string &s)
return toJS(dev::eth::sha3(jsToBytes(s)));
}
std::string EthStubServer::stateAt(const string &a, const int& block, const string &s)
std::string EthStubServer::stateAt(const string &address, const int& block, const string &storage)
{
return client() ? toJS(client()->stateAt(jsToAddress(a), jsToU256(s), block)) : "";
return client() ? toJS(client()->stateAt(jsToAddress(address), jsToU256(storage), block)) : "";
}
std::string EthStubServer::toAscii(const string &s)

8
libethrpc/EthStubServer.h

@ -36,12 +36,12 @@ class EthStubServer: public AbstractEthStubServer
public:
EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual std::string balanceAt(const std::string& a, const int& block);
virtual std::string balanceAt(const std::string& address, const int& block);
virtual Json::Value block(const std::string& numberOrHash);
virtual std::string call(const Json::Value& json);
virtual std::string codeAt(const std::string& a, const int& block);
virtual std::string codeAt(const std::string& address, const int& block);
virtual std::string coinbase();
virtual double countAt(const std::string& a, const int& block);
virtual double countAt(const std::string& address, const int& block);
virtual int defaultBlock();
virtual std::string fromAscii(const int& padding, const std::string& s);
virtual double fromFixed(const std::string& s);
@ -59,7 +59,7 @@ public:
virtual bool setListening(const bool& listening);
virtual bool setMining(const bool& mining);
virtual std::string sha3(const std::string& s);
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s);
virtual std::string stateAt(const std::string& address, const int& block, const std::string& storage);
virtual std::string toAscii(const std::string& s);
virtual std::string toDecimal(const std::string& s);
virtual std::string toFixed(const double& s);

24
libethrpc/abstractethstubserver.h

@ -13,12 +13,12 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
AbstractEthStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractEthStubServer>(conn)
{
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::balanceAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::balanceAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI);
this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::callI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "padding",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromFixedI);
@ -36,7 +36,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "listening",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "mining",jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"storage",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toDecimalI);
this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_REAL, NULL), &AbstractEthStubServer::toFixedI);
@ -49,7 +49,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void balanceAtI(const Json::Value& request, Json::Value& response)
{
response = this->balanceAt(request["a"].asString(), request["block"].asInt());
response = this->balanceAt(request["address"].asString(), request["block"].asInt());
}
inline virtual void blockI(const Json::Value& request, Json::Value& response)
@ -64,7 +64,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void codeAtI(const Json::Value& request, Json::Value& response)
{
response = this->codeAt(request["a"].asString(), request["block"].asInt());
response = this->codeAt(request["address"].asString(), request["block"].asInt());
}
inline virtual void coinbaseI(const Json::Value& request, Json::Value& response)
@ -74,7 +74,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void countAtI(const Json::Value& request, Json::Value& response)
{
response = this->countAt(request["a"].asString(), request["block"].asInt());
response = this->countAt(request["address"].asString(), request["block"].asInt());
}
inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response)
@ -164,7 +164,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void stateAtI(const Json::Value& request, Json::Value& response)
{
response = this->stateAt(request["a"].asString(), request["block"].asInt(), request["s"].asString());
response = this->stateAt(request["address"].asString(), request["block"].asInt(), request["storage"].asString());
}
inline virtual void toAsciiI(const Json::Value& request, Json::Value& response)
@ -203,12 +203,12 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
}
virtual std::string balanceAt(const std::string& a, const int& block) = 0;
virtual std::string balanceAt(const std::string& address, const int& block) = 0;
virtual Json::Value block(const std::string& numberOrHash) = 0;
virtual std::string call(const Json::Value& json) = 0;
virtual std::string codeAt(const std::string& a, const int& block) = 0;
virtual std::string codeAt(const std::string& address, const int& block) = 0;
virtual std::string coinbase() = 0;
virtual double countAt(const std::string& a, const int& block) = 0;
virtual double countAt(const std::string& address, const int& block) = 0;
virtual int defaultBlock() = 0;
virtual std::string fromAscii(const int& padding, const std::string& s) = 0;
virtual double fromFixed(const std::string& s) = 0;
@ -226,7 +226,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual bool setListening(const bool& listening) = 0;
virtual bool setMining(const bool& mining) = 0;
virtual std::string sha3(const std::string& s) = 0;
virtual std::string stateAt(const std::string& a, const int& block, const std::string& s) = 0;
virtual std::string stateAt(const std::string& address, const int& block, const std::string& storage) = 0;
virtual std::string toAscii(const std::string& s) = 0;
virtual std::string toDecimal(const std::string& s) = 0;
virtual std::string toFixed(const double& s) = 0;

9
libethrpc/eth.js

@ -30,11 +30,10 @@ var spec = [
{ "method": "defaultBlock", "params": null, "order": [], "returns" : 0},
{ "method": "number", "params": null, "order": [], "returns" : 0},
{ "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "s": "", "block": 0}, "order": ["a", "s", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : 0.0},
{ "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},
{ "method": "balanceAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "address": "", "storage": "", "block": 0}, "order": ["address", "storage", "block"], "returns": ""},
{ "method": "countAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns" : 0.0},
{ "method": "codeAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns": ""},
{ "method": "transact", "params": { "json": {}}, "order": ["json"], "returns": ""},
{ "method": "call", "params": { "json": {}}, "order": ["json"], "returns": ""},

8
libethrpc/spec.json

@ -13,10 +13,10 @@
{ "method": "number", "params": null, "order": [], "returns" : 0},
{ "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "s": "", "block": 0}, "order": ["a", "s", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : 0.0},
{ "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},
{ "method": "balanceAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "address": "", "storage": "", "block": 0}, "order": ["address", "storage", "block"], "returns": ""},
{ "method": "countAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns" : 0.0},
{ "method": "codeAt", "params": { "address": "", "block": 0}, "order": ["address", "block"], "returns": ""},
{ "method": "transact", "params": { "json": {}}, "order": ["json"], "returns": ""},
{ "method": "call", "params": { "json": {}}, "order": ["json"], "returns": ""},

18
test/ethstubclient.h

@ -19,10 +19,10 @@ class EthStubClient
delete this->client;
}
std::string balanceAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
std::string balanceAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["address"] = address;
p["block"] = block;
Json::Value result = this->client->CallMethod("balanceAt",p);
@ -59,10 +59,10 @@ p["block"] = block;
}
std::string codeAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
std::string codeAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["address"] = address;
p["block"] = block;
Json::Value result = this->client->CallMethod("codeAt",p);
@ -85,10 +85,10 @@ p["block"] = block;
}
double countAt(const std::string& a, const int& block) throw (jsonrpc::JsonRpcException)
double countAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["address"] = address;
p["block"] = block;
Json::Value result = this->client->CallMethod("countAt",p);
@ -313,12 +313,12 @@ p["s"] = s;
}
std::string stateAt(const std::string& a, const int& block, const std::string& s) throw (jsonrpc::JsonRpcException)
std::string stateAt(const std::string& address, const int& block, const std::string& storage) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["a"] = a;
p["address"] = address;
p["block"] = block;
p["s"] = s;
p["storage"] = storage;
Json::Value result = this->client->CallMethod("stateAt",p);
if (result.isString())

Loading…
Cancel
Save