Browse Source

jsonrpc offset method

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
1c9ca3d720
  1. 5
      libethrpc/EthStubServer.cpp
  2. 1
      libethrpc/EthStubServer.h
  3. 7
      libethrpc/abstractethstubserver.h
  4. 3
      libethrpc/eth.js
  5. 3
      libethrpc/spec.json
  6. 14
      test/ethstubclient.h

5
libethrpc/EthStubServer.cpp

@ -313,6 +313,11 @@ int EthStubServer::number()
return client() ? client()->number() + 1 : 0; return client() ? client()->number() + 1 : 0;
} }
std::string EthStubServer::offset(const int& o, const std::string& s)
{
return toJS(jsToU256(s) + o);
}
int EthStubServer::peerCount() int EthStubServer::peerCount()
{ {
return m_web3.peerCount(); return m_web3.peerCount();

1
libethrpc/EthStubServer.h

@ -55,6 +55,7 @@ public:
virtual std::string lll(const std::string& s); virtual std::string lll(const std::string& s);
virtual Json::Value messages(const Json::Value& json); virtual Json::Value messages(const Json::Value& json);
virtual int number(); virtual int number();
virtual std::string offset(const int& o, const std::string& s);
virtual int peerCount(); virtual int peerCount();
virtual std::string secretToAddress(const std::string& s); virtual std::string secretToAddress(const std::string& s);
virtual bool setCoinbase(const std::string& address); virtual bool setCoinbase(const std::string& address);

7
libethrpc/abstractethstubserver.h

@ -32,6 +32,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "params",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::messagesI); this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "params",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::messagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::miningI); this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::numberI); this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("offset", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "o",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::offsetI);
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI); this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI); this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI);
this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "address",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setCoinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "address",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setCoinbaseI);
@ -144,6 +145,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
response = this->number(); response = this->number();
} }
inline virtual void offsetI(const Json::Value& request, Json::Value& response)
{
response = this->offset(request["o"].asInt(), request["s"].asString());
}
inline virtual void peerCountI(const Json::Value& request, Json::Value& response) inline virtual void peerCountI(const Json::Value& request, Json::Value& response)
{ {
response = this->peerCount(); response = this->peerCount();
@ -234,6 +240,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual Json::Value messages(const Json::Value& params) = 0; virtual Json::Value messages(const Json::Value& params) = 0;
virtual bool mining() = 0; virtual bool mining() = 0;
virtual int number() = 0; virtual int number() = 0;
virtual std::string offset(const int& o, const std::string& s) = 0;
virtual int peerCount() = 0; virtual int peerCount() = 0;
virtual std::string secretToAddress(const std::string& s) = 0; virtual std::string secretToAddress(const std::string& s) = 0;
virtual bool setCoinbase(const std::string& address) = 0; virtual bool setCoinbase(const std::string& address) = 0;

3
libethrpc/eth.js

@ -54,7 +54,8 @@ var spec = [
{ "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""}, { "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""},
{ "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "toFixed", "params": {"s": 0.0}, "order": ["s"], "returns" : ""}, { "method": "toFixed", "params": {"s": 0.0}, "order": ["s"], "returns" : ""},
{ "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0} { "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0},
{ "method": "offset", "params": {"s": "", "o": 0}, "order": ["s", "o"], "returns" : ""}
]; ];
window.eth = (function ethScope() { window.eth = (function ethScope() {

3
libethrpc/spec.json

@ -36,7 +36,8 @@
{ "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""}, { "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""},
{ "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "toFixed", "params": {"s": 0.0}, "order": ["s"], "returns" : ""}, { "method": "toFixed", "params": {"s": 0.0}, "order": ["s"], "returns" : ""},
{ "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0} { "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0},
{ "method": "offset", "params": {"s": "", "o": 0}, "order": ["s", "o"], "returns" : ""}
] ]

14
test/ethstubclient.h

@ -262,6 +262,20 @@ p["s"] = s;
} }
std::string offset(const int& o, const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["o"] = o;
p["s"] = s;
Json::Value result = this->client->CallMethod("offset",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int peerCount() throw (jsonrpc::JsonRpcException) int peerCount() throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;

Loading…
Cancel
Save