Browse Source

changes from Generic JSON-RPC

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
692426f69a
  1. 109
      libethrpc/WebThreeStubServer.cpp
  2. 33
      libethrpc/WebThreeStubServer.h
  3. 158
      libethrpc/abstractwebthreestubserver.h
  4. 54
      libethrpc/spec.json
  5. 67
      test/jsonrpc.cpp
  6. 197
      test/webthreestubclient.h

109
libethrpc/WebThreeStubServer.cpp

@ -123,28 +123,24 @@ Json::Value WebThreeStubServer::accounts()
return ret;
}
std::string WebThreeStubServer::balanceAt(string const& _address, int const& _block)
std::string WebThreeStubServer::balanceAt(string const& _address)
{
return toJS(client()->balanceAt(jsToAddress(_address), _block));
int block = 0; // temporarily
return toJS(client()->balanceAt(jsToAddress(_address), block));
}
dev::FixedHash<32> WebThreeStubServer::numberOrHash(Json::Value const& _json) const
{
dev::FixedHash<32> hash;
if (!_json["hash"].empty())
hash = jsToFixed<32>(_json["hash"].asString());
else if (!_json["number"].empty())
hash = client()->hashFromNumber((unsigned)_json["number"].asInt());
return hash;
}
Json::Value WebThreeStubServer::block(Json::Value const& _params)
Json::Value WebThreeStubServer::block(int const& _block, std::string const& _hash)
{
if (!client())
return "";
auto hash = numberOrHash(_params);
return toJson(client()->blockInfo(hash));
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->blockInfo(blockHash));
}
static TransactionJS toTransaction(Json::Value const& _json)
@ -209,9 +205,11 @@ std::string WebThreeStubServer::call(Json::Value const& _json)
return ret;
}
std::string WebThreeStubServer::codeAt(string const& _address, int const& _block)
std::string WebThreeStubServer::codeAt(string const& _address)
{
return client() ? jsFromBinary(client()->codeAt(jsToAddress(_address), _block)) : "";
// temp
int block = 0;
return client() ? jsFromBinary(client()->codeAt(jsToAddress(_address), block)) : "";
}
std::string WebThreeStubServer::coinbase()
@ -219,9 +217,10 @@ std::string WebThreeStubServer::coinbase()
return client() ? toJS(client()->address()) : "";
}
double WebThreeStubServer::countAt(string const& _address, int const& _block)
double WebThreeStubServer::countAt(string const& _address)
{
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(_address), _block) : 0;
int block = 0;
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(_address), block) : 0;
}
int WebThreeStubServer::defaultBlock()
@ -229,16 +228,6 @@ int WebThreeStubServer::defaultBlock()
return client() ? client()->getDefault() : 0;
}
std::string WebThreeStubServer::fromAscii(int const& _padding, std::string const& _s)
{
return jsFromBinary(_s, _padding);
}
double WebThreeStubServer::fromFixed(string const& _s)
{
return jsFromFixed(_s);
}
std::string WebThreeStubServer::gasPrice()
{
return toJS(10 * dev::eth::szabo);
@ -254,7 +243,7 @@ bool WebThreeStubServer::mining()
return client() ? client()->isMining() : false;
}
std::string WebThreeStubServer::lll(string const& _s)
std::string WebThreeStubServer::compile(string const& _s)
{
return toJS(dev::eth::compileLLL(_s));
}
@ -320,21 +309,11 @@ int WebThreeStubServer::number()
return client() ? client()->number() + 1 : 0;
}
std::string WebThreeStubServer::offset(int const& _o, std::string const& _s)
{
return toJS(jsToU256(_s) + _o);
}
int WebThreeStubServer::peerCount()
{
return m_web3.peerCount();
}
std::string WebThreeStubServer::secretToAddress(string const& _s)
{
return toJS(KeyPair(jsToSecret(_s)).address());
}
bool WebThreeStubServer::setCoinbase(std::string const& _address)
{
client()->setAddress(jsToAddress(_address));
@ -362,32 +341,14 @@ bool WebThreeStubServer::setMining(bool const& _mining)
return true;
}
std::string WebThreeStubServer::sha3(string const& _s)
std::string WebThreeStubServer::stateAt(string const& _address, string const& _storage)
{
return toJS(dev::sha3(jsToBytes(_s)));
// temp
int block = 0;
return client() ? toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), block)) : "";
}
std::string WebThreeStubServer::stateAt(string const& _address, int const& _block, string const& _storage)
{
return client() ? toJS(client()->stateAt(jsToAddress(_address), jsToU256(_storage), _block)) : "";
}
std::string WebThreeStubServer::toAscii(string const& _s)
{
return jsToBinary(_s);
}
std::string WebThreeStubServer::toDecimal(string const& _s)
{
return jsToDecimal(_s);
}
std::string WebThreeStubServer::toFixed(double const& _s)
{
return jsToFixed(_s);
}
std::string WebThreeStubServer::transact(Json::Value const& _json)
Json::Value WebThreeStubServer::transact(Json::Value const& _json)
{
std::string ret;
if (!client())
@ -417,22 +378,32 @@ std::string WebThreeStubServer::transact(Json::Value const& _json)
return ret;
}
Json::Value WebThreeStubServer::transaction(int const& _i, Json::Value const& _params)
Json::Value WebThreeStubServer::transaction(int const& _block, std::string const& _hash, int const& _i)
{
if (!client())
return "";
auto hash = numberOrHash(_params);
return toJson(client()->transaction(hash, _i));
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->transaction(blockHash, _i));
}
Json::Value WebThreeStubServer::uncle(int const& _i, Json::Value const& _params)
Json::Value WebThreeStubServer::uncle(int const& _block, std::string const& _hash, int const& _i)
{
if (!client())
return "";
auto hash = numberOrHash(_params);
return toJson(client()->uncle(hash, _i));
dev::FixedHash<32> blockHash;
if (_hash.compare("") != 0)
blockHash = jsToFixed<32>(_hash);
else
blockHash = client()->hashFromNumber(_block);
return toJson(client()->uncle(blockHash, _i));
}
int WebThreeStubServer::watch(string const& _json)

