diff --git a/eth/CommonJS.cpp b/eth/CommonJS.cpp
deleted file mode 100644
index 57958a117..000000000
--- a/eth/CommonJS.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file CommonJS.cpp
- * @authors:
- * Gav Wood
- * @date 2014
- */
-
-#include "CommonJS.h"
-using namespace std;
-using namespace dev;
-using namespace dev::eth;
-
-bytes dev::eth::jsToBytes(string const& _s)
-{
- if (_s.substr(0, 2) == "0x")
- // Hex
- return fromHex(_s.substr(2));
- else if (_s.find_first_not_of("0123456789") == string::npos)
- // Decimal
- return toCompactBigEndian(bigint(_s));
- else
- // Binary
- return asBytes(_s);
-}
-
-string dev::eth::jsPadded(string const& _s, unsigned _l, unsigned _r)
-{
- bytes b = jsToBytes(_s);
- while (b.size() < _l)
- b.insert(b.begin(), 0);
- while (b.size() < _r)
- b.push_back(0);
- return asString(b).substr(b.size() - max(_l, _r));
-}
-
-string dev::eth::jsPadded(string const& _s, unsigned _l)
-{
- if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == string::npos)
- // Numeric: pad to right
- return jsPadded(_s, _l, _l);
- else
- // Text: pad to the left
- return jsPadded(_s, 0, _l);
-}
-
-string dev::eth::jsUnpadded(string _s)
-{
- auto p = _s.find_last_not_of((char)0);
- _s.resize(p == string::npos ? 0 : (p + 1));
- return _s;
-}
diff --git a/eth/CommonJS.h b/eth/CommonJS.h
deleted file mode 100644
index caa7e6651..000000000
--- a/eth/CommonJS.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- This file is part of cpp-ethereum.
-
- cpp-ethereum is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- cpp-ethereum is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cpp-ethereum. If not, see .
-*/
-/** @file CommonJS.h
- * @authors:
- * Gav Wood
- * @date 2014
- */
-
-#pragma once
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace dev
-{
-namespace eth
-{
-
-bytes jsToBytes(std::string const& _s);
-std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r);
-std::string jsPadded(std::string const& _s, unsigned _l);
-std::string jsUnpadded(std::string _s);
-
-template FixedHash jsToFixed(std::string const& _s)
-{
- if (_s.substr(0, 2) == "0x")
- // Hex
- return FixedHash(_s.substr(2));
- else if (_s.find_first_not_of("0123456789") == std::string::npos)
- // Decimal
- return (typename FixedHash::Arith)(_s);
- else
- // Binary
- return FixedHash(asBytes(jsPadded(_s, N)));
-}
-
-template boost::multiprecision::number> jsToInt(std::string const& _s)
-{
- if (_s.substr(0, 2) == "0x")
- // Hex
- return fromBigEndian>>(fromHex(_s.substr(2)));
- else if (_s.find_first_not_of("0123456789") == std::string::npos)
- // Decimal
- return boost::multiprecision::number>(_s);
- else
- // Binary
- return fromBigEndian>>(asBytes(jsPadded(_s, N)));
-}
-
-inline Address jsToAddress(std::string const& _s) { return jsToFixed<20>(_s); }
-inline Secret jsToSecret(std::string const& _s) { return jsToFixed<32>(_s); }
-inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); }
-
-template std::string toJS(FixedHash const& _h) { return "0x" + toHex(_h.ref()); }
-template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + toHex(toCompactBigEndian(_n)); }
-
-inline std::string jsToBinary(std::string const& _s)
-{
- return asString(jsToBytes(_s));
-}
-
-inline std::string jsToDecimal(std::string const& _s)
-{
- return toString(jsToU256(_s));
-}
-
-inline std::string jsToHex(std::string const& _s)
-{
- return "0x" + toHex(asBytes(_s));
-}
-
-}
-}
diff --git a/eth/EthStubServer.cpp b/eth/EthStubServer.cpp
index ad6a87781..77480d7a0 100644
--- a/eth/EthStubServer.cpp
+++ b/eth/EthStubServer.cpp
@@ -26,7 +26,7 @@
#include
#include
#include
-#include "CommonJS.h"
+#include
using namespace std;
using namespace dev;
using namespace dev::eth;
@@ -37,142 +37,164 @@ EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDi
{
}
-//only works with a json spec that doesn't have notifications for now
-Json::Value EthStubServer::procedures()
+dev::eth::Client& EthStubServer::ethereum() const
{
- Json::Value ret;
-
- for (auto proc: this->GetProtocolHanlder()->GetProcedures())
- {
- Json::Value proc_j;
+ return *m_web3.ethereum();
+}
- proc_j[proc.second->GetProcedureType() == 0 ? "method" : "notification"] = proc.first;
+std::string EthStubServer::balanceAt(const string &a, const string &block)
+{
- Json::Value params_j;
- for (auto params: proc.second->GetParameters())
- params_j[params.first] = jsontypeToValue(params.second);
- proc_j["params"] = params_j;
-
- proc_j["returns"] = jsontypeToValue(proc.second->GetReturnType());
+}
+
+std::string EthStubServer::block(const string &numberOrHash)
+{
- ret.append(proc_j);
- }
- return ret;
}
-dev::eth::Client& EthStubServer::ethereum() const
+std::string EthStubServer::call(const string &json)
{
- return *m_web3.ethereum();
+
}
-std::string EthStubServer::coinbase()
+std::string EthStubServer::codeAt(const string &a, const string &block)
{
- return toJS(ethereum().address());
+
}
-std::string EthStubServer::balanceAt(std::string const& _a)
+std::string EthStubServer::coinbase()
{
- return toJS(ethereum().balanceAt(jsToAddress(_a), 0));
+
}
-Json::Value EthStubServer::check(Json::Value const& _as)
+int EthStubServer::countAt(const string &a, const string &block)
{
- // TODO
-// if (ethereum().changed())
- return _as;
-/* else
- {
- Json::Value ret;
- ret.resize(0);
- return ret;
- }*/
+
}
-std::string EthStubServer::create(const std::string& _bCode, const std::string& _sec, const std::string& _xEndowment, const std::string& _xGas, const std::string& _xGasPrice)
+int EthStubServer::defaultBlock()
{
- Address ret = ethereum().transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
- return toJS(ret);
+
}
-std::string EthStubServer::lll(const std::string& _s)
+std::string EthStubServer::fromAscii(const string &s)
{
- return "0x" + toHex(dev::eth::compileLLL(_s));
+
}
-std::string EthStubServer::gasPrice()
+std::string EthStubServer::fromFixed(const string &s)
{
- return "100000000000000";
+
}
-bool EthStubServer::isContractAt(const std::string& _a)
+std::string EthStubServer::gasPrice()
{
- return ethereum().codeAt(jsToAddress(_a), 0).size();
+
}
bool EthStubServer::isListening()
{
- return m_web3.haveNetwork();
+
}
bool EthStubServer::isMining()
{
- return ethereum().isMining();
+
}
std::string EthStubServer::key()
{
- if (!m_keys.size())
- return std::string();
- return toJS(m_keys[0].sec());
+ if (!m_keys.size())
+ return std::string();
+ return toJS(m_keys[0].sec());
}
Json::Value EthStubServer::keys()
{
- Json::Value ret;
- for (auto i: m_keys)
- ret.append(toJS(i.secret()));
- return ret;
+ Json::Value ret;
+ for (auto i: m_keys)
+ ret.append(toJS(i.secret()));
+ return ret;
+}
+
+std::string EthStubServer::lll(const string &s)
+{
+
+}
+
+std::string EthStubServer::messages(const string &json)
+{
+
+}
+
+int EthStubServer::number()
+{
+
}
int EthStubServer::peerCount()
{
- return m_web3.peerCount();
+ return m_web3.peerCount();
}
-std::string EthStubServer::storageAt(const std::string& _a, const std::string& x)
+std::string EthStubServer::secretToAddress(const string &s)
{
- return toJS(ethereum().stateAt(jsToAddress(_a), jsToU256(x), 0));
+
}
-std::string EthStubServer::stateAt(const std::string& _a, const std::string& x, const std::string& s)
+std::string EthStubServer::setListening(const string &l)
{
- return toJS(ethereum().stateAt(jsToAddress(_a), jsToU256(x), std::atol(s.c_str())));
+
}
-Json::Value EthStubServer::transact(const std::string& _aDest, const std::string& _bData, const std::string& _sec, const std::string& _xGas, const std::string& _xGasPrice, const std::string& _xValue)
+std::string EthStubServer::setMining(const string &l)
{
- ethereum().transact(jsToSecret(_sec), jsToU256(_xValue), jsToAddress(_aDest), jsToBytes(_bData), jsToU256(_xGas), jsToU256(_xGasPrice));
- return Json::Value();
+
}
-std::string EthStubServer::txCountAt(const std::string& _a)
+std::string EthStubServer::sha3(const string &s)
{
- return toJS(ethereum().countAt(jsToAddress(_a), 0));
+
+}
+
+std::string EthStubServer::stateAt(const string &a, const string &block, const string &p)
+{
+
}
-std::string EthStubServer::secretToAddress(const std::string& _a)
+std::string EthStubServer::toAscii(const string &s)
{
- return toJS(KeyPair(jsToSecret(_a)).address());
+
}
-Json::Value EthStubServer::lastBlock()
+std::string EthStubServer::toDecimal(const string &s)
{
- return blockJson("");
+
}
-Json::Value EthStubServer::block(const std::string& _hash)
+std::string EthStubServer::toFixed(const string &s)
{
- return blockJson(_hash);
+
+}
+
+std::string EthStubServer::transact(const string &json)
+{
+
+}
+
+std::string EthStubServer::transaction(const string &i, const string &numberOrHash)
+{
+
+}
+
+std::string EthStubServer::uncle(const string &i, const string &numberOrHash)
+{
+
+}
+
+std::string EthStubServer::watch(const string &json)
+{
+
}
Json::Value EthStubServer::blockJson(const std::string& _hash)
diff --git a/eth/EthStubServer.h b/eth/EthStubServer.h
index 469abed07..c3f1e060e 100644
--- a/eth/EthStubServer.h
+++ b/eth/EthStubServer.h
@@ -36,27 +36,38 @@ class EthStubServer: public AbstractEthStubServer
public:
EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
- virtual Json::Value procedures();
- virtual std::string balanceAt(std::string const& _a);
- virtual Json::Value check(Json::Value const& _as);
- virtual std::string coinbase();
- virtual std::string create(const std::string& bCode, const std::string& sec, const std::string& xEndowment, const std::string& xGas, const std::string& xGasPrice);
- virtual std::string gasPrice();
- virtual bool isContractAt(const std::string& a);
- virtual bool isListening();
- virtual bool isMining();
- virtual std::string key();
- virtual Json::Value keys();
- virtual int peerCount();
- virtual std::string storageAt(const std::string& a, const std::string& x);
- virtual std::string stateAt(const std::string& a, const std::string& x, const std::string& s);
- virtual Json::Value transact(const std::string& aDest, const std::string& bData, const std::string& sec, const std::string& xGas, const std::string& xGasPrice, const std::string& xValue);
- virtual std::string txCountAt(const std::string& a);
- virtual std::string secretToAddress(const std::string& a);
- virtual Json::Value lastBlock();
- virtual std::string lll(const std::string& s);
- virtual Json::Value block(const std::string&);
- void setKeys(std::vector _keys) { m_keys = _keys; }
+ virtual std::string balanceAt(const std::string& a, const std::string& block);
+ virtual std::string block(const std::string& numberOrHash);
+ virtual std::string call(const std::string& json);
+ virtual std::string codeAt(const std::string& a, const std::string& block);
+ virtual std::string coinbase();
+ virtual int countAt(const std::string& a, const std::string& block);
+ virtual int defaultBlock();
+ virtual std::string fromAscii(const std::string& s);
+ virtual std::string fromFixed(const std::string& s);
+ virtual std::string gasPrice();
+ virtual bool isListening();
+ virtual bool isMining();
+ virtual std::string key();
+ virtual Json::Value keys();
+ virtual std::string lll(const std::string& s);
+ virtual std::string messages(const std::string& json);
+ virtual int number();
+ virtual int peerCount();
+ virtual std::string secretToAddress(const std::string& s);
+ virtual std::string setListening(const std::string& l);
+ virtual std::string setMining(const std::string& l);
+ virtual std::string sha3(const std::string& s);
+ virtual std::string stateAt(const std::string& a, const std::string& block, const std::string& p);
+ virtual std::string toAscii(const std::string& s);
+ virtual std::string toDecimal(const std::string& s);
+ virtual std::string toFixed(const std::string& s);
+ virtual std::string transact(const std::string& json);
+ virtual std::string transaction(const std::string& i, const std::string& numberOrHash);
+ virtual std::string uncle(const std::string& i, const std::string& numberOrHash);
+ virtual std::string watch(const std::string& json);
+
+ void setKeys(std::vector _keys) { m_keys = _keys; }
private:
dev::eth::Client& ethereum() const;
dev::WebThreeDirect& m_web3;
diff --git a/eth/abstractethstubserver.h b/eth/abstractethstubserver.h
index 6b55852dd..168ca425d 100644
--- a/eth/abstractethstubserver.h
+++ b/eth/abstractethstubserver.h
@@ -2,8 +2,8 @@
* THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!!
*/
-#ifndef _ABSTRACTTEST.HSERVER_H_
-#define _ABSTRACTTEST.HSERVER_H_
+#ifndef _AbstractEthStubServer_H_
+#define _AbstractEthStubServer_H_
#include
@@ -11,38 +11,38 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer(conn)
- {
- this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::balanceAtI);
- this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::blockI);
- this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::callI);
- this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::codeAtI);
- this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::coinbaseI);
- this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::countAtI);
- this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::defaultBlockI);
- this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::fromAsciiI);
- this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::fromFixedI);
- this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::gasPriceI);
- this->bindAndAddMethod(new jsonrpc::Procedure("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &Abstracttest.hServer::isListeningI);
- this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &Abstracttest.hServer::isMiningI);
- this->bindAndAddMethod(new jsonrpc::Procedure("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::keyI);
- this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &Abstracttest.hServer::keysI);
- this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::lllI);
- this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::messagesI);
- this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::numberI);
- this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::peerCountI);
- this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::secretToAddressI);
- this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::setListeningI);
- this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::setMiningI);
- this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::sha3I);
- this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING,"p",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::stateAtI);
- this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toAsciiI);
- this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toDecimalI);
- this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toFixedI);
- this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::transactI);
- this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::transactionI);
- this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::uncleI);
- this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::watchI);
+ jsonrpc::AbstractServer(conn)
+ {
+ this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::balanceAtI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::callI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, 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_INTEGER, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, 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, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromAsciiI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "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("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isListeningI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isMiningI);
+ 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("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_STRING, "json",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::messagesI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::numberI);
+ 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("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setListeningI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setMiningI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I);
+ this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING,"p",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_STRING, NULL), &AbstractEthStubServer::toFixedI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::transactI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::transactionI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::uncleI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::watchI);
}
@@ -229,4 +229,4 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer _accounts)
-{
- m_accounts = _accounts;
-}
-
-std::string CommonJS::ethTest() const
-{
- return "Hello World!";
-}
-
-std::string CommonJS::coinbase() const
-{
- return m_client ? toJS(client()->address()) : "";
-}
-
-bool CommonJS::isListening() const
-{
- return /*m_client ? client()->haveNetwork() :*/ false;
-}
-
-void CommonJS::setListening(bool _l)
-{
- if (!m_client)
- return;
-/* if (_l)
- client()->startNetwork();
- else
- client()->stopNetwork();*/
-}
-
-bool CommonJS::isMining() const
-{
- return m_client ? client()->isMining() : false;
-}
-
-void CommonJS::setMining(bool _l)
-{
- if (m_client)
- {
- if (_l)
- client()->startMining();
- else
- client()->stopMining();
- }
-}
-
-std::string CommonJS::gasPrice() const
-{
- return toJS(10 * dev::eth::szabo);
-}
-
-std::string CommonJS::key() const
-{
- if (m_accounts.empty())
- return toJS(KeyPair().sec());
- return toJS(m_accounts[0].sec());
-}
-
-std::vector CommonJS::keys() const
-{
- std::vector ret;
- for (auto i: m_accounts)
- ret.push_back(toJS(i.sec()));
- return ret;
-}
-
-unsigned CommonJS::peerCount() const
-{
- return /*m_client ? (unsigned)client()->peerCount() :*/ 0;
-}
-
-int CommonJS::defaultBlock() const
-{
- return m_client ? m_client->getDefault() : 0;
-}
-
-unsigned CommonJS::number() const
-{
- return m_client ? client()->number() + 1 : 0;
-}
-
-std::string CommonJS::balanceAt(const std::string &_a, int _block) const
-{
- return m_client ? toJS(client()->balanceAt(jsToAddress(_a), _block)) : "";
-}
-
-std::string CommonJS::stateAt(const std::string &_a, std::string &_p, int _block) const
-{
- return m_client ? toJS(client()->stateAt(jsToAddress(_a), jsToU256(_p), _block)) : "";
-}
-
-double CommonJS::countAt(const std::string &_a, int _block) const
-{
- return m_client ? (double)(uint64_t)client()->countAt(jsToAddress(_a), _block) : 0;
-}
-
-std::string CommonJS::codeAt(const std::string &_a, int _block) const
-{
- return m_client ? jsFromBinary(client()->codeAt(jsToAddress(_a), _block)) : "";
-}
-
-std::string CommonJS::transact(TransactionSkeleton _t)
-{
- std::string ret;
- if (!m_client)
- return ret;
- // what if there is no from accout specified?
- if (!_t.from.secret() && m_accounts.size())
- {
- auto b = m_accounts.front();
- for (auto a: m_accounts)
- if (client()->balanceAt(KeyPair(a).address()) > client()->balanceAt(KeyPair(b).address()))
- b = a;
- _t.from = b;
- }
- if (!_t.gasPrice)
- _t.gasPrice = 10 * dev::eth::szabo;
- if (!_t.gas)
- _t.gas = std::min(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(_t.from).address()) / _t.gasPrice);
- if (_t.to)
- client()->transact(_t.from.secret(), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice);
- else
- ret = toJS(client()->transact(_t.from.secret(), _t.value, _t.data, _t.gas, _t.gasPrice));
- client()->flushTransactions();
- return ret;
-}
-
-std::string CommonJS::call(TransactionSkeleton _t)
-{
- std::string ret;
- if (!m_client)
- return ret;
- if (!_t.to)
- return ret;
- if (!_t.from.secret() && m_accounts.size())
- _t.from = m_accounts[0];
- if (!_t.gasPrice)
- _t.gasPrice = 10 * dev::eth::szabo;
- if (!_t.gas)
- _t.gas = client()->balanceAt(_t.from.address()) / _t.gasPrice;
- ret = toJS(client()->call(_t.from.secret(), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice));
- return ret;
-}
-
-std::tuple CommonJS::block(const std::string &_numberOrHash) const
-{
- auto n = jsToU256(_numberOrHash);
- auto h = n < m_client->number() ? m_client->hashFromNumber((unsigned)n) : jsToFixed<32>(_numberOrHash);
- return std::make_tuple(m_client->blockInfo(h), m_client->blockDetails(h));
-}
-
diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h
index b48082ac1..7b64b164c 100644
--- a/libdevcore/CommonJS.h
+++ b/libdevcore/CommonJS.h
@@ -37,7 +37,6 @@ inline std::string jsToFixed(double _s)
return toJS(dev::u256(_s * (double)(dev::u256(1) << 128)));
}
-
template boost::multiprecision::number> jsToInt(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
@@ -66,71 +65,7 @@ inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32)
return jsFromBinary(asBytes(_s), _padding);
}
-// we note really need KeyPair from
-// but it usefull for checking the balance
-struct TransactionSkeleton
-{
- dev::KeyPair from;
- Address to;
- u256 value;
- bytes data;
- u256 gas;
- u256 gasPrice;
-};
-
-
-class CommonJS
-{
-public:
- CommonJS(dev::eth::Interface* _c) : m_client(_c) {}
- dev::eth::Interface* client() const;
- void setAccounts(std::vector _accounts);
-
- std::string ethTest() const;
-
- // properties
- std::string coinbase() const;
- bool isListening() const;
- void setListening(bool _l);
- bool isMining() const;
- void setMining(bool _l);
- std::string /*dev::u256*/ gasPrice() const;
- std::string /*dev::KeyPair*/ key() const;
- std::vector /*list of dev::KeyPair*/ keys() const;
- unsigned peerCount() const;
- int defaultBlock() const;
- unsigned /*dev::u256*/ number() const;
-
- // synchronous getters
- std::string balanceAt(std::string const &_a, int _block) const;
- std::string stateAt(std::string const &_a, std::string &_p, int _block) const;
- double countAt(std::string const &_a, int _block) const;
- std::string codeAt(std::string const &_a, int _block) const;
-
- // transactions
- std::string transact(dev::eth::TransactionSkeleton _t);
- std::string call(dev::eth::TransactionSkeleton _t);
-
- // blockchain
- std::tuple block(std::string const &_numberOrHash) const;
- std::string transaction(std::string const &_numberOrHash, int _index) const;
- std::string uncle(std::string const &_numberOrHash, int _index) const;
-
- // watches and messages filtering
- std::string messages(std::string const &_attribs) const;
- // TODO watch
-
- // misc
- std::string secretToAddress(std::string const &_a) const;
- std::string lll(std::string const &_l) const;
- std::string sha3(std::string const &_s) const;
-
-
-private:
- dev::eth::Interface* m_client;
- std::vector m_accounts;
-};
}
}
diff --git a/neth/main.cpp b/neth/main.cpp
index cac19727c..661556283 100644
--- a/neth/main.cpp
+++ b/neth/main.cpp
@@ -36,8 +36,7 @@
#include
#include
#include
-#include
-#include
+#include
#endif
#include
#include "BuildInfo.h"