Browse Source

EthStubServer renamed to WebThreeStubServer

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
4633dffc85
  1. 8
      eth/main.cpp
  2. 2
      libdevcore/CommonJS.cpp
  3. 2
      libdevcore/CommonJS.h
  4. 80
      libethrpc/WebThreeStubServer.cpp
  5. 8
      libethrpc/WebThreeStubServer.h
  6. 82
      libethrpc/abstractwebthreestubserver.h
  7. 10
      neth/main.cpp
  8. 20
      test/jsonrpc.cpp
  9. 12
      test/webthreestubclient.h
  10. 5
      third/MainWin.cpp
  11. 2
      third/MainWin.h

8
eth/main.cpp

@ -41,7 +41,7 @@
#include <readline/history.h>
#endif
#if ETH_JSONRPC
#include <libethrpc/EthStubServer.h>
#include <libethrpc/WebThreeStubServer.h>
#endif
#include "BuildInfo.h"
using namespace std;
@ -337,10 +337,10 @@ int main(int argc, char** argv)
web3.connect(remoteHost, remotePort);
#if ETH_JSONRPC
auto_ptr<EthStubServer> jsonrpcServer;
auto_ptr<WebThreeStubServer> jsonrpcServer;
if (jsonrpc > -1)
{
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@ -428,7 +428,7 @@ int main(int argc, char** argv)
{
if (jsonrpc < 0)
jsonrpc = 8080;
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}

2
libdevcore/CommonJS.cpp

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthStubServer.cpp
/** @file CommonJS.cpp
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>

2
libdevcore/CommonJS.h

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthStubServer.cpp
/** @file CommonJS.h
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>

80
libethrpc/EthStubServer.cpp → libethrpc/WebThreeStubServer.cpp

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthStubServer.cpp
/** @file WebThreeStubServer.cpp
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>
@ -22,7 +22,7 @@
*/
#if ETH_JSONRPC
#include "EthStubServer.h"
#include "WebThreeStubServer.h"
#include <libevmface/Instruction.h>
#include <liblll/Compiler.h>
#include <libethereum/Client.h>
@ -96,23 +96,23 @@ static Json::Value toJson(const dev::eth::Transaction& t)
return res;
}
EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3):
AbstractEthStubServer(_conn),
WebThreeStubServer::WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3):
AbstractWebThreeStubServer(_conn),
m_web3(_web3)
{
}
dev::eth::Interface* EthStubServer::client() const
dev::eth::Interface* WebThreeStubServer::client() const
{
return m_web3.ethereum();
}
std::string EthStubServer::balanceAt(const string &address, const int& block)
std::string WebThreeStubServer::balanceAt(const string &address, const int& block)
{
return toJS(client()->balanceAt(jsToAddress(address), block));
}
dev::FixedHash<32> EthStubServer::numberOrHash(Json::Value const &json) const
dev::FixedHash<32> WebThreeStubServer::numberOrHash(Json::Value const &json) const
{
dev::FixedHash<32> hash;
if (!json["hash"].empty())
@ -122,7 +122,7 @@ dev::FixedHash<32> EthStubServer::numberOrHash(Json::Value const &json) const
return hash;
}
Json::Value EthStubServer::block(const Json::Value &params)
Json::Value WebThreeStubServer::block(const Json::Value &params)
{
if (!client())
return "";
@ -169,7 +169,7 @@ static TransactionJS toTransaction(const Json::Value &json)
return ret;
}
std::string EthStubServer::call(const Json::Value &json)
std::string WebThreeStubServer::call(const Json::Value &json)
{
std::string ret;
if (!client())
@ -187,59 +187,59 @@ std::string EthStubServer::call(const Json::Value &json)
return ret;
}
std::string EthStubServer::codeAt(const string &address, const int& block)
std::string WebThreeStubServer::codeAt(const string &address, const int& block)
{
return client() ? jsFromBinary(client()->codeAt(jsToAddress(address), block)) : "";
}
std::string EthStubServer::coinbase()
std::string WebThreeStubServer::coinbase()
{
return client() ? toJS(client()->address()) : "";
}
double EthStubServer::countAt(const string &address, const int& block)
double WebThreeStubServer::countAt(const string &address, const int& block)
{
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(address), block) : 0;
}
int EthStubServer::defaultBlock()
int WebThreeStubServer::defaultBlock()
{
return client() ? client()->getDefault() : 0;
}
std::string EthStubServer::fromAscii(const int& padding, const std::string& s)
std::string WebThreeStubServer::fromAscii(const int& padding, const std::string& s)
{
return jsFromBinary(s, padding);
}
double EthStubServer::fromFixed(const string &s)
double WebThreeStubServer::fromFixed(const string &s)
{
return jsFromFixed(s);
}
std::string EthStubServer::gasPrice()
std::string WebThreeStubServer::gasPrice()
{
return toJS(10 * dev::eth::szabo);
}
bool EthStubServer::listening()
bool WebThreeStubServer::listening()
{
return m_web3.isNetworkStarted();
}
bool EthStubServer::mining()
bool WebThreeStubServer::mining()
{
return client() ? client()->isMining() : false;
}
std::string EthStubServer::key()
std::string WebThreeStubServer::key()
{
if (!m_keys.size())
return std::string();
return toJS(m_keys[0].sec());
}
Json::Value EthStubServer::keys()
Json::Value WebThreeStubServer::keys()
{
Json::Value ret;
for (auto i: m_keys)
@ -247,7 +247,7 @@ Json::Value EthStubServer::keys()
return ret;
}
std::string EthStubServer::lll(const string &s)
std::string WebThreeStubServer::lll(const string &s)
{
return toJS(dev::eth::compileLLL(s));
}
@ -300,7 +300,7 @@ static dev::eth::MessageFilter toMessageFilter(const Json::Value &json)
return filter;
}
Json::Value EthStubServer::messages(const Json::Value &json)
Json::Value WebThreeStubServer::messages(const Json::Value &json)
{
Json::Value res;
if (!client())
@ -308,33 +308,33 @@ Json::Value EthStubServer::messages(const Json::Value &json)
return toJson(client()->messages(toMessageFilter(json)));
}
int EthStubServer::number()
int WebThreeStubServer::number()
{
return client() ? client()->number() + 1 : 0;
}
std::string EthStubServer::offset(const int& o, const std::string& s)
std::string WebThreeStubServer::offset(const int& o, const std::string& s)
{
return toJS(jsToU256(s) + o);
}
int EthStubServer::peerCount()
int WebThreeStubServer::peerCount()
{
return m_web3.peerCount();
}
std::string EthStubServer::secretToAddress(const string &s)
std::string WebThreeStubServer::secretToAddress(const string &s)
{
return toJS(KeyPair(jsToSecret(s)).address());
}
bool EthStubServer::setCoinbase(const std::string &address)
bool WebThreeStubServer::setCoinbase(const std::string &address)
{
client()->setAddress(jsToAddress(address));
return true;
}
bool EthStubServer::setListening(const bool &listening)
bool WebThreeStubServer::setListening(const bool &listening)
{
if (listening)
m_web3.startNetwork();
@ -343,7 +343,7 @@ bool EthStubServer::setListening(const bool &listening)
return true;
}
bool EthStubServer::setMining(const bool &mining)
bool WebThreeStubServer::setMining(const bool &mining)
{
if (!client())
return Json::nullValue;
@ -355,32 +355,32 @@ bool EthStubServer::setMining(const bool &mining)
return true;
}
std::string EthStubServer::sha3(const string &s)
std::string WebThreeStubServer::sha3(const string &s)
{
return toJS(dev::eth::sha3(jsToBytes(s)));
}
std::string EthStubServer::stateAt(const string &address, const int& block, const string &storage)
std::string WebThreeStubServer::stateAt(const string &address, const int& block, const string &storage)
{
return client() ? toJS(client()->stateAt(jsToAddress(address), jsToU256(storage), block)) : "";
}
std::string EthStubServer::toAscii(const string &s)
std::string WebThreeStubServer::toAscii(const string &s)
{
return jsToBinary(s);
}
std::string EthStubServer::toDecimal(const string &s)
std::string WebThreeStubServer::toDecimal(const string &s)
{
return jsToDecimal(s);
}
std::string EthStubServer::toFixed(const double &s)
std::string WebThreeStubServer::toFixed(const double &s)
{
return jsToFixed(s);
}
std::string EthStubServer::transact(const Json::Value &json)
std::string WebThreeStubServer::transact(const Json::Value &json)
{
std::string ret;
if (!client())
@ -406,7 +406,7 @@ std::string EthStubServer::transact(const Json::Value &json)
return ret;
}
Json::Value EthStubServer::transaction(const int &i, const Json::Value &params)
Json::Value WebThreeStubServer::transaction(const int &i, const Json::Value &params)
{
if (!client())
return "";
@ -415,7 +415,7 @@ Json::Value EthStubServer::transaction(const int &i, const Json::Value &params)
return toJson(client()->transaction(hash, i));
}
Json::Value EthStubServer::uncle(const int &i, const Json::Value &params)
Json::Value WebThreeStubServer::uncle(const int &i, const Json::Value &params)
{
if (!client())
return "";
@ -424,7 +424,7 @@ Json::Value EthStubServer::uncle(const int &i, const Json::Value &params)
return toJson(client()->uncle(hash, i));
}
int EthStubServer::watch(const string &json)
int WebThreeStubServer::watch(const string &json)
{
unsigned ret = -1;
if (!client())
@ -444,14 +444,14 @@ int EthStubServer::watch(const string &json)
return ret;
}
bool EthStubServer::check(const int& id)
bool WebThreeStubServer::check(const int& id)
{
if (!client())
return false;
return client()->checkWatch(id);
}
bool EthStubServer::killWatch(const int& id)
bool WebThreeStubServer::killWatch(const int& id)
{
if (!client())
return false;

8
libethrpc/EthStubServer.h → libethrpc/WebThreeStubServer.h

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file EthStubServer.h
/** @file WebThreeStubServer.h
* @authors:
* Gav Wood <i@gavwood.com>
* Marek Kotewicz <marek@ethdev.com>
@ -28,15 +28,15 @@
#include <libdevcrypto/Common.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "abstractethstubserver.h"
#include "abstractwebthreestubserver.h"
#pragma GCC diagnostic pop
namespace dev { class WebThreeDirect; namespace eth { class Interface; } class KeyPair; }
class EthStubServer: public AbstractEthStubServer
class WebThreeStubServer: public AbstractWebThreeStubServer
{
public:
EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual std::string balanceAt(const std::string& address, const int& block);
virtual Json::Value block(const Json::Value& params);

82
libethrpc/abstractethstubserver.h → libethrpc/abstractwebthreestubserver.h

@ -2,51 +2,51 @@
* THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!!
*/
#ifndef _ABSTRACTETHSTUBSERVER_H_
#define _ABSTRACTETHSTUBSERVER_H_
#ifndef _ABSTRACTWEBTHREESTUBSERVER_H_
#define _ABSTRACTWEBTHREESTUBSERVER_H_
#include <jsonrpc/rpc.h>
class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServer>
class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThreeStubServer>
{
public:
AbstractEthStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractEthStubServer>(conn)
{
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, "params",jsonrpc::JSON_OBJECT, 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("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::checkI);
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, "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);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::keyI);
this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::keysI);
this->bindAndAddMethod(new jsonrpc::Procedure("killWatch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::killWatchI);
this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::lllI);
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("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("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("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, "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);
this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "i",jsonrpc::JSON_INTEGER,"params",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::transactionI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "i",jsonrpc::JSON_INTEGER,"params",jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::uncleI);
this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "params",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::watchI);
AbstractWebThreeStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractWebThreeStubServer>(conn)
{
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("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("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::keyI);
this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::keysI);
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("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("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "params",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::watchI);
}
@ -257,4 +257,4 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual int watch(const std::string& params) = 0;
};
#endif //_ABSTRACTETHSTUBSERVER_H_
#endif //_ABSTRACTWEBTHREESTUBSERVER_H_

10
neth/main.cpp

@ -33,8 +33,8 @@
#include <libevmface/Instruction.h>
#include <libethereum/All.h>
#if ETH_JSONRPC
#include <libethrpc/EthStubServer.h>
#include <libethrpc/abstractethstubserver.h>
#include <libethrpc/WebThreeStubServer.h>
#include <libethrpc/abstractwebthreestubserver.h>
#include <libdevcore/CommonJS.h>
#endif
#include <libwebthree/WebThree.h>
@ -475,10 +475,10 @@ int main(int argc, char** argv)
c.startMining();
#if ETH_JSONRPC
auto_ptr<EthStubServer> jsonrpcServer;
auto_ptr<WebThreeStubServer> jsonrpcServer;
if (jsonrpc > -1)
{
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@ -552,7 +552,7 @@ int main(int argc, char** argv)
{
if (jsonrpc < 0)
jsonrpc = 8080;
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}

20
test/jsonrpc.cpp

@ -27,29 +27,30 @@
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonJS.h>
#include <libwebthree/WebThree.h>
#include <libethrpc/EthStubServer.h>
#include <libethrpc/WebThreeStubServer.h>
#include <libethrpc/CorsHttpServer.h>
#include <jsonrpc/connectors/httpserver.h>
#include <jsonrpc/connectors/httpclient.h>
#include <set>
#include "JsonSpiritHeaders.h"
#include "TestHelper.h"
#include "ethstubclient.h"
#include "webthreestubclient.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;
namespace jsonrpc_tests {
string name = "Ethereum(++) tests";
string dbPath;
dev::WebThreeDirect web3(name, dbPath, true);
auto_ptr<EthStubServer> jsonrpcServer;
auto_ptr<EthStubClient> jsonrpcClient;
auto s = set<string>{"eth", "shh"};
dev::p2p::NetworkPreferences np(30303, std::string(), false);
dev::WebThreeDirect web3(name, dbPath, true, s, np);
auto_ptr<WebThreeStubServer> jsonrpcServer;
auto_ptr<WebThreeStubClient> jsonrpcClient;
struct JsonrpcFixture {
JsonrpcFixture()
@ -58,10 +59,10 @@ struct JsonrpcFixture {
web3.setIdealPeerCount(5);
web3.ethereum()->setForceMining(true);
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(8080), web3));
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new jsonrpc::CorsHttpServer(8080), web3));
jsonrpcServer->StartListening();
jsonrpcClient = auto_ptr<EthStubClient>(new EthStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
jsonrpcClient = auto_ptr<WebThreeStubClient>(new WebThreeStubClient(new jsonrpc::HttpClient("http://localhost:8080")));
}
~JsonrpcFixture()
{
@ -322,7 +323,6 @@ BOOST_AUTO_TEST_CASE(jsonrpc_transact)
BOOST_CHECK_EQUAL(txAmount, jsToU256(messages[0u]["value"].asString()));
}
}
#endif