33
libethrpc/WebThreeStubServer.h

@ -39,43 +39,34 @@ public:
WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> _accounts);
virtual Json::Value accounts();
virtual std::string balanceAt(std::string const& _address, int const& _block);
virtual Json::Value block(Json::Value const& _params);
virtual std::string balanceAt(std::string const& _address);
virtual Json::Value block(int const& _block, std::string const& _hash);
virtual std::string call(Json::Value const& _json);
virtual std::string codeAt(std::string const& _address, int const& _block);
virtual bool check(int const& _id);
virtual std::string codeAt(std::string const& _address);
virtual std::string coinbase();
virtual double countAt(std::string const& _address, int const& _block);
virtual std::string compile(std::string const& _s);
virtual double countAt(std::string const& _address);
virtual int defaultBlock();
virtual std::string fromAscii(int const& _padding, std::string const& _s);
virtual double fromFixed(std::string const& _s);
virtual std::string gasPrice();
virtual bool killWatch(int const& _id);
virtual bool listening();
virtual bool mining();
virtual std::string lll(std::string const& _s);
virtual Json::Value messages(Json::Value const& _json);
virtual bool mining();
virtual int number();
virtual std::string offset(int const& _o, std::string const& _s);
virtual int peerCount();
virtual std::string secretToAddress(std::string const& _s);
virtual bool setCoinbase(std::string const& _address);
virtual bool setListening(bool const& _listening);
virtual bool setMining(bool const& _mining);
virtual std::string sha3(std::string const& _s);
virtual std::string stateAt(std::string const& _address, int const& _block, std::string const& _storage);
virtual std::string toAscii(std::string const& _s);
virtual std::string toDecimal(std::string const& _s);
virtual std::string toFixed(double const& _s);
virtual std::string transact(Json::Value const& _json);
virtual Json::Value transaction(int const& _i, Json::Value const& _params);
virtual Json::Value uncle(int const& _i, Json::Value const& _params);
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 int watch(std::string const& _json);
virtual bool check(int const& _id);
virtual bool killWatch(int const& _id);
void setAccounts(std::vector<dev::KeyPair> const& _accounts);
private:
dev::eth::Interface* client() const;
dev::WebThreeDirect& m_web3;
std::map<dev::Address, dev::KeyPair> m_accounts;
dev::FixedHash<32> numberOrHash(Json::Value const& _json) const;
};

