diff --git a/libethrpc/WebThreeStubServer.cpp b/libethrpc/WebThreeStubServer.cpp index 33067dcd7..ea0e03b61 100644 --- a/libethrpc/WebThreeStubServer.cpp +++ b/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) diff --git a/libethrpc/WebThreeStubServer.h b/libethrpc/WebThreeStubServer.h index c4fa66e78..f6e957d3b 100644 --- a/libethrpc/WebThreeStubServer.h +++ b/libethrpc/WebThreeStubServer.h @@ -39,43 +39,34 @@ public: WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3, std::vector _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 const& _accounts); private: dev::eth::Interface* client() const; dev::WebThreeDirect& m_web3; std::map m_accounts; - dev::FixedHash<32> numberOrHash(Json::Value const& _json) const; }; diff --git a/libethrpc/abstractwebthreestubserver.h b/libethrpc/abstractwebthreestubserver.h index 8b0878b50..876d671d8 100644 --- a/libethrpc/abstractwebthreestubserver.h +++ b/libethrpc/abstractwebthreestubserver.h @@ -13,38 +13,30 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer(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::AbstractServerbalanceAt(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::AbstractServercodeAt(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::AbstractServercoinbase(); } - 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::AbstractServerlistening(); } - 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::AbstractServernumber(); } - 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::AbstractServerbalanceAt(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 (fromFixed); - string str2 = boost::lexical_cast (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..."; diff --git a/test/webthreestubclient.h b/test/webthreestubclient.h index 86600a7f6..f35985b26 100644 --- a/test/webthreestubclient.h +++ b/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())