12
test/ethstubclient.h → test/webthreestubclient.h

@ -2,19 +2,19 @@
* THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!!
*/
#ifndef _ETHSTUBCLIENT_H_
#define _ETHSTUBCLIENT_H_
#ifndef _WEBTHREESTUBCLIENT_H_
#define _WEBTHREESTUBCLIENT_H_
#include <jsonrpc/rpc.h>
class EthStubClient
class WebThreeStubClient
{
public:
EthStubClient(jsonrpc::AbstractClientConnector* conn)
WebThreeStubClient(jsonrpc::AbstractClientConnector* conn)
{
this->client = new jsonrpc::Client(conn);
}
~EthStubClient()
~WebThreeStubClient()
{
delete this->client;
}
@ -464,4 +464,4 @@ p["params"] = params;
private:
jsonrpc::Client* client;
};
#endif //_ETHSTUBCLIENT_H_
#endif //_WEBTHREESTUBCLIENT_H_

5
third/MainWin.cpp

@ -157,6 +157,11 @@ eth::Client* Main::ethereum() const
return m_web3->ethereum();
}
dev::p2p::Host* Main::peer2peer() const
{
return web3()->peer2peer();
}
std::shared_ptr<dev::shh::WhisperHost> Main::whisper() const
{
return m_web3->whisper();

2
third/MainWin.h

@ -59,6 +59,7 @@ public:
dev::WebThreeDirect* web3() const { return m_web3.get(); }
dev::eth::Client* ethereum() const;
dev::p2p::Host* peer2peer() const;
std::shared_ptr<dev::shh::WhisperHost> whisper() const;
QList<dev::KeyPair> const& owned() const { return m_myKeys; }
@ -134,4 +135,5 @@ private:
QEthereum* m_ethereum = nullptr;
QWhisper* m_whisper = nullptr;
QPeer2Peer* m_p2p = nullptr;
};

Loading…
Cancel
Save