158
libethrpc/abstractwebthreestubserver.h

@ -13,38 +13,30 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
AbstractWebThreeStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractWebThreeStubServer>(conn)
{
this->bindAndAddMethod(new jsonrpc::Procedure("accounts", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::accountsI);
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::balanceAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "params",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::blockI);
this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::callI);
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("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_NAME, jsonrpc::JSON_STRING, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "address",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "padding",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::fromAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::fromFixedI);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("compile", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::compileI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("killWatch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::killWatchI);
this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::lllI);
this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "params",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::messagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("offset", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "o",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::offsetI);
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::secretToAddressI);
this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "address",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::setCoinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "listening",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "mining",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::sha3I);
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), &AbstractWebThreeStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::toAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::toDecimalI);
this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_REAL, NULL), &AbstractWebThreeStubServer::toFixedI);
this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "i",jsonrpc::JSON_INTEGER,"params",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::transactionI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "i",jsonrpc::JSON_INTEGER,"params",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::uncleI);
this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::setCoinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::setListeningI);
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("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "params",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::watchI);
}
@ -56,17 +48,17 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
inline virtual void balanceAtI(const Json::Value& request, Json::Value& response)
{
response = this->balanceAt(request["address"].asString(), request["block"].asInt());
response = this->balanceAt(request[0u].asString());
}
inline virtual void blockI(const Json::Value& request, Json::Value& response)
{
response = this->block(request["params"]);
response = this->block(request[0u].asInt(), request[1u].asString());
}
inline virtual void callI(const Json::Value& request, Json::Value& response)
{
response = this->call(request["json"]);
response = this->call(request[0u]);
}
inline virtual void checkI(const Json::Value& request, Json::Value& response)
@ -76,7 +68,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
inline virtual void codeAtI(const Json::Value& request, Json::Value& response)
{
response = this->codeAt(request["address"].asString(), request["block"].asInt());
response = this->codeAt(request[0u].asString());
}
inline virtual void coinbaseI(const Json::Value& request, Json::Value& response)
@ -84,24 +76,19 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->coinbase();
}
inline virtual void countAtI(const Json::Value& request, Json::Value& response)
{
response = this->countAt(request["address"].asString(), request["block"].asInt());
}
inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response)
inline virtual void compileI(const Json::Value& request, Json::Value& response)
{
response = this->defaultBlock();
response = this->compile(request[0u].asString());
}
inline virtual void fromAsciiI(const Json::Value& request, Json::Value& response)
inline virtual void countAtI(const Json::Value& request, Json::Value& response)
{
response = this->fromAscii(request["padding"].asInt(), request["s"].asString());
response = this->countAt(request[0u].asString());
}
inline virtual void fromFixedI(const Json::Value& request, Json::Value& response)
inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response)
{
response = this->fromFixed(request["s"].asString());
response = this->defaultBlock();
}
inline virtual void gasPriceI(const Json::Value& request, Json::Value& response)
@ -119,11 +106,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->listening();
}
inline virtual void lllI(const Json::Value& request, Json::Value& response)
{
response = this->lll(request["s"].asString());
}
inline virtual void messagesI(const Json::Value& request, Json::Value& response)
{
response = this->messages(request["params"]);
@ -139,74 +121,44 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
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)
{
response = this->peerCount();
}
inline virtual void secretToAddressI(const Json::Value& request, Json::Value& response)
{
response = this->secretToAddress(request["s"].asString());
}
inline virtual void setCoinbaseI(const Json::Value& request, Json::Value& response)
{
response = this->setCoinbase(request["address"].asString());
response = this->setCoinbase(request[0u].asString());
}
inline virtual void setListeningI(const Json::Value& request, Json::Value& response)
{
response = this->setListening(request["listening"].asBool());
response = this->setListening(request[0u].asBool());
}
inline virtual void setMiningI(const Json::Value& request, Json::Value& response)
{
response = this->setMining(request["mining"].asBool());
}
inline virtual void sha3I(const Json::Value& request, Json::Value& response)
{
response = this->sha3(request["s"].asString());
response = this->setMining(request[0u].asBool());
}
inline virtual void stateAtI(const Json::Value& request, Json::Value& response)
{
response = this->stateAt(request["address"].asString(), request["block"].asInt(), request["storage"].asString());
}
inline virtual void toAsciiI(const Json::Value& request, Json::Value& response)
{
response = this->toAscii(request["s"].asString());
}
inline virtual void toDecimalI(const Json::Value& request, Json::Value& response)
{
response = this->toDecimal(request["s"].asString());
}
inline virtual void toFixedI(const Json::Value& request, Json::Value& response)
{
response = this->toFixed(request["s"].asDouble());
response = this->stateAt(request[0u].asString(), request[1u].asString());
}
inline virtual void transactI(const Json::Value& request, Json::Value& response)
{
response = this->transact(request["json"]);
response = this->transact(request[0u]);
}
inline virtual void transactionI(const Json::Value& request, Json::Value& response)
{
response = this->transaction(request["i"].asInt(), request["params"]);
response = this->transaction(request[0u].asInt(), request[1u].asString(), request[2u].asInt());
}
inline virtual void uncleI(const Json::Value& request, Json::Value& response)
{
response = this->uncle(request["i"].asInt(), request["params"]);
response = this->uncle(request[0u].asInt(), request[1u].asString(), request[2u].asInt());
}
inline virtual void watchI(const Json::Value& request, Json::Value& response)
@ -216,37 +168,29 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value accounts() = 0;
virtual std::string balanceAt(const std::string& address, const int& block) = 0;
virtual Json::Value block(const Json::Value& params) = 0;
virtual std::string call(const Json::Value& json) = 0;
virtual std::string balanceAt(const std::string& param1) = 0;
virtual Json::Value block(const int& param1, const std::string& param2) = 0;
virtual std::string call(const Json::Value& param1) = 0;
virtual bool check(const int& id) = 0;
virtual std::string codeAt(const std::string& address, const int& block) = 0;
virtual std::string codeAt(const std::string& param1) = 0;
virtual std::string coinbase() = 0;
virtual double countAt(const std::string& address, const int& block) = 0;
virtual std::string compile(const std::string& param1) = 0;
virtual double countAt(const std::string& param1) = 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;
virtual std::string gasPrice() = 0;
virtual bool killWatch(const int& id) = 0;
virtual bool listening() = 0;
virtual std::string lll(const std::string& s) = 0;
virtual Json::Value messages(const Json::Value& params) = 0;
virtual bool mining() = 0;
virtual int number() = 0;
virtual std::string offset(const int& o, const std::string& s) = 0;
virtual int peerCount() = 0;
virtual std::string secretToAddress(const std::string& s) = 0;
virtual bool setCoinbase(const std::string& address) = 0;
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& 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;
virtual std::string transact(const Json::Value& json) = 0;
virtual Json::Value transaction(const int& i, const Json::Value& params) = 0;
virtual Json::Value uncle(const int& i, const Json::Value& params) = 0;
virtual bool setCoinbase(const std::string& param1) = 0;
virtual bool setListening(const bool& param1) = 0;
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 int watch(const std::string& params) = 0;
};

