|
|
@ -31,6 +31,7 @@ |
|
|
|
#include <libserpent/funcs.h> |
|
|
|
#include <libserpent/util.h> |
|
|
|
#include <libethcore/Dagger.h> |
|
|
|
#include <libdevcrypto/FileSystem.h> |
|
|
|
#include <liblll/Compiler.h> |
|
|
|
#include <liblll/CodeFragment.h> |
|
|
|
#include <libevm/VM.h> |
|
|
@ -38,49 +39,14 @@ |
|
|
|
#include <libethereum/ExtVM.h> |
|
|
|
#include <libethereum/Client.h> |
|
|
|
#include <libethereum/EthereumHost.h> |
|
|
|
#include <libwebthree/WebThree.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::compileLLL; |
|
|
|
using dev::eth::disassemble; |
|
|
|
using dev::eth::formatBalance; |
|
|
|
using dev::eth::sha3; |
|
|
|
|
|
|
|
// vars
|
|
|
|
using dev::g_logPost; |
|
|
|
using dev::g_logVerbosity; |
|
|
|
using namespace dev; |
|
|
|
using namespace dev::eth; |
|
|
|
using namespace dev::p2p; |
|
|
|
|
|
|
|
static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr) |
|
|
|
{ |
|
|
@ -133,12 +99,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("Third")); |
|
|
|
m_web3.reset(new WebThreeDirect("Third", getDataDir() + "/Third", 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, m_client.get(), owned()); |
|
|
|
m_ethereum = new QEthereum(this, ethereum(), owned()); |
|
|
|
|
|
|
|
QWebFrame* f = ui->webView->page()->mainFrame(); |
|
|
|
f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); |
|
|
@ -181,6 +147,11 @@ Main::~Main() |
|
|
|
writeSettings(); |
|
|
|
} |
|
|
|
|
|
|
|
eth::Client* Main::ethereum() const |
|
|
|
{ |
|
|
|
return m_web3->ethereum(); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::onKeysChanged() |
|
|
|
{ |
|
|
|
installBalancesWatch(); |
|
|
@ -188,14 +159,14 @@ void Main::onKeysChanged() |
|
|
|
|
|
|
|
unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function<void()> const& _f) |
|
|
|
{ |
|
|
|
auto ret = m_client->installWatch(_tf); |
|
|
|
auto ret = ethereum()->installWatch(_tf); |
|
|
|
m_handlers[ret] = _f; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
unsigned Main::installWatch(dev::h256 _tf, std::function<void()> const& _f) |
|
|
|
{ |
|
|
|
auto ret = m_client->installWatch(_tf); |
|
|
|
auto ret = ethereum()->installWatch(_tf); |
|
|
|
m_handlers[ret] = _f; |
|
|
|
return ret; |
|
|
|
} |
|
|
@ -209,14 +180,14 @@ void Main::installWatches() |
|
|
|
|
|
|
|
void Main::installNameRegWatch() |
|
|
|
{ |
|
|
|
m_client->uninstallWatch(m_nameRegFilter); |
|
|
|
m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_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() |
|
|
|
{ |
|
|
|
m_client->uninstallWatch(m_currenciesFilter); |
|
|
|
m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_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() |
|
|
@ -224,9 +195,9 @@ void Main::installBalancesWatch() |
|
|
|
dev::eth::MessageFilter tf; |
|
|
|
|
|
|
|
vector<Address> altCoins; |
|
|
|
Address coinsAddr = right160(m_client->stateAt(c_config, 1)); |
|
|
|
for (unsigned i = 0; i < m_client->stateAt(coinsAddr, 0); ++i) |
|
|
|
altCoins.push_back(right160(m_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()); |
|
|
@ -234,7 +205,7 @@ void Main::installBalancesWatch() |
|
|
|
tf.altered(c, (u160)i.address()); |
|
|
|
} |
|
|
|
|
|
|
|
m_client->uninstallWatch(m_balancesFilter); |
|
|
|
ethereum()->uninstallWatch(m_balancesFilter); |
|
|
|
m_balancesFilter = installWatch(tf, [=](){ onBalancesChange(); }); |
|
|
|
} |
|
|
|
|
|
|
@ -295,8 +266,8 @@ QString Main::pretty(dev::Address _a) const |
|
|
|
{ |
|
|
|
h256 n; |
|
|
|
|
|
|
|
if (h160 nameReg = (u160)m_client->stateAt(c_config, 0)) |
|
|
|
n = m_client->stateAt(nameReg, (u160)(_a)); |
|
|
|
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) |
|
|
|
n = ethereum()->stateAt(nameReg, (u160)(_a)); |
|
|
|
|
|
|
|
return fromRaw(n); |
|
|
|
} |
|
|
@ -322,8 +293,8 @@ Address Main::fromString(QString const& _a) const |
|
|
|
memset(n.data() + sn.size(), 0, 32 - sn.size()); |
|
|
|
if (_a.size()) |
|
|
|
{ |
|
|
|
if (h160 nameReg = (u160)m_client->stateAt(c_config, 0)) |
|
|
|
if (h256 a = m_client->stateAt(nameReg, n)) |
|
|
|
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) |
|
|
|
if (h256 a = ethereum()->stateAt(nameReg, n)) |
|
|
|
return right160(a); |
|
|
|
} |
|
|
|
if (_a.size() == 40) |
|
|
@ -351,11 +322,11 @@ QString Main::lookup(QString const& _a) const |
|
|
|
*/ |
|
|
|
|
|
|
|
h256 ret; |
|
|
|
if (h160 dnsReg = (u160)m_client->stateAt(c_config, 4, 0)) |
|
|
|
ret = m_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]); |
|
|
@ -385,7 +356,7 @@ void Main::writeSettings() |
|
|
|
s.setValue("address", b); |
|
|
|
s.setValue("url", ui->urlEdit->text()); |
|
|
|
|
|
|
|
bytes d = m_client->savePeers(); |
|
|
|
bytes d = ethereum()->savePeers(); |
|
|
|
if (d.size()) |
|
|
|
m_peers = QByteArray((char*)d.data(), (int)d.size()); |
|
|
|
s.setValue("peers", m_peers); |
|
|
@ -416,7 +387,7 @@ void Main::readSettings(bool _skipGeometry) |
|
|
|
m_myKeys.append(KeyPair(k)); |
|
|
|
} |
|
|
|
} |
|
|
|
m_client->setAddress(m_myKeys.back().address()); |
|
|
|
ethereum()->setAddress(m_myKeys.back().address()); |
|
|
|
m_peers = s.value("peers").toByteArray(); |
|
|
|
ui->urlEdit->setText(s.value("url", "about:blank").toString()); //http://gavwood.com/gavcoin.html
|
|
|
|
on_urlEdit_returnPressed(); |
|
|
@ -466,8 +437,8 @@ void Main::on_urlEdit_returnPressed() |
|
|
|
|
|
|
|
void Main::refreshMining() |
|
|
|
{ |
|
|
|
dev::eth::MineProgress p = m_client->miningProgress(); |
|
|
|
ui->mineStatus->setText(m_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"); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::refreshBalances() |
|
|
@ -477,18 +448,18 @@ void Main::refreshBalances() |
|
|
|
ui->ourAccounts->clear(); |
|
|
|
u256 totalBalance = 0; |
|
|
|
map<Address, pair<QString, u256>> altCoins; |
|
|
|
Address coinsAddr = right160(m_client->stateAt(c_config, 1)); |
|
|
|
for (unsigned i = 0; i < m_client->stateAt(coinsAddr, 0); ++i) |
|
|
|
altCoins[right160(m_client->stateAt(coinsAddr, m_client->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(m_client->stateAt(coinsAddr, i + 1)), 0); |
|
|
|
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1)); |
|
|
|
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) |
|
|
|
altCoins[right160(ethereum()->stateAt(coinsAddr, ethereum()->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(ethereum()->stateAt(coinsAddr, i + 1)), 0); |
|
|
|
for (auto i: m_myKeys) |
|
|
|
{ |
|
|
|
u256 b = m_client->balanceAt(i.address()); |
|
|
|
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)m_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) |
|
|
|
c.second.second += (u256)m_client->stateAt(c.first, (u160)i.address()); |
|
|
|
c.second.second += (u256)ethereum()->stateAt(c.first, (u160)i.address()); |
|
|
|
} |
|
|
|
|
|
|
|
QString b; |
|
|
@ -500,7 +471,7 @@ void Main::refreshBalances() |
|
|
|
|
|
|
|
void Main::refreshNetwork() |
|
|
|
{ |
|
|
|
auto ps = m_client->peers(); |
|
|
|
auto ps = ethereum()->peers(); |
|
|
|
|
|
|
|
ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)"); |
|
|
|
} |
|
|
@ -514,8 +485,8 @@ void Main::refreshAll() |
|
|
|
void Main::refreshBlockCount() |
|
|
|
{ |
|
|
|
cwatch << "refreshBlockCount()"; |
|
|
|
auto d = m_client->blockChain().details(); |
|
|
|
auto diff = BlockInfo(m_client->blockChain().block()).difficulty; |
|
|
|
auto d = ethereum()->blockChain().details(); |
|
|
|
auto diff = BlockInfo(ethereum()->blockChain().block()).difficulty; |
|
|
|
ui->blockCount->setText(QString("#%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)); |
|
|
|
} |
|
|
|
|
|
|
@ -543,7 +514,7 @@ void Main::timerEvent(QTimerEvent*) |
|
|
|
m_ethereum->poll(); |
|
|
|
|
|
|
|
for (auto const& i: m_handlers) |
|
|
|
if (m_client->checkWatch(i.first)) |
|
|
|
if (ethereum()->checkWatch(i.first)) |
|
|
|
i.second(); |
|
|
|
} |
|
|
|
|
|
|
@ -574,7 +545,7 @@ void Main::ensureNetwork() |
|
|
|
{ |
|
|
|
string n = string("Third/v") + dev::Version; |
|
|
|
n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM); |
|
|
|
m_client->setClientVersion(n); |
|
|
|
web3()->setClientVersion(n); |
|
|
|
|
|
|
|
int pocnumber = QString(dev::Version).section('.', 1, 1).toInt(); |
|
|
|
string defPeer; |
|
|
@ -583,13 +554,16 @@ void Main::ensureNetwork() |
|
|
|
else if (pocnumber == 6) |
|
|
|
defPeer = "54.76.56.74"; |
|
|
|
|
|
|
|
if (!m_client->haveNetwork()) |
|
|
|
m_client->startNetwork(30303, defPeer); |
|
|
|
if (!web3()->haveNetwork()) |
|
|
|
{ |
|
|
|
web3()->startNetwork(); |
|
|
|
web3()->connect(defPeer); |
|
|
|
} |
|
|
|
else |
|
|
|
if (!m_client->peerCount()) |
|
|
|
m_client->connect(defPeer); |
|
|
|
if (!ethereum()->peerCount()) |
|
|
|
ethereum()->connect(defPeer); |
|
|
|
if (m_peers.size()) |
|
|
|
m_client->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size())); |
|
|
|
ethereum()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size())); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::on_connect_triggered() |
|
|
@ -600,7 +574,7 @@ void Main::on_connect_triggered() |
|
|
|
{ |
|
|
|
string host = s.section(":", 0, 0).toStdString(); |
|
|
|
unsigned short port = s.section(":", 1).toInt(); |
|
|
|
m_client->connect(host, port); |
|
|
|
web3()->connect(host, port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -608,11 +582,11 @@ void Main::on_mine_triggered() |
|
|
|
{ |
|
|
|
if (ui->mine->isChecked()) |
|
|
|
{ |
|
|
|
m_client->setAddress(m_myKeys.last().address()); |
|
|
|
m_client->startMining(); |
|
|
|
ethereum()->setAddress(m_myKeys.last().address()); |
|
|
|
ethereum()->startMining(); |
|
|
|
} |
|
|
|
else |
|
|
|
m_client->stopMining(); |
|
|
|
ethereum()->stopMining(); |
|
|
|
} |
|
|
|
|
|
|
|
// extra bits needed to link on VS
|
|
|
|