diff --git a/.gitignore b/.gitignore index c60cf19e1..b38a3f1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ ipch *.opensdf *.suo +# VIM stuff +*.swp + #Xcode stuff build_xc diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c1cf55c0..52721a702 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ endif() add_subdirectory(lllc) add_subdirectory(solc) add_subdirectory(sc) +if (JSONRPC_LS) + add_subdirectory(libweb3jsonrpc) +endif() if (NOT LANGUAGES) add_subdirectory(secp256k1) add_subdirectory(libp2p) @@ -156,7 +159,11 @@ if (NOT LANGUAGES) if ("${TARGET_PLATFORM}" STREQUAL "w64") cmake_policy(SET CMP0020 NEW) endif () - + if (NOT JSONRPC_LS) + message(FATAL_ERROR "Alethzero requires jsonrpc.") + endif() + + add_subdirectory(libjsqrc) add_subdirectory(libqethereum) add_subdirectory(alethzero) add_subdirectory(third) diff --git a/README.md b/README.md index d1d43815f..23a202510 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ All development goes in develop branch - please don't submit pull requests to ma Please read [CodingStandards.txt](CodingStandards.txt) thoroughly before making alterations to the code base. Please do *NOT* use an editor that automatically reformats whitespace away from astylerc or the formatting guidelines as described in [CodingStandards.txt](CodingStandards.txt). -When altering eth/spec.json, mirror the changes to eth/eth.js. This should simply be cutting and pasting the relevant part from spec.json into eth.js. Don't alter the spec part from eth.js independently. +libweb3jsonrpc/abstractwebthreestubserver.h is autogenerated from the jsonrpcstub executable that comes with the libjsonrpc library (json-rpc-cpp project). It shouldn't be maually altered. -eth/abstractethstubserver.h is autogenerated from the jsonrpcstub executable that comes with the libjsonrpc library (json-rpc-cpp project). It shouldn't be maually altered. +```bash +jsonrpcstub -s -c spec.json WebThreeStub +``` diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 4ad06f7a6..1548abbe3 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -53,7 +53,7 @@ else () endif () qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets) -target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore devcrypto secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore) +target_link_libraries(${EXECUTEABLE} webthree qethereum ethereum evm ethcore devcrypto secp256k1 gmp ${CRYPTOPP_LS} serpent lll evmface devcore web3jsonrpc jsqrc) if (APPLE) # First have qt5 install plugins and frameworks diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 2853536b9..f413532b7 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include "DownloadView.h" #include "MiningView.h" #include "BuildInfo.h" @@ -83,6 +85,21 @@ static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr) return QString(); } +static std::vector keysAsVector(QList const& keys) +{ + auto list = keys.toStdList(); + return {begin(list), end(list)}; +} + +static QString contentsOfQResource(std::string const& res) +{ + QFile file(QString::fromStdString(res)); + if (!file.open(QFile::ReadOnly)) + BOOST_THROW_EXCEPTION(FileError()); + QTextStream in(&file); + return in.readAll(); +} + Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f"); Main::Main(QWidget *parent) : @@ -131,32 +148,28 @@ Main::Main(QWidget *parent) : connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved())); m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/AlethZero", false, {"eth", "shh"})); - m_ldb = new QLDB(this); + + m_server = unique_ptr(new WebThreeStubServer(&m_qwebConnector, *web3(), keysAsVector(m_myKeys))); + m_server->setIdentities(keysAsVector(owned())); + m_server->StartListening(); connect(ui->webView, &QWebView::loadStarted, [this]() { - m_ethereum = nullptr; - m_whisper = nullptr; // NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it. - m_dev = new QDev(this); - m_ethereum = new QEthereum(this, ethereum(), m_myKeys); - m_whisper = new QWhisper(this, whisper(), owned()); + m_qweb = new QWebThree(this); + auto qweb = m_qweb; + m_qwebConnector.setQWeb(qweb); QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); QWebFrame* f = ui->webView->page()->mainFrame(); f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); - auto qdev = m_dev; - auto qeth = m_ethereum; - auto qshh = m_whisper; - auto qldb = m_ldb; - connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qdev, qeth, qshh, qldb)); - connect(m_whisper, SIGNAL(newIdToAdd(QString)), this, SLOT(addNewId(QString))); + connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb)); + connect(m_qweb, SIGNAL(onNewId(QString)), this, SLOT(addNewId(QString))); }); connect(ui->webView, &QWebView::loadFinished, [=]() { - m_ethereum->poll(); - m_whisper->poll(); + m_qweb->poll(); }); connect(ui->webView, &QWebView::titleChanged, [=]() @@ -165,9 +178,7 @@ Main::Main(QWidget *parent) : }); readSettings(); - installWatches(); - startTimer(100); { @@ -184,19 +195,17 @@ Main::~Main() { // Must do this here since otherwise m_ethereum'll be deleted (and therefore clearWatches() called by the destructor) // *after* the client is dead. - m_ethereum->clientDieing(); - m_whisper->faceDieing(); - + m_qweb->clientDieing(); g_logPost = simpleDebugOut; writeSettings(); } void Main::addNewId(QString _ids) { - Secret _id = toSecret(_ids); + Secret _id = jsToSecret(_ids.toStdString()); KeyPair kp(_id); m_myIdentities.push_back(kp); - m_whisper->setIdentities(owned()); + m_server->setIdentities(keysAsVector(owned())); } dev::p2p::NetworkPreferences Main::netPrefs() const @@ -1056,10 +1065,8 @@ void Main::timerEvent(QTimerEvent*) else interval += 100; - if (m_ethereum) - m_ethereum->poll(); - if (m_whisper) - m_whisper->poll(); + if (m_qweb) + m_qweb->poll(); for (auto const& i: m_handlers) if (ethereum()->checkWatch(i.first)) @@ -1182,8 +1189,9 @@ void Main::ourAccountsRowsMoved() myKeys.push_back(i); } m_myKeys = myKeys; - if (m_ethereum) - m_ethereum->setAccounts(myKeys); + + if (m_server.get()) + m_server->setAccounts(keysAsVector(m_myKeys)); } void Main::on_inject_triggered() @@ -1629,7 +1637,6 @@ void Main::on_killBlockchain_triggered() ui->net->setChecked(false); web3()->stopNetwork(); ethereum()->killChain(); - m_ethereum->setClient(ethereum()); readSettings(true); installWatches(); refreshAll(); @@ -1785,7 +1792,6 @@ void Main::on_debug_clicked() t.gasPrice = gasPrice(); t.gas = ui->gas->value(); t.data = m_data; - t.type = isCreation() ? Transaction::ContractCreation : Transaction::MessageCall; t.receiveAddress = isCreation() ? Address() : fromString(ui->destination->currentText()); t.sign(s); auto r = t.rlp(); @@ -2139,20 +2145,22 @@ void Main::on_post_clicked() m.setPayload(dataFromText(ui->shhData->toPlainText())); Public f = stringToPublic(ui->shhFrom->currentText()); Secret from; - if (m_whisper->ids().count(f)) - from = m_whisper->ids().at(f); + if (m_server->ids().count(f)) + from = m_server->ids().at(f); whisper()->inject(m.seal(from, topicFromText(ui->shhTopic->toPlainText()), ui->shhTtl->value(), ui->shhWork->value())); } void Main::on_newIdentity_triggered() { - m_whisper->makeIdentity(); + KeyPair kp = KeyPair::create(); + m_myIdentities.append(kp); + m_server->setIdentities(keysAsVector(owned())); } void Main::refreshWhisper() { ui->shhFrom->clear(); - for (auto i: m_whisper->ids()) + for (auto i: m_server ->ids()) ui->shhFrom->addItem(QString::fromStdString(toHex(i.first.ref()))); } @@ -2163,7 +2171,7 @@ void Main::refreshWhispers() { shh::Envelope const& e = w.second; shh::Message m; - for (pair const& i: m_whisper->ids()) + for (pair const& i: m_server->ids()) if (!!(m = e.open(i.second))) break; if (!m) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 8905e53dc..ba2592491 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -47,6 +47,7 @@ class MessageFilter; }} class QQuickView; +class WebThreeStubServer; struct WorldState { @@ -153,11 +154,10 @@ private slots: void on_newIdentity_triggered(); void refreshWhisper(); - void addNewId(QString); + void addNewId(QString _ids); signals: void poll(); - void idsChanged(); private: dev::p2p::NetworkPreferences netPrefs() const; @@ -181,8 +181,6 @@ private: void readSettings(bool _skipGeometry = false); void writeSettings(); - void keysChanged(); - bool isCreation() const; dev::u256 fee() const; dev::u256 total() const; @@ -193,6 +191,8 @@ private: unsigned installWatch(dev::h256 _tf, std::function const& _f); void uninstallWatch(unsigned _w); + void keysChanged(); + void onNewPending(); void onNewBlock(); void onNameRegChange(); @@ -255,8 +255,7 @@ private: QString m_logHistory; bool m_logChanged = true; - QDev* m_dev = nullptr; - QEthereum* m_ethereum = nullptr; - QWhisper* m_whisper = nullptr; - QLDB* m_ldb = nullptr; + std::unique_ptr m_server; + QWebThreeConnector m_qwebConnector; + QWebThree* m_qweb = nullptr; }; diff --git a/alethzero/main.cpp b/alethzero/main.cpp index 42afd5e66..8a430b0e9 100644 --- a/alethzero/main.cpp +++ b/alethzero/main.cpp @@ -4,6 +4,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + Q_INIT_RESOURCE(js); Main w; w.show(); diff --git a/eth/BigInteger.js b/eth/BigInteger.js deleted file mode 100644 index e4a9d1c7b..000000000 --- a/eth/BigInteger.js +++ /dev/null @@ -1,379 +0,0 @@ -var bigInt = (function () { - var base = 10000000, logBase = 7; - var sign = { - positive: false, - negative: true - }; - - var normalize = function (first, second) { - var a = first.value, b = second.value; - var length = a.length > b.length ? a.length : b.length; - for (var i = 0; i < length; i++) { - a[i] = a[i] || 0; - b[i] = b[i] || 0; - } - for (var i = length - 1; i >= 0; i--) { - if (a[i] === 0 && b[i] === 0) { - a.pop(); - b.pop(); - } else break; - } - if (!a.length) a = [0], b = [0]; - first.value = a; - second.value = b; - }; - - var parse = function (text, first) { - if (typeof text === "object") return text; - text += ""; - var s = sign.positive, value = []; - if (text[0] === "-") { - s = sign.negative; - text = text.slice(1); - } - var base = 10; - if (text.slice(0, 2) == "0x") { - base = 16; - text = text.slice(2); - } - else { - var texts = text.split("e"); - if (texts.length > 2) throw new Error("Invalid integer"); - if (texts[1]) { - var exp = texts[1]; - if (exp[0] === "+") exp = exp.slice(1); - exp = parse(exp); - if (exp.lesser(0)) throw new Error("Cannot include negative exponent part for integers"); - while (exp.notEquals(0)) { - texts[0] += "0"; - exp = exp.prev(); - } - } - text = texts[0]; - } - if (text === "-0") text = "0"; - text = text.toUpperCase(); - var isValid = (base == 16 ? /^[0-9A-F]*$/ : /^[0-9]+$/).test(text); - if (!isValid) throw new Error("Invalid integer"); - if (base == 16) { - var val = bigInt(0); - while (text.length) { - v = text.charCodeAt(0) - 48; - if (v > 9) - v -= 7; - text = text.slice(1); - val = val.times(16).plus(v); - } - return val; - } - else { - while (text.length) { - var divider = text.length > logBase ? text.length - logBase : 0; - value.push(+text.slice(divider)); - text = text.slice(0, divider); - } - var val = bigInt(value, s); - if (first) normalize(first, val); - return val; - } - }; - - var goesInto = function (a, b) { - var a = bigInt(a, sign.positive), b = bigInt(b, sign.positive); - if (a.equals(0)) throw new Error("Cannot divide by 0"); - var n = 0; - do { - var inc = 1; - var c = bigInt(a.value, sign.positive), t = c.times(10); - while (t.lesser(b)) { - c = t; - inc *= 10; - t = t.times(10); - } - while (c.lesserOrEquals(b)) { - b = b.minus(c); - n += inc; - } - } while (a.lesserOrEquals(b)); - - return { - remainder: b.value, - result: n - }; - }; - - var bigInt = function (value, s) { - var self = { - value: value, - sign: s - }; - var o = { - value: value, - sign: s, - negate: function (m) { - var first = m || self; - return bigInt(first.value, !first.sign); - }, - abs: function (m) { - var first = m || self; - return bigInt(first.value, sign.positive); - }, - add: function (n, m) { - var s, first = self, second; - if (m) (first = parse(n)) && (second = parse(m)); - else second = parse(n, first); - s = first.sign; - if (first.sign !== second.sign) { - first = bigInt(first.value, sign.positive); - second = bigInt(second.value, sign.positive); - return s === sign.positive ? - o.subtract(first, second) : - o.subtract(second, first); - } - normalize(first, second); - var a = first.value, b = second.value; - var result = [], - carry = 0; - for (var i = 0; i < a.length || carry > 0; i++) { - var sum = (a[i] || 0) + (b[i] || 0) + carry; - carry = sum >= base ? 1 : 0; - sum -= carry * base; - result.push(sum); - } - return bigInt(result, s); - }, - plus: function (n, m) { - return o.add(n, m); - }, - subtract: function (n, m) { - var first = self, second; - if (m) (first = parse(n)) && (second = parse(m)); - else second = parse(n, first); - if (first.sign !== second.sign) return o.add(first, o.negate(second)); - if (first.sign === sign.negative) return o.subtract(o.negate(second), o.negate(first)); - if (o.compare(first, second) === -1) return o.negate(o.subtract(second, first)); - var a = first.value, b = second.value; - var result = [], - borrow = 0; - for (var i = 0; i < a.length; i++) { - var tmp = a[i] - borrow; - borrow = tmp < b[i] ? 1 : 0; - var minuend = (borrow * base) + tmp - b[i]; - result.push(minuend); - } - return bigInt(result, sign.positive); - }, - minus: function (n, m) { - return o.subtract(n, m); - }, - multiply: function (n, m) { - var s, first = self, second; - if (m) (first = parse(n)) && (second = parse(m)); - else second = parse(n, first); - s = first.sign !== second.sign; - var a = first.value, b = second.value; - var resultSum = []; - for (var i = 0; i < a.length; i++) { - resultSum[i] = []; - var j = i; - while (j--) { - resultSum[i].push(0); - } - } - var carry = 0; - for (var i = 0; i < a.length; i++) { - var x = a[i]; - for (var j = 0; j < b.length || carry > 0; j++) { - var y = b[j]; - var product = y ? (x * y) + carry : carry; - carry = product > base ? Math.floor(product / base) : 0; - product -= carry * base; - resultSum[i].push(product); - } - } - var max = -1; - for (var i = 0; i < resultSum.length; i++) { - var len = resultSum[i].length; - if (len > max) max = len; - } - var result = [], carry = 0; - for (var i = 0; i < max || carry > 0; i++) { - var sum = carry; - for (var j = 0; j < resultSum.length; j++) { - sum += resultSum[j][i] || 0; - } - carry = sum > base ? Math.floor(sum / base) : 0; - sum -= carry * base; - result.push(sum); - } - return bigInt(result, s); - }, - times: function (n, m) { - return o.multiply(n, m); - }, - divmod: function (n, m) { - var s, first = self, second; - if (m) (first = parse(n)) && (second = parse(m)); - else second = parse(n, first); - s = first.sign !== second.sign; - if (bigInt(first.value, first.sign).equals(0)) return { - quotient: bigInt([0], sign.positive), - remainder: bigInt([0], sign.positive) - }; - if (second.equals(0)) throw new Error("Cannot divide by zero"); - var a = first.value, b = second.value; - var result = [], remainder = []; - for (var i = a.length - 1; i >= 0; i--) { - var n = [a[i]].concat(remainder); - var quotient = goesInto(b, n); - result.push(quotient.result); - remainder = quotient.remainder; - } - result.reverse(); - return { - quotient: bigInt(result, s), - remainder: bigInt(remainder, first.sign) - }; - }, - divide: function (n, m) { - return o.divmod(n, m).quotient; - }, - over: function (n, m) { - return o.divide(n, m); - }, - mod: function (n, m) { - return o.divmod(n, m).remainder; - }, - pow: function (n, m) { - var first = self, second; - if (m) (first = parse(n)) && (second = parse(m)); - else second = parse(n, first); - var a = first, b = second; - if (b.lesser(0)) return ZERO; - if (b.equals(0)) return ONE; - var result = bigInt(a.value, a.sign); - - if (b.mod(2).equals(0)) { - var c = result.pow(b.over(2)); - return c.times(c); - } else { - return result.times(result.pow(b.minus(1))); - } - }, - next: function (m) { - var first = m || self; - return o.add(first, 1); - }, - prev: function (m) { - var first = m || self; - return o.subtract(first, 1); - }, - compare: function (n, m) { - var first = self, second; - if (m) (first = parse(n)) && (second = parse(m, first)); - else second = parse(n, first); - normalize(first, second); - if (first.value.length === 1 && second.value.length === 1 && first.value[0] === 0 && second.value[0] === 0) return 0; - if (second.sign !== first.sign) return first.sign === sign.positive ? 1 : -1; - var multiplier = first.sign === sign.positive ? 1 : -1; - var a = first.value, b = second.value; - for (var i = a.length - 1; i >= 0; i--) { - if (a[i] > b[i]) return 1 * multiplier; - if (b[i] > a[i]) return -1 * multiplier; - } - return 0; - }, - compareAbs: function (n, m) { - var first = self, second; - if (m) (first = parse(n)) && (second = parse(m, first)); - else second = parse(n, first); - first.sign = second.sign = sign.positive; - return o.compare(first, second); - }, - equals: function (n, m) { - return o.compare(n, m) === 0; - }, - notEquals: function (n, m) { - return !o.equals(n, m); - }, - lesser: function (n, m) { - return o.compare(n, m) < 0; - }, - greater: function (n, m) { - return o.compare(n, m) > 0; - }, - greaterOrEquals: function (n, m) { - return o.compare(n, m) >= 0; - }, - lesserOrEquals: function (n, m) { - return o.compare(n, m) <= 0; - }, - isPositive: function (m) { - var first = m || self; - return first.sign === sign.positive; - }, - isNegative: function (m) { - var first = m || self; - return first.sign === sign.negative; - }, - isEven: function (m) { - var first = m || self; - return first.value[0] % 2 === 0; - }, - isOdd: function (m) { - var first = m || self; - return first.value[0] % 2 === 1; - }, - toString: function (m) { - var first = m || self; - var str = "", len = first.value.length; - while (len--) { - if (first.value[len].toString().length === 8) str += first.value[len]; - else str += (base.toString() + first.value[len]).slice(-logBase); - } - while (str[0] === "0") { - str = str.slice(1); - } - if (!str.length) str = "0"; - var s = (first.sign === sign.positive || str == "0") ? "" : "-"; - return s + str; - }, - toHex: function (m) { - var first = m || self; - var str = ""; - var l = this.abs(); - while (l > 0) { - var qr = l.divmod(256); - var b = qr.remainder.toJSNumber(); - str = (b >> 4).toString(16) + (b & 15).toString(16) + str; - l = qr.quotient; - } - return (this.isNegative() ? "-" : "") + "0x" + str; - }, - toJSNumber: function (m) { - return +o.toString(m); - }, - valueOf: function (m) { - return o.toJSNumber(m); - } - }; - return o; - }; - - var ZERO = bigInt([0], sign.positive); - var ONE = bigInt([1], sign.positive); - var MINUS_ONE = bigInt([1], sign.negative); - - var fnReturn = function (a) { - if (typeof a === "undefined") return ZERO; - return parse(a); - }; - fnReturn.zero = ZERO; - fnReturn.one = ONE; - fnReturn.minusOne = MINUS_ONE; - return fnReturn; -})(); - -if (typeof module !== "undefined") { - module.exports = bigInt; -} diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index d04cac504..70ed25f5e 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_policy(SET CMP0015 NEW) aux_source_directory(. SRC_LIST) include_directories(..) -link_directories(../libethcore) -link_directories(../libwebthree) set(EXECUTABLE eth) @@ -25,7 +23,7 @@ endif() target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) if(JSONRPC_LS) -target_link_libraries(${EXECUTABLE} ${JSONRPC_LS}) +target_link_libraries(${EXECUTABLE} web3jsonrpc) endif() if(READLINE_LS) target_link_libraries(${EXECUTABLE} ${READLINE_LS}) diff --git a/eth/EthStubServer.cpp b/eth/EthStubServer.cpp deleted file mode 100644 index ad6a87781..000000000 --- a/eth/EthStubServer.cpp +++ /dev/null @@ -1,217 +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 EthStubServer.cpp - * @authors: - * Gav Wood - * @date 2014 - */ - -#if ETH_JSONRPC -#include "EthStubServer.h" -#include -#include -#include -#include -#include "CommonJS.h" -using namespace std; -using namespace dev; -using namespace dev::eth; - -EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3): - AbstractEthStubServer(_conn), - m_web3(_web3) -{ -} - -//only works with a json spec that doesn't have notifications for now -Json::Value EthStubServer::procedures() -{ - Json::Value ret; - - for (auto proc: this->GetProtocolHanlder()->GetProcedures()) - { - Json::Value proc_j; - - proc_j[proc.second->GetProcedureType() == 0 ? "method" : "notification"] = proc.first; - - 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()); - - ret.append(proc_j); - } - return ret; -} - -dev::eth::Client& EthStubServer::ethereum() const -{ - return *m_web3.ethereum(); -} - -std::string EthStubServer::coinbase() -{ - return toJS(ethereum().address()); -} - -std::string EthStubServer::balanceAt(std::string const& _a) -{ - return toJS(ethereum().balanceAt(jsToAddress(_a), 0)); -} - -Json::Value EthStubServer::check(Json::Value const& _as) -{ - // 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) -{ - 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) -{ - return "0x" + toHex(dev::eth::compileLLL(_s)); -} - -std::string EthStubServer::gasPrice() -{ - return "100000000000000"; -} - -bool EthStubServer::isContractAt(const std::string& _a) -{ - 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()); -} - -Json::Value EthStubServer::keys() -{ - Json::Value ret; - for (auto i: m_keys) - ret.append(toJS(i.secret())); - return ret; -} - -int EthStubServer::peerCount() -{ - return m_web3.peerCount(); -} - -std::string EthStubServer::storageAt(const std::string& _a, const std::string& x) -{ - 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) -{ - 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) -{ - 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) -{ - return toJS(ethereum().countAt(jsToAddress(_a), 0)); -} - -std::string EthStubServer::secretToAddress(const std::string& _a) -{ - return toJS(KeyPair(jsToSecret(_a)).address()); -} - -Json::Value EthStubServer::lastBlock() -{ - return blockJson(""); -} - -Json::Value EthStubServer::block(const std::string& _hash) -{ - return blockJson(_hash); -} - -Json::Value EthStubServer::blockJson(const std::string& _hash) -{ - Json::Value res; - auto const& bc = ethereum().blockChain(); - - auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block(); - - auto bi = BlockInfo(b); - res["number"] = boost::lexical_cast(bi.number); - res["hash"] = boost::lexical_cast(bi.hash); - res["parentHash"] = boost::lexical_cast(bi.parentHash); - res["sha3Uncles"] = boost::lexical_cast(bi.sha3Uncles); - res["coinbaseAddress"] = boost::lexical_cast(bi.coinbaseAddress); - res["stateRoot"] = boost::lexical_cast(bi.stateRoot); - res["transactionsRoot"] = boost::lexical_cast(bi.transactionsRoot); - res["minGasPrice"] = boost::lexical_cast(bi.minGasPrice); - res["gasLimit"] = boost::lexical_cast(bi.gasLimit); - res["gasUsed"] = boost::lexical_cast(bi.gasUsed); - res["difficulty"] = boost::lexical_cast(bi.difficulty); - res["timestamp"] = boost::lexical_cast(bi.timestamp); - res["nonce"] = boost::lexical_cast(bi.nonce); - - return res; -} - -Json::Value EthStubServer::jsontypeToValue(int _jsontype) -{ - switch (_jsontype) - { - case jsonrpc::JSON_STRING: return ""; //Json::stringValue segfault, fuck knows why - case jsonrpc::JSON_BOOLEAN: return Json::booleanValue; - case jsonrpc::JSON_INTEGER: return Json::intValue; - case jsonrpc::JSON_REAL: return Json::realValue; - case jsonrpc::JSON_OBJECT: return Json::objectValue; - case jsonrpc::JSON_ARRAY: return Json::arrayValue; - default: return Json::nullValue; - } -} - -#endif diff --git a/eth/EthStubServer.h b/eth/EthStubServer.h deleted file mode 100644 index 469abed07..000000000 --- a/eth/EthStubServer.h +++ /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 EthStubServer.h - * @author Gav Wood - * @date 2014 - */ - -#pragma once - -#include -#include -#include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include "abstractethstubserver.h" -#pragma GCC diagnostic pop - -namespace dev { class WebThreeDirect; namespace eth { class Client; } class KeyPair; } - -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; } -private: - dev::eth::Client& ethereum() const; - dev::WebThreeDirect& m_web3; - std::vector m_keys; - Json::Value jsontypeToValue(int); - Json::Value blockJson(const std::string&); -}; diff --git a/eth/abstractethstubserver.h b/eth/abstractethstubserver.h deleted file mode 100644 index 7f110513d..000000000 --- a/eth/abstractethstubserver.h +++ /dev/null @@ -1,162 +0,0 @@ -/** - * THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!! - */ - -#ifndef _ABSTRACTETHSTUBSERVER_H_ -#define _ABSTRACTETHSTUBSERVER_H_ - -#include - -class AbstractEthStubServer : public jsonrpc::AbstractServer -{ - public: - AbstractEthStubServer(jsonrpc::AbstractServerConnector* conn) : - jsonrpc::AbstractServer(conn) - { - this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::balanceAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI); - this->bindAndAddMethod(new jsonrpc::Procedure("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "a",jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::checkI); - this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI); - this->bindAndAddMethod(new jsonrpc::Procedure("create", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "bCode",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xEndowment",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::createI); - this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI); - this->bindAndAddMethod(new jsonrpc::Procedure("isContractAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::isContractAtI); - 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("lastBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::lastBlockI); - 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("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI); - this->bindAndAddMethod(new jsonrpc::Procedure("procedures", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::proceduresI); - this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI); - this->bindAndAddMethod(new jsonrpc::Procedure("storageAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::storageAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "aDest",jsonrpc::JSON_STRING,"bData",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING,"xValue",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::transactI); - this->bindAndAddMethod(new jsonrpc::Procedure("txCountAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::txCountAtI); - - } - - inline virtual void balanceAtI(const Json::Value& request, Json::Value& response) - { - response = this->balanceAt(request["a"].asString()); - } - - inline virtual void blockI(const Json::Value& request, Json::Value& response) - { - response = this->block(request["a"].asString()); - } - - inline virtual void checkI(const Json::Value& request, Json::Value& response) - { - response = this->check(request["a"]); - } - - inline virtual void coinbaseI(const Json::Value& request, Json::Value& response) - { - response = this->coinbase(); - } - - inline virtual void createI(const Json::Value& request, Json::Value& response) - { - response = this->create(request["bCode"].asString(), request["sec"].asString(), request["xEndowment"].asString(), request["xGas"].asString(), request["xGasPrice"].asString()); - } - - inline virtual void gasPriceI(const Json::Value& request, Json::Value& response) - { - response = this->gasPrice(); - } - - inline virtual void isContractAtI(const Json::Value& request, Json::Value& response) - { - response = this->isContractAt(request["a"].asString()); - } - - inline virtual void isListeningI(const Json::Value& request, Json::Value& response) - { - response = this->isListening(); - } - - inline virtual void isMiningI(const Json::Value& request, Json::Value& response) - { - response = this->isMining(); - } - - inline virtual void keyI(const Json::Value& request, Json::Value& response) - { - response = this->key(); - } - - inline virtual void keysI(const Json::Value& request, Json::Value& response) - { - response = this->keys(); - } - - inline virtual void lastBlockI(const Json::Value& request, Json::Value& response) - { - response = this->lastBlock(); - } - - inline virtual void lllI(const Json::Value& request, Json::Value& response) - { - response = this->lll(request["s"].asString()); - } - - inline virtual void peerCountI(const Json::Value& request, Json::Value& response) - { - response = this->peerCount(); - } - - inline virtual void proceduresI(const Json::Value& request, Json::Value& response) - { - response = this->procedures(); - } - - inline virtual void secretToAddressI(const Json::Value& request, Json::Value& response) - { - response = this->secretToAddress(request["a"].asString()); - } - - inline virtual void storageAtI(const Json::Value& request, Json::Value& response) - { - response = this->storageAt(request["a"].asString(), request["x"].asString()); - } - - inline virtual void stateAtI(const Json::Value& request, Json::Value& response) - { - response = this->stateAt(request["a"].asString(), request["x"].asString(), request["s"].asString()); - } - - inline virtual void transactI(const Json::Value& request, Json::Value& response) - { - response = this->transact(request["aDest"].asString(), request["bData"].asString(), request["sec"].asString(), request["xGas"].asString(), request["xGasPrice"].asString(), request["xValue"].asString()); - } - - inline virtual void txCountAtI(const Json::Value& request, Json::Value& response) - { - response = this->txCountAt(request["a"].asString()); - } - - - virtual std::string balanceAt(const std::string& a) = 0; - virtual Json::Value block(const std::string& a) = 0; - virtual Json::Value check(const Json::Value& a) = 0; - virtual std::string coinbase() = 0; - virtual std::string create(const std::string& bCode, const std::string& sec, const std::string& xEndowment, const std::string& xGas, const std::string& xGasPrice) = 0; - virtual std::string gasPrice() = 0; - virtual bool isContractAt(const std::string& a) = 0; - virtual bool isListening() = 0; - virtual bool isMining() = 0; - virtual std::string key() = 0; - virtual Json::Value keys() = 0; - virtual Json::Value lastBlock() = 0; - virtual std::string lll(const std::string& s) = 0; - virtual int peerCount() = 0; - virtual Json::Value procedures() = 0; - virtual std::string secretToAddress(const std::string& a) = 0; - virtual std::string storageAt(const std::string& a, const std::string& x) = 0; - virtual std::string stateAt(const std::string& a, const std::string& x, const std::string& b) = 0; - 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) = 0; - virtual std::string txCountAt(const std::string& a) = 0; - -}; -#endif //_ABSTRACTETHSTUBSERVER_H_ diff --git a/eth/eth.js b/eth/eth.js deleted file mode 100644 index 791386a0b..000000000 --- a/eth/eth.js +++ /dev/null @@ -1,137 +0,0 @@ -if (typeof(window.eth) === "undefined") -{ -if (typeof(require) !== "undefined") - require( ['ethString'], function() {} ) -else if (typeof(String.prototype.pad) === "undefined") -{ - var scriptTag = document.getElementsByTagName('script'); - scriptTag = scriptTag[scriptTag.length - 1]; - var scriptPath = scriptTag.src; - var path = scriptPath.substr(0, scriptPath.lastIndexOf( '/' )); - var start = '