54
libethrpc/spec.json

@ -1,42 +1,34 @@
[
{ "method": "coinbase", "params": null, "order": [], "returns" : "" },
{ "method": "setCoinbase", "params": { "address": "" }, "order": ["address"], "returns" : true },
{ "method": "listening", "params": null, "order": [], "returns" : false },
{ "method": "setListening", "params": { "listening": false }, "order" : ["listening"], "returns" : true },
{ "method": "mining", "params": null, "order": [], "returns" : false },
{ "method": "setMining", "params": { "mining": false }, "order" : ["mining"], "returns" : true },
{ "method": "gasPrice", "params": null, "order": [], "returns" : "" },
{ "method": "accounts", "params": null, "order": [], "returns" : [] },
{ "method": "peerCount", "params": null, "order": [], "returns" : 0 },
{ "method": "defaultBlock", "params": null, "order": [], "returns" : 0},
{ "method": "number", "params": null, "order": [], "returns" : 0},
{ "method": "coinbase", "params": [], "order": [], "returns" : "" },
{ "method": "setCoinbase", "params": [""], "order": [], "returns" : true },
{ "method": "listening", "params": [], "order": [], "returns" : false },
{ "method": "setListening", "params": [false], "order" : [], "returns" : true },
{ "method": "mining", "params": [], "order": [], "returns" : false },
{ "method": "setMining", "params": [false], "order" : [], "returns" : true },
{ "method": "gasPrice", "params": [], "order": [], "returns" : "" },
{ "method": "accounts", "params": [], "order": [], "returns" : [] },
{ "method": "peerCount", "params": [], "order": [], "returns" : 0 },
{ "method": "defaultBlock", "params": [], "order": [], "returns" : 0},
{ "method": "number", "params": [], "order": [], "returns" : 0},
{ "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": "balanceAt", "params": [""], "order": [], "returns" : ""},
{ "method": "stateAt", "params": ["", ""], "order": [], "returns": ""},
{ "method": "countAt", "params": [""], "order": [], "returns" : 0.0},
{ "method": "codeAt", "params": [""], "order": [], "returns": ""},
{ "method": "transact", "params": { "json": {}}, "order": ["json"], "returns": ""},
{ "method": "call", "params": { "json": {}}, "order": ["json"], "returns": ""},
{ "method": "transact", "params": [{}], "order": [], "returns": []},
{ "method": "call", "params": [{}], "order": [], "returns": ""},
{ "method": "block", "params": { "params": {}}, "order": ["params"], "returns": {}},
{ "method": "transaction", "params": { "params": {}, "i": 0}, "order": ["params", "i"], "returns": {}},
{ "method": "uncle", "params": { "params": {}, "i": 0}, "order": ["params", "i"], "returns": {}},
{ "method": "block", "params": [0, ""],"order": [], "returns": {}},
{ "method": "transaction", "params": [0, "", 0], "order": [], "returns": {}},
{ "method": "uncle", "params": [0, "", 0], "order": [], "returns": {}},
{ "method": "compile", "params": [""], "order": [], "returns": ""},
{ "method": "messages", "params": { "params": {}}, "order": ["params"], "returns": []},
{ "method": "watch", "params": { "params": ""}, "order": ["params"], "returns": 0},
{ "method": "check", "params": { "id": 0}, "order": [], "returns": true},
{ "method": "killWatch", "params": { "id": 0}, "order": ["params"], "returns": true},
{ "method": "secretToAddress", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""},
{ "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "toFixed", "params": {"s": 0.0}, "order": ["s"], "returns" : ""},
{ "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0},
{ "method": "offset", "params": {"s": "", "o": 0}, "order": ["s", "o"], "returns" : ""}
{ "method": "killWatch", "params": { "id": 0}, "order": ["params"], "returns": true}
]

67
test/jsonrpc.cpp

@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_balanceAt)
cnote << "Testing jsonrpc balanceAt...";
dev::KeyPair key = KeyPair::create();
auto address = key.address();
string balance = jsonrpcClient->balanceAt(toJS(address), 0);
string balance = jsonrpcClient->balanceAt(toJS(address));
BOOST_CHECK_EQUAL(toJS(web3.ethereum()->balanceAt(address)), balance);
}
@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(jsonrpc_countAt)
cnote << "Testing jsonrpc countAt...";
dev::KeyPair key = KeyPair::create();
auto address = key.address();
double countAt = jsonrpcClient->countAt(toJS(address), 0);
double countAt = jsonrpcClient->countAt(toJS(address));
BOOST_CHECK_EQUAL(countAt, (double)(uint64_t)web3.ethereum()->countAt(address, 0));
}
@ -109,26 +109,6 @@ BOOST_AUTO_TEST_CASE(jsonrpc_defaultBlock)
BOOST_CHECK_EQUAL(defaultBlock, web3.ethereum()->getDefault());
}
BOOST_AUTO_TEST_CASE(jsonrpc_fromAscii)
{
cnote << "Testing jsonrpc fromAscii...";
string testString = "1234567890987654";
string fromAscii = jsonrpcClient->fromAscii(32, testString);
BOOST_CHECK_EQUAL(fromAscii, jsFromBinary(testString, 32));
}
BOOST_AUTO_TEST_CASE(jsonrpc_fromFixed)
{
cnote << "Testing jsonrpc fromFixed...";
string testString = "0x1234567890987654";
double fromFixed = jsonrpcClient->fromFixed(testString);
double ff = jsFromFixed(testString);
string str1 = boost::lexical_cast<string> (fromFixed);
string str2 = boost::lexical_cast<string> (ff);
BOOST_CHECK_EQUAL(str1.substr(0, 3), str2.substr(0, 3));
}
BOOST_AUTO_TEST_CASE(jsonrpc_gasPrice)
{
cnote << "Testing jsonrpc gasPrice...";
@ -214,14 +194,6 @@ BOOST_AUTO_TEST_CASE(jsonrpc_peerCount)
BOOST_CHECK_EQUAL(web3.peerCount(), peerCount);
}
BOOST_AUTO_TEST_CASE(jsonrpc_secretToAddress)
{
cnote << "Testing jsonrpc secretToAddress...";
dev::KeyPair pair = dev::KeyPair::create();
string address = jsonrpcClient->secretToAddress(toJS(pair.secret()));
BOOST_CHECK_EQUAL(jsToAddress(address), pair.address());
}
BOOST_AUTO_TEST_CASE(jsonrpc_setListening)
{
cnote << "Testing jsonrpc setListening...";
@ -244,48 +216,15 @@ BOOST_AUTO_TEST_CASE(jsonrpc_setMining)
BOOST_CHECK_EQUAL(web3.ethereum()->isMining(), false);
}
BOOST_AUTO_TEST_CASE(jsonrpc_sha3)
{
cnote << "Testing jsonrpc sha3...";
string testString = "1234567890987654";
string sha3 = jsonrpcClient->sha3(testString);
BOOST_CHECK_EQUAL(jsToFixed<32>(sha3), dev::sha3(jsToBytes(testString)));
}
BOOST_AUTO_TEST_CASE(jsonrpc_stateAt)
{
cnote << "Testing jsonrpc stateAt...";
dev::KeyPair key = KeyPair::create();
auto address = key.address();
string stateAt = jsonrpcClient->stateAt(toJS(address), 0, "0");
string stateAt = jsonrpcClient->stateAt(toJS(address), "0");
BOOST_CHECK_EQUAL(toJS(web3.ethereum()->stateAt(address, jsToU256("0"), 0)), stateAt);
}
BOOST_AUTO_TEST_CASE(jsonrpc_toAscii)
{
cnote << "Testing jsonrpc toAscii...";
string testString = "1234567890987654";
string ascii = jsonrpcClient->toAscii(testString);
BOOST_CHECK_EQUAL(jsToBinary(testString), ascii);
}
BOOST_AUTO_TEST_CASE(jsonrpc_toDecimal)
{
cnote << "Testing jsonrpc toDecimal...";
string testString = "1234567890987654";
string decimal = jsonrpcClient->toDecimal(testString);
BOOST_CHECK_EQUAL(jsToDecimal(testString), decimal);
}
BOOST_AUTO_TEST_CASE(jsonrpc_toFixed)
{
cnote << "Testing jsonrpc toFixed...";
double testValue = 123567;
string fixed = jsonrpcClient->toFixed(testValue);
BOOST_CHECK_EQUAL(jsToFixed(testValue), fixed);
BOOST_CHECK_EQUAL(testValue, jsFromFixed(fixed));
}
BOOST_AUTO_TEST_CASE(jsonrpc_transact)
{
cnote << "Testing jsonrpc transact...";

197
test/webthreestubclient.h

@ -31,11 +31,10 @@ class WebThreeStubClient
}
std::string balanceAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
std::string balanceAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p["block"] = block;
p.append(param1);
Json::Value result = this->client->CallMethod("balanceAt",p);
if (result.isString())
@ -45,10 +44,11 @@ p["block"] = block;
}
Json::Value block(const Json::Value& params) throw (jsonrpc::JsonRpcException)
Json::Value block(const int& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["params"] = params;
p.append(param1);
p.append(param2);
Json::Value result = this->client->CallMethod("block",p);
if (result.isObject())
@ -58,10 +58,10 @@ p["block"] = block;
}
std::string call(const Json::Value& json) throw (jsonrpc::JsonRpcException)
std::string call(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
p.append(param1);
Json::Value result = this->client->CallMethod("call",p);
if (result.isString())
@ -84,11 +84,10 @@ p["block"] = block;
}
std::string codeAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
std::string codeAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p["block"] = block;
p.append(param1);
Json::Value result = this->client->CallMethod("codeAt",p);
if (result.isString())
@ -110,54 +109,39 @@ p["block"] = block;
}
double countAt(const std::string& address, const int& block) throw (jsonrpc::JsonRpcException)
std::string compile(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p["block"] = block;
Json::Value result = this->client->CallMethod("countAt",p);
if (result.isDouble())
return result.asDouble();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
p.append(param1);
}
int defaultBlock() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("defaultBlock",p);
if (result.isInt())
return result.asInt();
Json::Value result = this->client->CallMethod("compile",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string fromAscii(const int& padding, const std::string& s) throw (jsonrpc::JsonRpcException)
double countAt(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["padding"] = padding;
p["s"] = s;
p.append(param1);
Json::Value result = this->client->CallMethod("fromAscii",p);
if (result.isString())
return result.asString();
Json::Value result = this->client->CallMethod("countAt",p);
if (result.isDouble())
return result.asDouble();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
double fromFixed(const std::string& s) throw (jsonrpc::JsonRpcException)
int defaultBlock() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("fromFixed",p);
if (result.isDouble())
return result.asDouble();
p = Json::nullValue;
Json::Value result = this->client->CallMethod("defaultBlock",p);
if (result.isInt())
return result.asInt();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -200,19 +184,6 @@ p["s"] = s;
}
std::string lll(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("lll",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value messages(const Json::Value& params) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -250,20 +221,6 @@ 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)
{
Json::Value p;
@ -276,23 +233,10 @@ p["s"] = s;
}
std::string secretToAddress(const std::string& s) throw (jsonrpc::JsonRpcException)
bool setCoinbase(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("secretToAddress",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool setCoinbase(const std::string& address) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p.append(param1);
Json::Value result = this->client->CallMethod("setCoinbase",p);
if (result.isBool())
@ -302,10 +246,10 @@ p["s"] = s;
}
bool setListening(const bool& listening) throw (jsonrpc::JsonRpcException)
bool setListening(const bool& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["listening"] = listening;
p.append(param1);
Json::Value result = this->client->CallMethod("setListening",p);
if (result.isBool())
@ -315,10 +259,10 @@ p["s"] = s;
}
bool setMining(const bool& mining) throw (jsonrpc::JsonRpcException)
bool setMining(const bool& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["mining"] = mining;
p.append(param1);
Json::Value result = this->client->CallMethod("setMining",p);
if (result.isBool())
@ -328,25 +272,11 @@ p["s"] = s;
}
std::string sha3(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("sha3",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string stateAt(const std::string& address, const int& block, const std::string& storage) throw (jsonrpc::JsonRpcException)
std::string stateAt(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["address"] = address;
p["block"] = block;
p["storage"] = storage;
p.append(param1);
p.append(param2);
Json::Value result = this->client->CallMethod("stateAt",p);
if (result.isString())
@ -356,63 +286,25 @@ p["storage"] = storage;
}
std::string toAscii(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toAscii",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string toDecimal(const std::string& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toDecimal",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string toFixed(const double& s) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["s"] = s;
Json::Value result = this->client->CallMethod("toFixed",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string transact(const Json::Value& json) throw (jsonrpc::JsonRpcException)
Json::Value transact(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["json"] = json;
p.append(param1);
Json::Value result = this->client->CallMethod("transact",p);
if (result.isString())
return result.asString();
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value transaction(const int& i, const Json::Value& params) throw (jsonrpc::JsonRpcException)
Json::Value transaction(const int& param1, const std::string& param2, const int& param3) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["i"] = i;
p["params"] = params;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->client->CallMethod("transaction",p);
if (result.isObject())
@ -422,11 +314,12 @@ p["params"] = params;
}
Json::Value uncle(const int& i, const Json::Value& params) throw (jsonrpc::JsonRpcException)
Json::Value uncle(const int& param1, const std::string& param2, const int& param3) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p["i"] = i;
p["params"] = params;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->client->CallMethod("uncle",p);
if (result.isObject())

Loading…
Cancel
Save