diff --git a/CMakeLists.txt b/CMakeLists.txt
index d69e1e958..9ed54656f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -369,7 +369,7 @@ if (NOT LANGUAGES)
add_subdirectory(third)
if(QTQML)
#add_subdirectory(iethxi)
- add_subdirectory(walleth)
+ #add_subdirectory(walleth) // resurect once we want to submit ourselves to QML.
endif()
endif()
endif()
diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt
index 3eac0a0b6..c5d1aa0be 100644
--- a/alethzero/CMakeLists.txt
+++ b/alethzero/CMakeLists.txt
@@ -52,7 +52,7 @@ else ()
endif ()
qt5_use_modules(${EXECUTEABLE} Core)# Gui Widgets Network WebKit WebKitWidgets)
-target_link_libraries(${EXECUTEABLE} 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)
if (APPLE)
# First have qt5 install plugins and frameworks
diff --git a/alethzero/DownloadView.cpp b/alethzero/DownloadView.cpp
new file mode 100644
index 000000000..657727a6a
--- /dev/null
+++ b/alethzero/DownloadView.cpp
@@ -0,0 +1,83 @@
+/*
+ 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 DownloadView.cpp
+ * @author Gav Wood
+ * @date 2014
+ */
+
+#include "DownloadView.h"
+
+#include
+#include
+#include
+#include "Grapher.h"
+
+using namespace std;
+using namespace dev;
+using namespace dev::eth;
+
+DownloadView::DownloadView(QWidget* _p): QWidget(_p)
+{
+}
+
+void DownloadView::paintEvent(QPaintEvent*)
+{
+ QPainter p(this);
+
+ p.fillRect(rect(), Qt::white);
+ if (!m_man || m_man->chain().empty() || !m_man->subCount())
+ return;
+
+ double ratio = (double)rect().width() / rect().height();
+ if (ratio < 1)
+ ratio = 1 / ratio;
+ double n = min(rect().width(), rect().height()) / ceil(sqrt(m_man->chain().size() / ratio));
+
+// QSizeF area(rect().width() / floor(rect().width() / n), rect().height() / floor(rect().height() / n));
+ QSizeF area(n, n);
+ QPointF pos(0, 0);
+
+ auto const& bg = m_man->blocksGot();
+
+ for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i)
+ {
+ int s = -2;
+ if (bg.contains(i))
+ s = -1;
+ else
+ {
+ unsigned h = 0;
+ m_man->foreachSub([&](DownloadSub const& sub)
+ {
+ if (sub.asked().contains(i))
+ s = h;
+ h++;
+ });
+ }
+ unsigned dh = 360 / m_man->subCount();
+ if (s == -2)
+ p.fillRect(QRectF(QPointF(pos) + QPointF(3 * area.width() / 8, 3 * area.height() / 8), area / 4), Qt::black);
+ else if (s == -1)
+ p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), Qt::black);
+ else
+ p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), QColor::fromHsv(s * dh, 64, 128));
+
+ pos.setX(pos.x() + n);
+ if (pos.x() >= rect().width() - n)
+ pos = QPoint(0, pos.y() + n);
+ }
+}
diff --git a/alethzero/DownloadView.h b/alethzero/DownloadView.h
new file mode 100644
index 000000000..22a11651c
--- /dev/null
+++ b/alethzero/DownloadView.h
@@ -0,0 +1,53 @@
+/*
+ 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 DownloadView.h
+ * @author Gav Wood
+ * @date 2014
+ */
+
+#pragma once
+
+#ifdef Q_MOC_RUN
+#define BOOST_MPL_IF_HPP_INCLUDED
+#endif
+
+#include
+#include
+#ifndef Q_MOC_RUN
+#include
+#endif
+
+namespace dev { namespace eth {
+struct MineInfo;
+class DownloadMan;
+}}
+
+class DownloadView: public QWidget
+{
+ Q_OBJECT
+
+public:
+ DownloadView(QWidget* _p = nullptr);
+
+ void setDownloadMan(dev::eth::DownloadMan const* _man) { m_man = _man; }
+
+protected:
+ virtual void paintEvent(QPaintEvent*);
+
+private:
+ dev::eth::DownloadMan const* m_man = nullptr;
+};
diff --git a/alethzero/Main.ui b/alethzero/Main.ui
index aa8a43f1c..dbc4bb144 100644
--- a/alethzero/Main.ui
+++ b/alethzero/Main.ui
@@ -132,6 +132,7 @@
+
@@ -1432,6 +1433,39 @@ font-size: 14pt
+
+
+ QDockWidget::DockWidgetFeatureMask
+
+
+ Blockchain Download
+
+
+ 2
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
+
+
+
&Quit
@@ -1698,6 +1732,14 @@ font-size: 14pt
Reserved Debug 1
+
+
+ true
+
+
+ Enable Local Addresses
+
+
@@ -1712,6 +1754,12 @@ font-size: 14pt
1
+
+ DownloadView
+ QWidget
+
+ 1
+
destination
diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp
index e9cdf90bc..b4bbb8ca7 100644
--- a/alethzero/MainWin.cpp
+++ b/alethzero/MainWin.cpp
@@ -30,6 +30,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -38,50 +39,16 @@
#include
#include
#include
+#include
+#include "DownloadView.h"
#include "MiningView.h"
#include "BuildInfo.h"
#include "MainWin.h"
#include "ui_Main.h"
using namespace std;
-
-// types
-using dev::bytes;
-using dev::bytesConstRef;
-using dev::h160;
-using dev::h256;
-using dev::u160;
-using dev::u256;
-using dev::Address;
-using dev::eth::BlockInfo;
-using dev::eth::Client;
-using dev::eth::Instruction;
-using dev::KeyPair;
-using dev::eth::NodeMode;
-using dev::eth::BlockChain;
-using dev::p2p::PeerInfo;
-using dev::RLP;
-using dev::Secret;
-using dev::eth::Transaction;
-using dev::eth::Executive;
-
-// functions
-using dev::toHex;
-using dev::fromHex;
-using dev::left160;
-using dev::right160;
-using dev::simpleDebugOut;
-using dev::toLog2;
-using dev::toString;
-using dev::operator<<;
-using dev::eth::units;
-using dev::eth::sha3;
-using dev::eth::compileLLL;
-using dev::eth::disassemble;
-using dev::eth::formatBalance;
-
-// vars
-using dev::g_logPost;
-using dev::g_logVerbosity;
+using namespace dev;
+using namespace dev::p2p;
+using namespace dev::eth;
static void initUnits(QComboBox* _b)
{
@@ -114,7 +81,6 @@ static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr)
return QString();
}
-
Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f");
Main::Main(QWidget *parent) :
@@ -133,26 +99,10 @@ Main::Main(QWidget *parent) :
// ui->log->addItem(QString::fromStdString(s));
};
-#if 0&Ð_DEBUG
- m_servers.append("192.168.0.10:30301");
-#else
- int pocnumber = QString(dev::Version).section('.', 1, 1).toInt();
- if (pocnumber == 5)
- m_servers.push_back("54.72.69.180:30303");
- else if (pocnumber == 6)
- m_servers.push_back("54.76.56.74:30303");
- else
- {
- connect(&m_webCtrl, &QNetworkAccessManager::finished, [&](QNetworkReply* _r)
- {
- m_servers = QString::fromUtf8(_r->readAll()).split("\n", QString::SkipEmptyParts);
- });
- QNetworkRequest r(QUrl("http://www.ethereum.org/servers.poc" + QString::number(pocnumber) + ".txt"));
- r.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.0 Safari/537.36");
- m_webCtrl.get(r);
- srand(time(0));
- }
+#if ETH_DEBUG
+ m_servers.append("localhost:30300");
#endif
+ m_servers.append(QString::fromStdString(Host::pocHost() + ":30303"));
cerr << "State root: " << BlockChain::genesis().stateRoot << endl;
cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl;
@@ -177,12 +127,12 @@ Main::Main(QWidget *parent) :
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved()));
- m_client.reset(new Client("AlethZero"));
+ 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"}));
connect(ui->webView, &QWebView::loadStarted, [this]()
{
// NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it.
- m_ethereum = new QEthereum(this, client(), owned());
+ m_ethereum = new QEthereum(this, ethereum(), owned());
QWebFrame* f = ui->webView->page()->mainFrame();
f->disconnect(SIGNAL(javaScriptWindowObjectCleared()));
@@ -226,6 +176,11 @@ Main::~Main()
writeSettings();
}
+dev::p2p::NetworkPreferences Main::netPrefs() const
+{
+ return NetworkPreferences(ui->port->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), ui->localNetworking->isChecked());
+}
+
void Main::onKeysChanged()
{
installBalancesWatch();
@@ -233,14 +188,14 @@ void Main::onKeysChanged()
unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function const& _f)
{
- auto ret = client()->installWatch(_tf);
+ auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f;
return ret;
}
unsigned Main::installWatch(dev::h256 _tf, std::function const& _f)
{
- auto ret = client()->installWatch(_tf);
+ auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f;
return ret;
}
@@ -255,14 +210,14 @@ void Main::installWatches()
void Main::installNameRegWatch()
{
- client()->uninstallWatch(m_nameRegFilter);
- m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)client()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
+ ethereum()->uninstallWatch(m_nameRegFilter);
+ m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 0)), [=](){ onNameRegChange(); });
}
void Main::installCurrenciesWatch()
{
- client()->uninstallWatch(m_currenciesFilter);
- m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)client()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
+ ethereum()->uninstallWatch(m_currenciesFilter);
+ m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)ethereum()->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); });
}
void Main::installBalancesWatch()
@@ -270,9 +225,9 @@ void Main::installBalancesWatch()
dev::eth::MessageFilter tf;
vector altCoins;
- Address coinsAddr = right160(client()->stateAt(c_config, 1));
- for (unsigned i = 0; i < client()->stateAt(coinsAddr, 0); ++i)
- altCoins.push_back(right160(client()->stateAt(coinsAddr, i + 1)));
+ Address coinsAddr = right160(ethereum()->stateAt(c_config, 1));
+ for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i)
+ altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys)
{
tf.altered(i.address());
@@ -280,7 +235,7 @@ void Main::installBalancesWatch()
tf.altered(c, (u160)i.address());
}
- client()->uninstallWatch(m_balancesFilter);
+ ethereum()->uninstallWatch(m_balancesFilter);
m_balancesFilter = installWatch(tf, [=](){ onBalancesChange(); });
}
@@ -328,7 +283,7 @@ void Main::onNewPending()
void Main::on_forceMining_triggered()
{
- client()->setForceMining(ui->forceMining->isChecked());
+ ethereum()->setForceMining(ui->forceMining->isChecked());
}
void Main::on_enableOptimizer_triggered()
@@ -422,11 +377,11 @@ QString Main::pretty(dev::Address _a) const
{
h256 n;
- if (h160 nameReg = (u160)client()->stateAt(c_config, 0))
- n = client()->stateAt(nameReg, (u160)(_a));
+ if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0))
+ n = ethereum()->stateAt(nameReg, (u160)(_a));
if (!n)
- n = client()->stateAt(m_nameReg, (u160)(_a));
+ n = ethereum()->stateAt(m_nameReg, (u160)(_a));
return fromRaw(n);
}
@@ -452,11 +407,11 @@ Address Main::fromString(QString const& _a) const
memset(n.data() + sn.size(), 0, 32 - sn.size());
if (_a.size())
{
- if (h160 nameReg = (u160)client()->stateAt(c_config, 0))
- if (h256 a = client()->stateAt(nameReg, n))
+ if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0))
+ if (h256 a = ethereum()->stateAt(nameReg, n))
return right160(a);
- if (h256 a = client()->stateAt(m_nameReg, n))
+ if (h256 a = ethereum()->stateAt(m_nameReg, n))
return right160(a);
}
if (_a.size() == 40)
@@ -484,11 +439,11 @@ QString Main::lookup(QString const& _a) const
*/
h256 ret;
- if (h160 dnsReg = (u160)client()->stateAt(c_config, 4, 0))
- ret = client()->stateAt(dnsReg, n);
+ if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, 0))
+ ret = ethereum()->stateAt(dnsReg, n);
/* if (!ret)
- if (h160 nameReg = (u160)m_client->stateAt(c_config, 0, 0))
- ret = m_client->stateAt(nameReg, n2);
+ if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, 0))
+ ret = ethereum()->stateAt(nameReg, n2);
*/
if (ret && !((u256)ret >> 32))
return QString("%1.%2.%3.%4").arg((int)ret[28]).arg((int)ret[29]).arg((int)ret[30]).arg((int)ret[31]);
@@ -506,7 +461,7 @@ void Main::on_about_triggered()
void Main::on_paranoia_triggered()
{
- client()->setParanoia(ui->paranoia->isChecked());
+ ethereum()->setParanoia(ui->paranoia->isChecked());
}
void Main::writeSettings()
@@ -525,6 +480,7 @@ void Main::writeSettings()
s.setValue("upnp", ui->upnp->isChecked());
s.setValue("forceAddress", ui->forceAddress->text());
s.setValue("usePast", ui->usePast->isChecked());
+ s.setValue("localNetworking", ui->localNetworking->isChecked());
s.setValue("forceMining", ui->forceMining->isChecked());
s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("showAll", ui->showAll->isChecked());
@@ -537,7 +493,7 @@ void Main::writeSettings()
s.setValue("privateChain", m_privateChain);
s.setValue("verbosity", ui->verbosity->value());
- bytes d = client()->savePeers();
+ bytes d = m_webThree->savePeers();
if (d.size())
m_peers = QByteArray((char*)d.data(), (int)d.size());
s.setValue("peers", m_peers);
@@ -569,11 +525,12 @@ void Main::readSettings(bool _skipGeometry)
m_myKeys.append(KeyPair(k));
}
}
- client()->setAddress(m_myKeys.back().address());
+ ethereum()->setAddress(m_myKeys.back().address());
m_peers = s.value("peers").toByteArray();
ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->forceAddress->setText(s.value("forceAddress", "").toString());
ui->usePast->setChecked(s.value("usePast", true).toBool());
+ ui->localNetworking->setChecked(s.value("localNetworking", true).toBool());
ui->forceMining->setChecked(s.value("forceMining", false).toBool());
on_forceMining_triggered();
ui->paranoia->setChecked(s.value("paranoia", false).toBool());
@@ -665,17 +622,17 @@ void Main::on_nameReg_textChanged()
void Main::on_preview_triggered()
{
- client()->setDefault(ui->preview->isChecked() ? 0 : -1);
+ ethereum()->setDefault(ui->preview->isChecked() ? 0 : -1);
refreshAll();
}
void Main::refreshMining()
{
- dev::eth::MineProgress p = client()->miningProgress();
- ui->mineStatus->setText(client()->isMining() ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Not mining");
+ dev::eth::MineProgress p = ethereum()->miningProgress();
+ ui->mineStatus->setText(ethereum()->isMining() ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Not mining");
if (!ui->miningView->isVisible())
return;
- list l = client()->miningHistory();
+ list l = ethereum()->miningHistory();
static unsigned lh = 0;
if (p.hashes < lh)
ui->miningView->resetStats();
@@ -694,12 +651,12 @@ void Main::refreshBalances()
ui->ourAccounts->clear();
u256 totalBalance = 0;
map> altCoins;
- Address coinsAddr = right160(client()->stateAt(c_config, 1));
- for (unsigned i = 0; i < client()->stateAt(coinsAddr, 0); ++i)
+ Address coinsAddr = right160(ethereum()->stateAt(c_config, 1));
+ for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i)
{
- auto n = client()->stateAt(coinsAddr, i + 1);
- auto addr = right160(client()->stateAt(coinsAddr, n));
- auto denom = client()->stateAt(coinsAddr, sha3(h256(n).asBytes()));
+ auto n = ethereum()->stateAt(coinsAddr, i + 1);
+ auto addr = right160(ethereum()->stateAt(coinsAddr, n));
+ auto denom = ethereum()->stateAt(coinsAddr, sha3(h256(n).asBytes()));
if (denom == 0)
denom = 1;
// cdebug << n << addr << denom << sha3(h256(n).asBytes());
@@ -707,13 +664,13 @@ void Main::refreshBalances()
}
for (auto i: m_myKeys)
{
- u256 b = client()->balanceAt(i.address());
- (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)client()->countAt(i.address())), ui->ourAccounts))
+ u256 b = ethereum()->balanceAt(i.address());
+ (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)ethereum()->countAt(i.address())), ui->ourAccounts))
->setData(Qt::UserRole, QByteArray((char const*)i.address().data(), Address::size));
totalBalance += b;
for (auto& c: altCoins)
- get<1>(c.second) += (u256)client()->stateAt(c.first, (u160)i.address());
+ get<1>(c.second) += (u256)ethereum()->stateAt(c.first, (u160)i.address());
}
QString b;
@@ -729,12 +686,12 @@ void Main::refreshBalances()
void Main::refreshNetwork()
{
- auto ps = client()->peers();
+ auto ps = web3()->peers();
ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)");
ui->peers->clear();
for (PeerInfo const& i: ps)
- ui->peers->addItem(QString("%3 ms - %1:%2 - %4").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast(i.lastPing).count()).arg(i.clientVersion.c_str()));
+ ui->peers->addItem(QString("%3 ms - %1:%2 - %4 %5").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))));
}
void Main::refreshAll()
@@ -751,7 +708,7 @@ void Main::refreshPending()
{
cwatch << "refreshPending()";
ui->transactionQueue->clear();
- for (Transaction const& t: client()->pending())
+ for (Transaction const& t: ethereum()->pending())
{
QString s = t.receiveAddress ?
QString("%2 %5> %3: %1 [%4]")
@@ -759,7 +716,7 @@ void Main::refreshPending()
.arg(render(t.safeSender()))
.arg(render(t.receiveAddress))
.arg((unsigned)t.nonce)
- .arg(client()->codeAt(t.receiveAddress).size() ? '*' : '-') :
+ .arg(ethereum()->codeAt(t.receiveAddress).size() ? '*' : '-') :
QString("%2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
@@ -775,16 +732,16 @@ void Main::refreshAccounts()
ui->accounts->clear();
ui->contracts->clear();
for (auto n = 0; n < 2; ++n)
- for (auto i: client()->addresses())
+ for (auto i: ethereum()->addresses())
{
auto r = render(i);
if (r.contains('(') == !n)
{
if (n == 0 || ui->showAllAccounts->isChecked())
- (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(client()->balanceAt(i)).c_str()).arg(r).arg((unsigned)client()->countAt(i)), ui->accounts))
+ (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(r).arg((unsigned)ethereum()->countAt(i)), ui->accounts))
->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size));
- if (client()->codeAt(i).size())
- (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(client()->balanceAt(i)).c_str()).arg(r).arg((unsigned)client()->countAt(i)), ui->contracts))
+ if (ethereum()->codeAt(i).size())
+ (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(r).arg((unsigned)ethereum()->countAt(i)), ui->contracts))
->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size));
}
}
@@ -794,7 +751,7 @@ void Main::refreshDestination()
{
cwatch << "refreshDestination()";
QString s;
- for (auto i: client()->addresses())
+ for (auto i: ethereum()->addresses())
if ((s = pretty(i)).size())
// A namereg address
if (ui->destination->findText(s, Qt::MatchExactly | Qt::MatchCaseSensitive) == -1)
@@ -807,8 +764,8 @@ void Main::refreshDestination()
void Main::refreshBlockCount()
{
cwatch << "refreshBlockCount()";
- auto d = client()->blockChain().details();
- auto diff = BlockInfo(client()->blockChain().block()).difficulty;
+ auto d = ethereum()->blockChain().details();
+ auto diff = BlockInfo(ethereum()->blockChain().block()).difficulty;
ui->blockCount->setText(QString("%6 #%1 @%3 T%2 N%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(dev::eth::c_protocolVersion).arg(dev::eth::c_databaseVersion).arg(m_privateChain.size() ? "[" + m_privateChain + "] " : "testnet"));
}
@@ -839,7 +796,7 @@ static bool transactionMatch(string const& _f, Transaction const& _t)
void Main::on_turboMining_triggered()
{
- client()->setTurboMining(ui->turboMining->isChecked());
+ ethereum()->setTurboMining(ui->turboMining->isChecked());
}
void Main::refreshBlockChain()
@@ -850,7 +807,7 @@ void Main::refreshBlockChain()
ui->blocks->clear();
string filter = ui->blockChainFilter->text().toLower().toStdString();
- auto const& bc = client()->blockChain();
+ auto const& bc = ethereum()->blockChain();
unsigned i = (ui->showAll->isChecked() || !filter.empty()) ? (unsigned)-1 : 10;
for (auto h = bc.currentHash(); h != bc.genesisHash() && bc.details(h) && i; h = bc.details(h).parent, --i)
{
@@ -877,7 +834,7 @@ void Main::refreshBlockChain()
.arg(render(t.safeSender()))
.arg(render(t.receiveAddress))
.arg((unsigned)t.nonce)
- .arg(client()->codeAt(t.receiveAddress).size() ? '*' : '-') :
+ .arg(ethereum()->codeAt(t.receiveAddress).size() ? '*' : '-') :
QString(" %2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
@@ -926,6 +883,9 @@ void Main::timerEvent(QTimerEvent*)
if (interval / 100 % 2 == 0)
refreshMining();
+ if (interval / 100 % 2 == 0 && m_webThree->ethereum()->isSyncing())
+ ui->downloadView->update();
+
if (m_logChanged)
{
m_logLock.lock();
@@ -948,7 +908,7 @@ void Main::timerEvent(QTimerEvent*)
m_ethereum->poll();
for (auto const& i: m_handlers)
- if (client()->checkWatch(i.first))
+ if (ethereum()->checkWatch(i.first))
i.second();
}
@@ -1019,9 +979,9 @@ void Main::on_transactionQueue_currentItemChanged()
stringstream s;
int i = ui->transactionQueue->currentRow();
- if (i >= 0 && i < (int)client()->pending().size())
+ if (i >= 0 && i < (int)ethereum()->pending().size())
{
- Transaction tx(client()->pending()[i]);
+ Transaction tx(ethereum()->pending()[i]);
auto ss = tx.safeSender();
h256 th = sha3(rlpList(ss, tx.nonce));
s << "" << th << "
";
@@ -1049,7 +1009,7 @@ void Main::on_transactionQueue_currentItemChanged()
// s << "Pre: " << fs.rootHash() << "
";
// s << "Post: " << ts.rootHash() << "";
- s << renderDiff(client()->diff(i, 0));
+ s << renderDiff(ethereum()->diff(i, 0));
}
ui->pendingInfo->setHtml(QString::fromStdString(s.str()));
@@ -1076,7 +1036,7 @@ void Main::on_inject_triggered()
{
QString s = QInputDialog::getText(this, "Inject Transaction", "Enter transaction dump in hex");
bytes b = fromHex(s.toStdString());
- client()->inject(&b);
+ ethereum()->inject(&b);
}
void Main::on_blocks_currentItemChanged()
@@ -1090,8 +1050,8 @@ void Main::on_blocks_currentItemChanged()
auto hba = item->data(Qt::UserRole).toByteArray();
assert(hba.size() == 32);
auto h = h256((byte const*)hba.data(), h256::ConstructFromPointer);
- auto details = client()->blockChain().details(h);
- auto blockData = client()->blockChain().block(h);
+ auto details = ethereum()->blockChain().details(h);
+ auto blockData = ethereum()->blockChain().block(h);
auto block = RLP(blockData);
BlockInfo info(blockData);
@@ -1115,7 +1075,7 @@ void Main::on_blocks_currentItemChanged()
s << "
Bloom: " << details.bloom << "";
s << "
Transactions: " << block[1].itemCount() << " @" << info.transactionsRoot << "";
s << "
Uncles: " << block[2].itemCount() << " @" << info.sha3Uncles << "";
- s << "
Pre: " << BlockInfo(client()->blockChain().block(info.parentHash)).stateRoot << "";
+ s << "
Pre: " << BlockInfo(ethereum()->blockChain().block(info.parentHash)).stateRoot << "";
for (auto const& i: block[1])
s << "
" << sha3(i[0].data()).abridged() << ": " << i[1].toHash() << " [" << i[2].toInt() << " used]";
s << "
Post: " << info.stateRoot << "";
@@ -1151,7 +1111,7 @@ void Main::on_blocks_currentItemChanged()
if (tx.data.size())
s << dev::memDump(tx.data, 16, true);
}
- s << renderDiff(client()->diff(txi, h));
+ s << renderDiff(ethereum()->diff(txi, h));
ui->debugCurrent->setEnabled(true);
ui->debugDumpState->setEnabled(true);
ui->debugDumpStatePre->setEnabled(true);
@@ -1173,7 +1133,7 @@ void Main::on_debugCurrent_triggered()
if (!item->data(Qt::UserRole + 1).isNull())
{
unsigned txi = item->data(Qt::UserRole + 1).toInt();
- m_executiveState = client()->state(txi + 1, h);
+ m_executiveState = ethereum()->state(txi + 1, h);
m_currentExecution = unique_ptr(new Executive(m_executiveState));
Transaction t = m_executiveState.pending()[txi];
m_executiveState = m_executiveState.fromPending(txi);
@@ -1199,7 +1159,7 @@ void Main::on_debugDumpState_triggered(int _add)
if (f.is_open())
{
unsigned txi = item->data(Qt::UserRole + 1).toInt();
- f << client()->state(txi + _add, h) << endl;
+ f << ethereum()->state(txi + _add, h) << endl;
}
}
}
@@ -1265,10 +1225,10 @@ void Main::on_contracts_currentItemChanged()
stringstream s;
try
{
- auto storage = client()->storageAt(address);
+ auto storage = ethereum()->storageAt(address);
for (auto const& i: storage)
s << "@" << showbase << hex << prettyU256(i.first).toStdString() << " " << showbase << hex << prettyU256(i.second).toStdString() << "
";
- s << "Body Code
" << disassemble(client()->codeAt(address));
+ s << "Body Code
" << disassemble(ethereum()->codeAt(address));
ui->contractInfo->appendHtml(QString::fromStdString(s.str()));
}
catch (dev::eth::InvalidTrie)
@@ -1281,7 +1241,7 @@ void Main::on_contracts_currentItemChanged()
void Main::on_idealPeers_valueChanged()
{
- client()->setIdealPeerCount(ui->idealPeers->value());
+ m_webThree->setIdealPeerCount(ui->idealPeers->value());
}
void Main::on_ourAccounts_doubleClicked()
@@ -1427,7 +1387,7 @@ void Main::on_data_textChanged()
s = s.mid(1);
}
ui->code->setHtml(QString::fromStdString(dev::memDump(m_data, 8, true)));
- if (client()->codeAt(fromString(ui->destination->currentText()), 0).size())
+ if (ethereum()->codeAt(fromString(ui->destination->currentText()), 0).size())
{
ui->gas->setMinimum((qint64)Client::txGas(m_data.size(), 1));
if (!ui->gas->isEnabled())
@@ -1450,9 +1410,9 @@ void Main::on_killBlockchain_triggered()
writeSettings();
ui->mine->setChecked(false);
ui->net->setChecked(false);
- m_client.reset();
- m_client.reset(new Client("AlethZero", Address(), string(), true));
- m_ethereum->setClient(client());
+ web3()->stopNetwork();
+ ethereum()->killChain();
+ m_ethereum->setClient(ethereum());
readSettings(true);
installWatches();
refreshAll();
@@ -1495,7 +1455,7 @@ void Main::updateFee()
bool ok = false;
for (auto i: m_myKeys)
- if (client()->balanceAt(i.address()) >= totalReq)
+ if (ethereum()->balanceAt(i.address()) >= totalReq)
{
ok = true;
break;
@@ -1514,15 +1474,24 @@ void Main::on_net_triggered()
if (ui->clientName->text().size())
n += "/" + ui->clientName->text().toStdString();
n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM);
- client()->setClientVersion(n);
+ web3()->setClientVersion(n);
if (ui->net->isChecked())
{
- client()->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0);
+ // TODO: alter network stuff?
+ //ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0
+ web3()->setIdealPeerCount(ui->idealPeers->value());
+ web3()->setNetworkPreferences(netPrefs());
+ ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0);
+ web3()->startNetwork();
+ ui->downloadView->setDownloadMan(ethereum()->downloadMan());
if (m_peers.size() && ui->usePast->isChecked())
- client()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
+ web3()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
}
else
- client()->stopNetwork();
+ {
+ ui->downloadView->setDownloadMan(nullptr);
+ web3()->stopNetwork();
+ }
}
void Main::on_connect_triggered()
@@ -1538,7 +1507,7 @@ void Main::on_connect_triggered()
{
string host = s.section(":", 0, 0).toStdString();
unsigned short port = s.section(":", 1).toInt();
- client()->connect(host, port);
+ web3()->connect(host, port);
}
}
@@ -1552,25 +1521,25 @@ void Main::on_mine_triggered()
{
if (ui->mine->isChecked())
{
- client()->setAddress(m_myKeys.last().address());
- client()->startMining();
+ ethereum()->setAddress(m_myKeys.last().address());
+ ethereum()->startMining();
}
else
- client()->stopMining();
+ ethereum()->stopMining();
}
void Main::on_send_clicked()
{
u256 totalReq = value() + fee();
for (auto i: m_myKeys)
- if (client()->balanceAt(i.address(), 0) >= totalReq)
+ if (ethereum()->balanceAt(i.address(), 0) >= totalReq)
{
debugFinished();
Secret s = i.secret();
if (isCreation())
- client()->transact(s, value(), m_data, ui->gas->value(), gasPrice());
+ ethereum()->transact(s, value(), m_data, ui->gas->value(), gasPrice());
else
- client()->transact(s, value(), fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice());
+ ethereum()->transact(s, value(), fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice());
return;
}
statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount.");
@@ -1583,10 +1552,10 @@ void Main::on_debug_clicked()
{
u256 totalReq = value() + fee();
for (auto i: m_myKeys)
- if (client()->balanceAt(i.address()) >= totalReq)
+ if (ethereum()->balanceAt(i.address()) >= totalReq)
{
Secret s = i.secret();
- m_executiveState = client()->postState();
+ m_executiveState = ethereum()->postState();
m_currentExecution = unique_ptr(new Executive(m_executiveState));
Transaction t;
t.nonce = m_executiveState.transactionsFrom(dev::toAddress(s));
@@ -1937,4 +1906,7 @@ void Main::updateDebugger()
#include\
"moc_MiningView.cpp"
+#include\
+"moc_DownloadView.cpp"
+
#endif
diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h
index a3bfa718d..ce1a9b670 100644
--- a/alethzero/MainWin.h
+++ b/alethzero/MainWin.h
@@ -31,6 +31,7 @@
#include
#include
#include
+#include
namespace Ui {
class Main;
@@ -69,7 +70,9 @@ public:
explicit Main(QWidget *parent = 0);
~Main();
- dev::eth::Client* client() const { return m_client.get(); }
+ dev::WebThreeDirect* web3() const { return m_webThree.get(); }
+ dev::eth::Client* ethereum() const { return m_webThree->ethereum(); }
+ dev::shh::WhisperHost* whisper() const { return m_webThree->whisper(); }
QList const& owned() const { return m_myKeys; }
@@ -146,6 +149,8 @@ signals:
void poll();
private:
+ dev::p2p::NetworkPreferences netPrefs() const;
+
QString pretty(dev::Address _a) const;
QString prettyU256(dev::u256 _n) const;
@@ -200,7 +205,7 @@ private:
std::unique_ptr ui;
- std::unique_ptr m_client;
+ std::unique_ptr m_webThree;
std::map> m_handlers;
unsigned m_nameRegFilter = (unsigned)-1;
diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt
index 93946aa8f..eee1d258b 100644
--- a/eth/CMakeLists.txt
+++ b/eth/CMakeLists.txt
@@ -4,13 +4,13 @@ aux_source_directory(. SRC_LIST)
include_directories(..)
link_directories(../libethcore)
-link_directories(../libethereum)
+link_directories(../libwebthree)
set(EXECUTABLE eth)
add_executable(${EXECUTABLE} ${SRC_LIST})
-target_link_libraries(${EXECUTABLE} ethereum)
+target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} secp256k1)
target_link_libraries(${EXECUTABLE} gmp)
if(MINIUPNPC_LS)
diff --git a/eth/EthStubServer.cpp b/eth/EthStubServer.cpp
index 86bb1ba58..ad6a87781 100644
--- a/eth/EthStubServer.cpp
+++ b/eth/EthStubServer.cpp
@@ -25,14 +25,15 @@
#include
#include
#include
+#include
#include "CommonJS.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
-EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, Client& _client):
+EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3):
AbstractEthStubServer(_conn),
- m_client(_client)
+ m_web3(_web3)
{
}
@@ -59,20 +60,25 @@ Json::Value EthStubServer::procedures()
return ret;
}
+dev::eth::Client& EthStubServer::ethereum() const
+{
+ return *m_web3.ethereum();
+}
+
std::string EthStubServer::coinbase()
{
- return toJS(m_client.address());
+ return toJS(ethereum().address());
}
std::string EthStubServer::balanceAt(std::string const& _a)
{
- return toJS(m_client.balanceAt(jsToAddress(_a), 0));
+ return toJS(ethereum().balanceAt(jsToAddress(_a), 0));
}
Json::Value EthStubServer::check(Json::Value const& _as)
{
// TODO
-// if (m_client.changed())
+// if (ethereum().changed())
return _as;
/* else
{
@@ -84,7 +90,7 @@ Json::Value EthStubServer::check(Json::Value const& _as)
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 = m_client.transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
+ Address ret = ethereum().transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
return toJS(ret);
}
@@ -100,17 +106,17 @@ std::string EthStubServer::gasPrice()
bool EthStubServer::isContractAt(const std::string& _a)
{
- return m_client.codeAt(jsToAddress(_a), 0).size();
+ return ethereum().codeAt(jsToAddress(_a), 0).size();
}
bool EthStubServer::isListening()
{
- return m_client.haveNetwork();
+ return m_web3.haveNetwork();
}
bool EthStubServer::isMining()
{
- return m_client.isMining();
+ return ethereum().isMining();
}
std::string EthStubServer::key()
@@ -130,23 +136,28 @@ Json::Value EthStubServer::keys()
int EthStubServer::peerCount()
{
- return m_client.peerCount();
+ return m_web3.peerCount();
}
std::string EthStubServer::storageAt(const std::string& _a, const std::string& x)
{
- return toJS(m_client.stateAt(jsToAddress(_a), jsToU256(x), 0));
+ 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)
{
- m_client.transact(jsToSecret(_sec), jsToU256(_xValue), jsToAddress(_aDest), jsToBytes(_bData), jsToU256(_xGas), jsToU256(_xGasPrice));
+ 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(m_client.countAt(jsToAddress(_a), 0));
+ return toJS(ethereum().countAt(jsToAddress(_a), 0));
}
std::string EthStubServer::secretToAddress(const std::string& _a)
@@ -167,7 +178,7 @@ Json::Value EthStubServer::block(const std::string& _hash)
Json::Value EthStubServer::blockJson(const std::string& _hash)
{
Json::Value res;
- auto const& bc = m_client.blockChain();
+ auto const& bc = ethereum().blockChain();
auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block();
diff --git a/eth/EthStubServer.h b/eth/EthStubServer.h
index 28af916a2..469abed07 100644
--- a/eth/EthStubServer.h
+++ b/eth/EthStubServer.h
@@ -29,12 +29,12 @@
#include "abstractethstubserver.h"
#pragma GCC diagnostic pop
-namespace dev { namespace eth { class Client; } class KeyPair; }
+namespace dev { class WebThreeDirect; namespace eth { class Client; } class KeyPair; }
class EthStubServer: public AbstractEthStubServer
{
public:
- EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::eth::Client& _client);
+ EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual Json::Value procedures();
virtual std::string balanceAt(std::string const& _a);
@@ -49,6 +49,7 @@ public:
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);
@@ -57,7 +58,8 @@ public:
virtual Json::Value block(const std::string&);
void setKeys(std::vector _keys) { m_keys = _keys; }
private:
- dev::eth::Client& m_client;
+ 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
index 940e4c809..7f110513d 100644
--- a/eth/abstractethstubserver.h
+++ b/eth/abstractethstubserver.h
@@ -30,6 +30,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerbindAndAddMethod(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);
@@ -120,6 +121,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerstorageAt(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());
@@ -148,6 +154,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer
#include
#include
+#include
#if ETH_READLINE
#include
#include
@@ -43,6 +44,7 @@
#include "BuildInfo.h"
using namespace std;
using namespace dev;
+using namespace dev::p2p;
using namespace dev::eth;
using namespace boost::algorithm;
using dev::eth::Instruction;
@@ -97,6 +99,7 @@ void help()
<< "Usage eth [OPTIONS] " << endl
<< "Options:" << endl
<< " -a,--address Set the coinbase (mining payout) address to addr (default: auto)." << endl
+ << " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
<< " -c,--client-name Add a name to your client's version string (default: blank)." << endl
<< " -d,--db-path Load database from path (default: ~/.ethereum " << endl
<< " /Etherum or Library/Application Support/Ethereum)." << endl
@@ -110,7 +113,8 @@ void help()
<< " -l,--listen Listen on the given port for incoming connected (default: 30303)." << endl
<< " -m,--mining Enable mining, optionally for a specified number of blocks (Default: off)" << endl
<< " -n,--upnp Use upnp for NAT (default: on)." << endl
- << " -o,--mode Start a full node or a peer node (Default: full)." << endl
+ << " -L,--local-networking Use peers whose addresses are local." << endl
+ << " -o,--mode Start a full node or a peer node (Default: full)." << endl
<< " -p,--port Connect to remote port (default: 30303)." << endl
<< " -r,--remote Connect to remote host (default: none)." << endl
<< " -s,--secret Set the secret key for use with send command (default: auto)." << endl
@@ -131,17 +135,8 @@ string credits(bool _interactive = false)
if (_interactive)
{
- string vs = toString(dev::Version);
- vs = vs.substr(vs.find_first_of('.') + 1)[0];
- int pocnumber = stoi(vs);
- string m_servers;
- if (pocnumber == 4)
- m_servers = "54.72.31.55";
- else
- m_servers = "54.72.69.180";
-
cout << "Type 'netstart 30303' to start networking" << endl;
- cout << "Type 'connect " << m_servers << " 30303' to connect" << endl;
+ cout << "Type 'connect " << Host::pocHost() << " 30303' to connect" << endl;
cout << "Type 'exit' to quit" << endl << endl;
}
return cout.str();
@@ -182,10 +177,12 @@ int main(int argc, char** argv)
unsigned peers = 5;
bool interactive = false;
#if ETH_JSONRPC
- int jsonrpc = 8080;
+ int jsonrpc = -1;
#endif
string publicIP;
+ bool bootstrap = false;
bool upnp = true;
+ bool useLocal = false;
bool forceMining = false;
string clientName;
@@ -231,10 +228,12 @@ int main(int argc, char** argv)
upnp = false;
else
{
- cerr << "Invalid UPnP option: " << m << endl;
+ cerr << "Invalid -n/--upnp option: " << m << endl;
return -1;
}
}
+ else if (arg == "-L" || arg == "--local-networking")
+ useLocal = true;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
@@ -254,17 +253,19 @@ int main(int argc, char** argv)
mining = i;
else
{
- cerr << "Unknown mining option: " << m << endl;
+ cerr << "Unknown -m/--mining option: " << m << endl;
return -1;
}
}
+ else if (arg == "-b" || arg == "--bootstrap")
+ bootstrap = true;
else if (arg == "-f" || arg == "--force-mining")
forceMining = true;
else if (arg == "-i" || arg == "--interactive")
interactive = true;
#if ETH_JSONRPC
else if ((arg == "-j" || arg == "--json-rpc"))
- jsonrpc = jsonrpc ? jsonrpc : 8080;
+ jsonrpc = jsonrpc == -1 ? 8080 : jsonrpc;
else if (arg == "--json-rpc-port" && i + 1 < argc)
jsonrpc = atoi(argv[++i]);
#endif
@@ -296,22 +297,32 @@ int main(int argc, char** argv)
if (!clientName.empty())
clientName += "/";
- Client c("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath);
-
- c.setForceMining(true);
-
cout << credits();
- c.setForceMining(forceMining);
+ NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
+ dev::WebThreeDirect web3("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), dbPath, false, mode == NodeMode::Full ? set{"eth", "shh"} : set{}, netPrefs);
+ web3.setIdealPeerCount(peers);
+ eth::Client* c = mode == NodeMode::Full ? web3.ethereum() : nullptr;
+
+ if (c)
+ {
+ c->setForceMining(forceMining);
+ c->setAddress(coinbase);
+ }
cout << "Address: " << endl << toHex(us.address().asArray()) << endl;
- c.startNetwork(listenPort, remoteHost, remotePort, mode, peers, publicIP, upnp);
+ web3.startNetwork();
+
+ if (bootstrap)
+ web3.connect(Host::pocHost());
+ if (remoteHost.size())
+ web3.connect(remoteHost, remotePort);
#if ETH_JSONRPC
auto_ptr jsonrpcServer;
if (jsonrpc > -1)
{
- jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), c));
+ jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@@ -349,34 +360,34 @@ int main(int argc, char** argv)
iss >> cmd;
if (cmd == "netstart")
{
- unsigned port;
- iss >> port;
- c.startNetwork((short)port);
+ iss >> netPrefs.listenPort;
+ web3.setNetworkPreferences(netPrefs);
+ web3.startNetwork();
}
else if (cmd == "connect")
{
string addr;
unsigned port;
iss >> addr >> port;
- c.connect(addr, (short)port);
+ web3.connect(addr, (short)port);
}
else if (cmd == "netstop")
{
- c.stopNetwork();
+ web3.stopNetwork();
}
- else if (cmd == "minestart")
+ else if (c && cmd == "minestart")
{
- c.startMining();
+ c->startMining();
}
- else if (cmd == "minestop")
+ else if (c && cmd == "minestop")
{
- c.stopMining();
+ c->stopMining();
}
- else if (cmd == "mineforce")
+ else if (c && cmd == "mineforce")
{
string enable;
iss >> enable;
- c.setForceMining(isTrue(enable));
+ c->setForceMining(isTrue(enable));
}
else if (cmd == "verbosity")
{
@@ -395,7 +406,7 @@ int main(int argc, char** argv)
{
if (jsonrpc < 0)
jsonrpc = 8080;
- jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), c));
+ jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@@ -416,24 +427,24 @@ int main(int argc, char** argv)
{
cout << "Secret Key: " << toHex(us.secret().asArray()) << endl;
}
- else if (cmd == "block")
+ else if (c && cmd == "block")
{
- cout << "Current block: " << c.blockChain().details().number << endl;
+ cout << "Current block: " <blockChain().details().number << endl;
}
else if (cmd == "peers")
{
- for (auto it: c.peers())
+ for (auto it: web3.peers())
cout << it.host << ":" << it.port << ", " << it.clientVersion << ", "
<< std::chrono::duration_cast(it.lastPing).count() << "ms"
<< endl;
}
- else if (cmd == "balance")
+ else if (c && cmd == "balance")
{
- cout << "Current balance: " << formatBalance(c.balanceAt(us.address())) << " = " << c.balanceAt(us.address()) << " wei" << endl;
+ cout << "Current balance: " << formatBalance( c->balanceAt(us.address())) << " = " <balanceAt(us.address()) << " wei" << endl;
}
- else if (cmd == "transact")
+ else if (c && cmd == "transact")
{
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
@@ -478,35 +489,35 @@ int main(int argc, char** argv)
{
Secret secret = h256(fromHex(sechex));
Address dest = h160(fromHex(hexAddr));
- c.transact(secret, amount, dest, data, gas, gasPrice);
+ c->transact(secret, amount, dest, data, gas, gasPrice);
}
}
else
cwarn << "Require parameters: transact ADDRESS AMOUNT GASPRICE GAS SECRET DATA";
}
- else if (cmd == "listContracts")
+ else if (c && cmd == "listContracts")
{
- auto acs = c.addresses();
+ auto acs =c->addresses();
string ss;
for (auto const& i: acs)
- if (c.codeAt(i, 0).size())
+ if ( c->codeAt(i, 0).size())
{
- ss = toString(i) + " : " + toString(c.balanceAt(i)) + " [" + toString((unsigned)c.countAt(i)) + "]";
+ ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl;
}
}
- else if (cmd == "listAccounts")
+ else if (c && cmd == "listAccounts")
{
- auto acs = c.addresses();
+ auto acs =c->addresses();
string ss;
for (auto const& i: acs)
- if (c.codeAt(i, 0).empty())
+ if ( c->codeAt(i, 0).empty())
{
- ss = toString(i) + " : " + toString(c.balanceAt(i)) + " [" + toString((unsigned)c.countAt(i)) + "]";
+ ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl;
}
}
- else if (cmd == "send")
+ else if (c && cmd == "send")
{
if (iss.peek() != -1)
{
@@ -522,21 +533,21 @@ int main(int argc, char** argv)
}
else
{
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
u256 minGas = (u256)Client::txGas(0, 0);
Address dest = h160(fromHex(hexAddr));
- c.transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice);
+ c->transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice);
}
}
else
cwarn << "Require parameters: send ADDRESS AMOUNT";
}
- else if (cmd == "contract")
+ else if (c && cmd == "contract")
{
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
@@ -573,12 +584,12 @@ int main(int argc, char** argv)
else if (gas < minGas)
cwarn << "Minimum gas amount is" << minGas;
else
- c.transact(us.secret(), endowment, init, gas, gasPrice);
+ c->transact(us.secret(), endowment, init, gas, gasPrice);
}
else
cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX";
}
- else if (cmd == "dumptrace")
+ else if (c && cmd == "dumptrace")
{
unsigned block;
unsigned index;
@@ -588,7 +599,7 @@ int main(int argc, char** argv)
ofstream f;
f.open(filename);
- dev::eth::State state = c.state(index + 1, c.blockChain().numberHash(block));
+ dev::eth::State state =c->state(index + 1,c->blockChain().numberHash(block));
if (index < state.pending().size())
{
Executive e(state);
@@ -633,7 +644,7 @@ int main(int argc, char** argv)
e.finalize(oof);
}
}
- else if (cmd == "inspect")
+ else if (c && cmd == "inspect")
{
string rechex;
iss >> rechex;
@@ -647,10 +658,10 @@ int main(int argc, char** argv)
try
{
- auto storage = c.storageAt(h, 0);
+ auto storage =c->storageAt(h, 0);
for (auto const& i: storage)
s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl;
- s << endl << disassemble(c.codeAt(h, 0)) << endl;
+ s << endl << disassemble( c->codeAt(h, 0)) << endl;
string outFile = getDataDir() + "/" + rechex + ".evm";
ofstream ofs;
@@ -735,19 +746,21 @@ int main(int argc, char** argv)
jsonrpcServer->StopListening();
#endif
}
- else
+ else if (c)
{
- unsigned n = c.blockChain().details().number;
+ unsigned n =c->blockChain().details().number;
if (mining)
- c.startMining();
+ c->startMining();
while (true)
{
- if (c.blockChain().details().number - n == mining)
- c.stopMining();
+ if ( c->isMining() &&c->blockChain().details().number - n == mining)
+ c->stopMining();
this_thread::sleep_for(chrono::milliseconds(100));
}
}
-
+ else
+ while (true)
+ this_thread::sleep_for(chrono::milliseconds(1000));
return 0;
}
diff --git a/exp/main.cpp b/exp/main.cpp
index c49b13e44..1f29ab207 100644
--- a/exp/main.cpp
+++ b/exp/main.cpp
@@ -19,290 +19,59 @@
* @date 2014
* Ethereum client.
*/
-#if 0
-#define BOOST_RESULT_OF_USE_DECLTYPE
-#define BOOST_SPIRIT_USE_PHOENIX_V3
-#include
-#include
-#include
-#endif
+#include
#include
#include
#include
#include
#include
+#include
+#include
#include
-#if 0
-#include
-#include "BuildInfo.h"
-#endif
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace dev::p2p;
using namespace dev::shh;
-#if 0
-#if 0
-namespace qi = boost::spirit::qi;
-namespace px = boost::phoenix;
-namespace sp = boost::spirit;
-
-class ASTSymbol: public string
-{
-public:
- ASTSymbol() {}
-};
-
-enum class ASTType
-{
- Symbol,
- IntegerLiteral,
- StringLiteral,
- Call,
- Return,
- Operator,
- Compound
-};
-
-class ASTNode: public vector
-{
-public:
- ASTNode() {}
- ASTNode(ASTSymbol const& _s): m_type(ASTType::Symbol), m_s(_s) {}
- ASTNode(string const& _s): m_type(ASTType::StringLiteral), m_s(_s) {}
- ASTNode(bigint const& _i): m_type(ASTType::IntegerLiteral), m_i(_i) {}
- ASTNode(ASTType _t): m_type(_t) {}
-
- ASTNode& operator=(ASTSymbol const& _s) { m_type = ASTType::Symbol; m_s = _s; return *this; }
- ASTNode& operator=(string const& _s) { m_type = ASTType::StringLiteral; m_s = _s; return *this; }
- ASTNode& operator=(bigint const& _i) { m_type = ASTType::IntegerLiteral; m_i = _i; return *this; }
- ASTNode& operator=(ASTType const& _s) { m_type = _s; return *this; }
-
- void debugOut(ostream& _out) const;
-
-private:
- ASTType m_type;
- string m_s;
- bigint m_i;
-};
-
-void parseTree(string const& _s, ASTNode& o_out)
-{
- using qi::standard::space;
- using qi::standard::space_type;
- typedef string::const_iterator it;
-
-/* static const u256 ether = u256(1000000000) * 1000000000;
- static const u256 finney = u256(1000000000) * 1000000;
- static const u256 szabo = u256(1000000000) * 1000;*/
-
- qi::rule element;
- qi::rule call;
- qi::rule str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
- qi::rule symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
-/* qi::rule strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
- qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
- qi::rule integer = intstr;
- qi::rule multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
- qi::rule quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
- qi::rule atom = quantity[qi::_val = px::construct(px::new_(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
- qi::rule seq = '{' > *element > '}';
- qi::rule mload = '@' > element;
- qi::rule sload = qi::lit("@@") > element;
- qi::rule mstore = '[' > element > ']' > -qi::lit(":") > element;
- qi::rule sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
- qi::rule calldataload = qi::lit("$") > element;
- qi::rule list = '(' > *element > ')';
-
- qi::rule extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | seq[tagNode<5>()] | calldataload[tagNode<6>()];*/
- qi::rule value = call[qi::_val = ASTType::Call] | str[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
- qi::rule compound = '{' > *element > '}';
- call = '(' > *value > ')'; //symbol > '(' > !(value > *(',' > value)) > ')';
- element = compound[qi::_val = ASTType::Compound] | value[qi::_val = qi::_1];
-
- auto ret = _s.cbegin();
- qi::phrase_parse(ret, _s.cend(), element, space, qi::skip_flag::dont_postskip, o_out);
- for (auto i = ret; i != _s.cend(); ++i)
- if (!isspace(*i))
- throw std::exception();
-}
-
-void ASTNode::debugOut(ostream& _out) const
-{
- switch (m_type)
- {
- case ASTType::StringLiteral:
- _out << "\"" << m_s << "\"";
- break;
- case ASTType::Symbol:
- _out << m_s;
- break;
- case ASTType::Compound:
- {
- unsigned n = 0;
- _out << "{";
- for (auto const& i: *this)
- {
- i.debugOut(_out);
- _out << ";";
- ++n;
- }
- _out << "}";
- break;
- }
- case ASTType::Call:
- {
- unsigned n = 0;
- for (auto const& i: *this)
- {
- i.debugOut(_out);
- if (n == 0)
- _out << "(";
- else if (n < size() - 1)
- _out << ",";
- if (n == size() - 1)
- _out << ")";
- ++n;
- }
- break;
- }
- default:
- _out << "nil";
- }
-}
-
-int main(int, char**)
+int main()
{
- ASTNode out;
- parseTree("{x}", out);
- out.debugOut(cout);
- cout << endl;
+ DownloadMan man;
+ DownloadSub s0(man);
+ DownloadSub s1(man);
+ DownloadSub s2(man);
+ man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)}));
+ cnote << s0.nextFetch(2);
+ cnote << s1.nextFetch(2);
+ cnote << s2.nextFetch(2);
+ s0.noteBlock(u256(0));
+ s0.doneFetch();
+ cnote << s0.nextFetch(2);
+ s1.noteBlock(u256(2));
+ s1.noteBlock(u256(3));
+ s1.doneFetch();
+ cnote << s1.nextFetch(2);
+ s0.doneFetch();
+ cnote << s0.nextFetch(2);
+
+/* RangeMask m(0, 100);
+ cnote << m;
+ m += UnsignedRange(3, 10);
+ cnote << m;
+ m += UnsignedRange(11, 16);
+ cnote << m;
+ m += UnsignedRange(10, 11);
+ cnote << m;
+ cnote << ~m;
+ cnote << (~m).lowest(10);
+ for (auto i: (~m).lowest(10))
+ cnote << i;*/
return 0;
}
-#endif
-void killBigints(sp::utree const& _this)
-{
- switch (_this.which())
- {
- case sp::utree_type::list_type: for (auto const& i: _this) killBigints(i); break;
- case sp::utree_type::any_type: delete _this.get(); break;
- default:;
- }
-}
-
-void debugOutAST(ostream& _out, sp::utree const& _this)
-{
- switch (_this.which())
- {
- case sp::utree_type::list_type:
- switch (_this.tag())
- {
- case 0: { int n = 0; for (auto const& i: _this) { debugOutAST(_out, i); if (n++) _out << ", "; } break; }
- case 1: _out << "@ "; debugOutAST(_out, _this.front()); break;
- case 2: _out << "@@ "; debugOutAST(_out, _this.front()); break;
- case 3: _out << "[ "; debugOutAST(_out, _this.front()); _out << " ] "; debugOutAST(_out, _this.back()); break;
- case 4: _out << "[[ "; debugOutAST(_out, _this.front()); _out << " ]] "; debugOutAST(_out, _this.back()); break;
- case 5: _out << "{ "; for (auto const& i: _this) { debugOutAST(_out, i); _out << " "; } _out << "}"; break;
- case 6: _out << "$ "; debugOutAST(_out, _this.front()); break;
- default:
- { _out << _this.tag() << ": "; int n = 0; for (auto const& i: _this) { debugOutAST(_out, i); if (n++) _out << ", "; } break; }
- }
-
- break;
- case sp::utree_type::int_type: _out << _this.get(); break;
- case sp::utree_type::string_type: _out << "\"" << _this.get, sp::utree_type::string_type>>() << "\""; break;
- case sp::utree_type::symbol_type: _out << _this.get, sp::utree_type::symbol_type>>(); break;
- case sp::utree_type::any_type: _out << *_this.get(); break;
- default: _out << "nil";
- }
-}
-
-namespace dev {
-namespace eth {
-namespace parseTreeLLL_ {
-
-template
-struct tagNode
-{
- void operator()(sp::utree& n, qi::rule::context_type& c) const
- {
- (boost::fusion::at_c<0>(c.attributes) = n).tag(N);
- }
-};
-
-}}}
-
-void parseTree(string const& _s, sp::utree& o_out)
-{
- using qi::standard::space;
- using qi::standard::space_type;
- using dev::eth::parseTreeLLL_::tagNode;
- typedef sp::basic_string symbol_type;
- typedef string::const_iterator it;
-
- static const u256 ether = u256(1000000000) * 1000000000;
- static const u256 finney = u256(1000000000) * 1000000;
- static const u256 szabo = u256(1000000000) * 1000;
-#if 0
- qi::rule element;
- qi::rule statement;
- qi::rule str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"';
- qi::rule strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))];
- qi::rule symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
- qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
- qi::rule integer = intstr;
- qi::rule multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether];
- qi::rule quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1];
- qi::rule atom = quantity[qi::_val = px::construct(px::new_(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1];
- qi::rule compound = '{' > *statement > '}';
-/* qi::rule mload = '@' > element;
- qi::rule sload = qi::lit("@@") > element;
- qi::rule mstore = '[' > element > ']' > -qi::lit(":") > element;
- qi::rule sstore = qi::lit("[[") > element > qi::lit("]]") > -qi::lit(":") > element;
- qi::rule calldataload = qi::lit("$") > element;*/
-// qi::rule args = '(' > (element % ',') > ')';
-
- qi::rule expression;
- qi::rule group = '(' >> expression[qi::_val = qi::_1] >> ')';
- qi::rule factor = atom | group;
- qi::rule mul = '*' >> factor;
- qi::rule div = '/' >> factor;
- qi::rule op = mul[tagNode<10>()] | div[tagNode<11>()];
- qi::rule term = factor >> !op;
- expression = term >> !(('+' >> term) | ('-' >> term));
-
- // qi::rule extra = sload[tagNode<2>()] | mload[tagNode<1>()] | sstore[tagNode<4>()] | mstore[tagNode<3>()] | calldataload[tagNode<6>()];
- statement = compound[tagNode<5>()] | (element > ';')[qi::_val = qi::_1];
- element %= expression;// | extra;
-#endif
- qi::rule symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))];
- qi::rule intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]];
- qi::rule integer = intstr;
- qi::rule intnode = integer[qi::_val = px::construct(px::new_(qi::_1))];
- qi::rule funcname = symbol;
- qi::rule statement;
- qi::rule call = funcname > '(' > funcname > ')';
- statement = call | intnode | symbol;
-
- auto ret = _s.cbegin();
- qi::phrase_parse(ret, _s.cend(), statement, space, qi::skip_flag::dont_postskip, o_out);
- for (auto i = ret; i != _s.cend(); ++i)
- if (!isspace(*i))
- throw std::exception();
-}
-#endif
+/*
int main(int argc, char** argv)
{
-#if 0
- sp::utree out;
- parseTree("x(2)", out);
- debugOutAST(cout, out);
- killBigints(out);
- cout << endl;
-#endif
-
g_logVerbosity = 20;
short listenPort = 30303;
@@ -322,24 +91,25 @@ int main(int argc, char** argv)
remoteHost = argv[i];
}
- Host ph("Test", listenPort, "", false, true);
+ Host ph("Test", NetworkPreferences(listenPort, "", false, true));
ph.registerCapability(new WhisperHost());
auto wh = ph.cap();
+ ph.start();
+
if (!remoteHost.empty())
ph.connect(remoteHost, remotePort);
/// Only interested in the packet if the lowest bit is 1
auto w = wh->installWatch(MessageFilter(std::vector >({{fromHex("0000000000000000000000000000000000000000000000000000000000000001"), fromHex("0000000000000000000000000000000000000000000000000000000000000001")}})));
+
for (int i = 0; ; ++i)
{
- this_thread::sleep_for(chrono::milliseconds(1000));
- ph.process();
wh->sendRaw(h256(u256(i * i)).asBytes(), h256(u256(i)).asBytes(), 1000);
for (auto i: wh->checkWatch(w))
cnote << "New message:" << (u256)h256(wh->message(i).payload);
}
-
return 0;
}
+*/
diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp
index 325ba274e..8312960c1 100644
--- a/libdevcore/Common.cpp
+++ b/libdevcore/Common.cpp
@@ -27,7 +27,7 @@ using namespace dev;
namespace dev
{
-char const* Version = "0.6.8b";
+char const* Version = "0.6.9";
}
diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp
index 96269bbc1..6e889a6b0 100644
--- a/libdevcore/CommonData.cpp
+++ b/libdevcore/CommonData.cpp
@@ -102,3 +102,181 @@ bytes dev::asNibbles(std::string const& _s)
}
return ret;
}
+
+#if 0
+
+/* Following code is copyright 2012-2014 Luke Dashjr
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the standard MIT license. See COPYING for more details.
+ */
+
+#include
+#include
+#include
+#include
+
+static const int8_t b58digits_map[] = {
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1,
+ -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1,
+ 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1,
+ -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46,
+ 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1,
+};
+
+bool b58tobin(void *bin, size_t *binszp, const char *b58, size_t b58sz)
+{
+ size_t binsz = *binszp;
+ const unsigned char *b58u = (void*)b58;
+ unsigned char *binu = bin;
+ size_t outisz = (binsz + 3) / 4;
+ uint32_t outi[outisz];
+ uint64_t t;
+ uint32_t c;
+ size_t i, j;
+ uint8_t bytesleft = binsz % 4;
+ uint32_t zeromask = bytesleft ? (0xffffffff << (bytesleft * 8)) : 0;
+ unsigned zerocount = 0;
+
+ if (!b58sz)
+ b58sz = strlen(b58);
+
+ memset(outi, 0, outisz * sizeof(*outi));
+
+ // Leading zeros, just count
+ for (i = 0; i < b58sz && !b58digits_map[b58u[i]]; ++i)
+ ++zerocount;
+
+ for ( ; i < b58sz; ++i)
+ {
+ if (b58u[i] & 0x80)
+ // High-bit set on invalid digit
+ return false;
+ if (b58digits_map[b58u[i]] == -1)
+ // Invalid base58 digit
+ return false;
+ c = (unsigned)b58digits_map[b58u[i]];
+ for (j = outisz; j--; )
+ {
+ t = ((uint64_t)outi[j]) * 58 + c;
+ c = (t & 0x3f00000000) >> 32;
+ outi[j] = t & 0xffffffff;
+ }
+ if (c)
+ // Output number too big (carry to the next int32)
+ return false;
+ if (outi[0] & zeromask)
+ // Output number too big (last int32 filled too far)
+ return false;
+ }
+
+ j = 0;
+ switch (bytesleft) {
+ case 3:
+ *(binu++) = (outi[0] & 0xff0000) >> 16;
+ case 2:
+ *(binu++) = (outi[0] & 0xff00) >> 8;
+ case 1:
+ *(binu++) = (outi[0] & 0xff);
+ ++j;
+ default:
+ break;
+ }
+
+ for (; j < outisz; ++j)
+ {
+ *(binu++) = (outi[j] >> 0x18) & 0xff;
+ *(binu++) = (outi[j] >> 0x10) & 0xff;
+ *(binu++) = (outi[j] >> 8) & 0xff;
+ *(binu++) = (outi[j] >> 0) & 0xff;
+ }
+
+ // Count canonical base58 byte count
+ binu = bin;
+ for (i = 0; i < binsz; ++i)
+ {
+ if (binu[i])
+ break;
+ --*binszp;
+ }
+ *binszp += zerocount;
+
+ return true;
+}
+
+static
+bool my_dblsha256(void *hash, const void *data, size_t datasz)
+{
+ uint8_t buf[0x20];
+ return b58_sha256_impl(buf, data, datasz) && b58_sha256_impl(hash, buf, sizeof(buf));
+}
+
+int b58check(const void *bin, size_t binsz, const char *base58str, size_t b58sz)
+{
+ unsigned char buf[32];
+ const uint8_t *binc = bin;
+ unsigned i;
+ if (binsz < 4)
+ return -4;
+ if (!my_dblsha256(buf, bin, binsz - 4))
+ return -2;
+ if (memcmp(&binc[binsz - 4], buf, 4))
+ return -1;
+
+ // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
+ for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
+ {} // Just finding the end of zeros, nothing to do in loop
+ if (binc[i] == '\0' || base58str[i] == '1')
+ return -3;
+
+ return binc[0];
+}
+
+static const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
+
+bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
+{
+ const uint8_t *bin = data;
+ int carry;
+ size_t i, j, high, zcount = 0;
+ size_t size;
+
+ while (zcount < binsz && !bin[zcount])
+ ++zcount;
+
+ size = (binsz - zcount) * 138 / 100 + 1;
+ uint8_t buf[size];
+ memset(buf, 0, size);
+
+ for (i = zcount, high = size - 1; i < binsz; ++i, high = j)
+ {
+ for (carry = bin[i], j = size - 1; (j > high) || carry; --j)
+ {
+ carry += 256 * buf[j];
+ buf[j] = carry % 58;
+ carry /= 58;
+ }
+ }
+
+ for (j = 0; j < size && !buf[j]; ++j);
+
+ if (*b58sz <= zcount + size - j)
+ {
+ *b58sz = zcount + size - j + 1;
+ return false;
+ }
+
+ if (zcount)
+ memset(b58, '1', zcount);
+ for (i = zcount; j < size; ++i, ++j)
+ b58[i] = b58digits_ordered[buf[j]];
+ b58[i] = '\0';
+ *b58sz = i + 1;
+
+ return true;
+}
+
+#endif
diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h
index 1181e07e8..11850fa69 100644
--- a/libdevcore/CommonData.h
+++ b/libdevcore/CommonData.h
@@ -55,6 +55,11 @@ int fromHex(char _i);
/// @example fromHex("41626261") == asBytes("Abba")
bytes fromHex(std::string const& _s);
+#if 0
+std::string toBase58(bytesConstRef _data);
+bytes fromBase58(std::string const& _s);
+#endif
+
/// Converts byte array to a string containing the same (binary) data. Unless
/// the byte array happens to contain ASCII data, this won't be printable.
inline std::string asString(bytes const& _b)
diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h
index 068c5c777..98c5a96c7 100644
--- a/libdevcore/CommonIO.h
+++ b/libdevcore/CommonIO.h
@@ -49,15 +49,6 @@ void writeFile(std::string const& _file, bytes const& _data);
/// Nicely renders the given bytes to a string, optionally as HTML.
std::string memDump(bytes const& _b, unsigned _w = 8, bool _html = false);
-/// Converts arbitrary value to string representation using std::stringstream.
-template
-std::string toString(_T const& _t)
-{
- std::ostringstream o;
- o << _t;
- return o.str();
-}
-
// Stream I/O functions.
// Provides templated stream I/O for all STL collections so they can be shifted on to any iostream-like interface.
@@ -223,4 +214,15 @@ template inline std::ostream& operator<<(std::ostream& _out,
template _S& operator<<(_S& _out, std::shared_ptr<_T> const& _p) { if (_p) _out << "@" << (*_p); else _out << "nullptr"; return _out; }
+// Functions that use streaming stuff.
+
+/// Converts arbitrary value to string representation using std::stringstream.
+template
+std::string toString(_T const& _t)
+{
+ std::ostringstream o;
+ o << _t;
+ return o.str();
+}
+
}
diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h
index ed311a082..35e1d1dcf 100644
--- a/libdevcore/RLP.h
+++ b/libdevcore/RLP.h
@@ -160,7 +160,6 @@ public:
explicit operator std::string() const { return toString(); }
explicit operator RLPs() const { return toList(); }
explicit operator byte() const { return toInt(); }
- explicit operator unsigned() const { return toInt(); }
explicit operator u256() const { return toInt(); }
explicit operator bigint() const { return toInt(); }
template explicit operator FixedHash<_N>() const { return toHash>(); }
@@ -213,8 +212,8 @@ public:
std::pair ret;
if (isList())
{
- ret.first = (*this)[0].operator T();
- ret.second = (*this)[1].operator U();
+ ret.first = (T)(*this)[0];
+ ret.second = (U)(*this)[1];
}
return ret;
}
diff --git a/libdevcore/RangeMask.cpp b/libdevcore/RangeMask.cpp
new file mode 100644
index 000000000..5317e00e8
--- /dev/null
+++ b/libdevcore/RangeMask.cpp
@@ -0,0 +1,22 @@
+/*
+ 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 RangeMask.cpp
+ * @author Gav Wood
+ * @date 2014
+ */
+
+#include "RangeMask.h"
diff --git a/libdevcore/RangeMask.h b/libdevcore/RangeMask.h
new file mode 100644
index 000000000..f1b0043ff
--- /dev/null
+++ b/libdevcore/RangeMask.h
@@ -0,0 +1,212 @@
+/*
+ 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 EthereumHost.h
+ * @author Gav Wood
+ * @date 2014
+ */
+
+#pragma once
+
+#include