|
|
@ -84,10 +84,6 @@ using eth::g_logPost; |
|
|
|
using eth::g_logVerbosity; |
|
|
|
using eth::c_instructionInfo; |
|
|
|
|
|
|
|
// Horrible global for the mainwindow. Needed for the QEthereums to find the Main window which acts as multiplexer for now.
|
|
|
|
// Can get rid of this once we've sorted out ITC for signalling & multiplexed querying.
|
|
|
|
Main* g_main = nullptr; |
|
|
|
|
|
|
|
static void initUnits(QComboBox* _b) |
|
|
|
{ |
|
|
|
for (auto n = (::uint)units().size(); n-- != 0; ) |
|
|
@ -100,24 +96,9 @@ Main::Main(QWidget *parent) : |
|
|
|
QMainWindow(parent), |
|
|
|
ui(new Ui::Main) |
|
|
|
{ |
|
|
|
g_main = this; |
|
|
|
|
|
|
|
setWindowFlags(Qt::Window); |
|
|
|
ui->setupUi(this); |
|
|
|
g_logPost = [=](std::string const& s, char const* c) { simpleDebugOut(s, c); ui->log->addItem(QString::fromStdString(s)); }; |
|
|
|
m_client.reset(new Client("AlethZero")); |
|
|
|
|
|
|
|
m_refresh = new QTimer(this); |
|
|
|
connect(m_refresh, SIGNAL(timeout()), SLOT(refresh())); |
|
|
|
m_refresh->start(100); |
|
|
|
m_refreshNetwork = new QTimer(this); |
|
|
|
connect(m_refreshNetwork, SIGNAL(timeout()), SLOT(refreshNetwork())); |
|
|
|
m_refreshNetwork->start(1000); |
|
|
|
m_refreshMining = new QTimer(this); |
|
|
|
connect(m_refreshMining, SIGNAL(timeout()), SLOT(refreshMining())); |
|
|
|
m_refreshMining->start(200); |
|
|
|
|
|
|
|
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved())); |
|
|
|
|
|
|
|
#if 0&Ð_DEBUG
|
|
|
|
m_servers.append("192.168.0.10:30301"); |
|
|
@ -147,7 +128,6 @@ Main::Main(QWidget *parent) : |
|
|
|
cerr << "Network protocol version: " << eth::c_protocolVersion << endl; |
|
|
|
|
|
|
|
ui->configDock->close(); |
|
|
|
|
|
|
|
on_verbosity_valueChanged(); |
|
|
|
initUnits(ui->gasPriceUnits); |
|
|
|
initUnits(ui->valueUnits); |
|
|
@ -160,27 +140,61 @@ Main::Main(QWidget *parent) : |
|
|
|
statusBar()->addPermanentWidget(ui->peerCount); |
|
|
|
statusBar()->addPermanentWidget(ui->mineStatus); |
|
|
|
statusBar()->addPermanentWidget(ui->blockCount); |
|
|
|
|
|
|
|
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved())); |
|
|
|
|
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::titleChanged, [=]() |
|
|
|
m_client.reset(new Client("AlethZero")); |
|
|
|
m_client->start(); |
|
|
|
m_ethereum.reset(new QEthereum(this, this->m_client.get(), this->owned())); |
|
|
|
|
|
|
|
shared_ptr<Main>qmain(this); |
|
|
|
shared_ptr<QEthereum>qeth(m_ethereum.get()); |
|
|
|
connect(ui->webView, &QWebView::loadStarted, [qmain, qeth]() |
|
|
|
{ |
|
|
|
ui->tabWidget->setTabText(0, ui->webView->title()); |
|
|
|
}); |
|
|
|
Main::Main *self = qmain.get(); |
|
|
|
QEthereum *eth = new QEthereum(self, self->m_client.get(), self->owned()); |
|
|
|
connect(self, SIGNAL(changed()), eth, SIGNAL(changed())); |
|
|
|
|
|
|
|
QWebFrame* f = self->ui->webView->page()->mainFrame(); |
|
|
|
f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); |
|
|
|
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [f, eth, self]() |
|
|
|
{ |
|
|
|
f->disconnect(); |
|
|
|
f->addToJavaScriptWindowObject("env", self, QWebFrame::QtOwnership); |
|
|
|
f->addToJavaScriptWindowObject("eth", eth, QWebFrame::ScriptOwnership); |
|
|
|
f->evaluateJavaScript("eth.watch = function(a, s, f) { eth.changed.connect(f ? f : s) }"); |
|
|
|
f->evaluateJavaScript("eth.newBlock = function(f) { eth.changed.connect(f) }"); |
|
|
|
|
|
|
|
f->evaluateJavaScript("eth.create = function(s, v, c, g, p, f) { var v = eth.doCreate(s, v, c, g, p); if (f) f(v) }"); |
|
|
|
f->evaluateJavaScript("eth.transact = function(s, v, t, d, g, p, f) { eth.doTransact(s, v, t, d, g, p); if (f) f() }"); |
|
|
|
f->evaluateJavaScript("eth.transactions = function(a) { return JSON.parse(eth.getTransactions(JSON.stringify(a))); }"); |
|
|
|
f->evaluateJavaScript("String.prototype.pad = function(l, r) { return eth.pad(this, l, r) }"); |
|
|
|
f->evaluateJavaScript("String.prototype.bin = function() { return eth.toBinary(this) }"); |
|
|
|
f->evaluateJavaScript("String.prototype.unbin = function(l) { return eth.fromBinary(this) }"); |
|
|
|
f->evaluateJavaScript("String.prototype.unpad = function(l) { return eth.unpad(this) }"); |
|
|
|
f->evaluateJavaScript("String.prototype.dec = function() { return eth.toDecimal(this) }"); |
|
|
|
f->evaluateJavaScript("String.prototype.sha3 = function() { return eth.sha3(this) }"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::loadFinished, [=]() |
|
|
|
{ |
|
|
|
this->changed(); |
|
|
|
}); |
|
|
|
|
|
|
|
QWebFrame* f = ui->webView->page()->currentFrame(); |
|
|
|
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [=](){ |
|
|
|
auto qe = new QEthereum(this, m_client.get(), owned()); |
|
|
|
qe->setup(f); |
|
|
|
f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); |
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::titleChanged, [=]() |
|
|
|
{ |
|
|
|
ui->tabWidget->setTabText(0, ui->webView->title()); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
readSettings(); |
|
|
|
refresh(); |
|
|
|
|
|
|
|
m_refresh = new QTimer(this); |
|
|
|
connect(m_refresh, SIGNAL(timeout()), SLOT(refresh())); |
|
|
|
m_refresh->start(100); |
|
|
|
|
|
|
|
{ |
|
|
|
QSettings s("ethereum", "alethzero"); |
|
|
|
if (s.value("splashMessage", true).toBool()) |
|
|
@ -618,6 +632,23 @@ void Main::refreshBlockChain() |
|
|
|
|
|
|
|
void Main::refresh(bool _override) |
|
|
|
{ |
|
|
|
// 7/18, Alex: aggregating timers, prelude to better threading?
|
|
|
|
// Runs much faster on slower dual-core processors
|
|
|
|
static int interval = 100; |
|
|
|
|
|
|
|
// refresh mining every 200ms
|
|
|
|
if(interval / 100 % 2 == 0) |
|
|
|
refreshMining(); |
|
|
|
|
|
|
|
// refresh peer list every 1000ms, reset counter
|
|
|
|
if(interval == 1000) |
|
|
|
{ |
|
|
|
interval = 0; |
|
|
|
refreshNetwork(); |
|
|
|
} else |
|
|
|
interval += 100; |
|
|
|
|
|
|
|
|
|
|
|
eth::ClientGuard g(m_client.get()); |
|
|
|
auto const& st = state(); |
|
|
|
|
|
|
@ -625,7 +656,7 @@ void Main::refresh(bool _override) |
|
|
|
if (c || _override) |
|
|
|
{ |
|
|
|
changed(); |
|
|
|
|
|
|
|
|
|
|
|
updateBlockCount(); |
|
|
|
|
|
|
|
auto acs = st.addresses(); |
|
|
@ -1189,6 +1220,7 @@ void Main::on_killBlockchain_triggered() |
|
|
|
ui->net->setChecked(false); |
|
|
|
m_client.reset(); |
|
|
|
m_client.reset(new Client("AlethZero", Address(), string(), true)); |
|
|
|
m_client->start(); |
|
|
|
readSettings(); |
|
|
|
} |
|
|
|
|
|
|
|