|
|
@ -2,6 +2,7 @@ |
|
|
|
#include <QtWidgets> |
|
|
|
#include <QtCore> |
|
|
|
#include <libethereum/Dagger.h> |
|
|
|
#include <libethereum/Client.h> |
|
|
|
#include "MainWin.h" |
|
|
|
#include "ui_Main.h" |
|
|
|
using namespace std; |
|
|
@ -14,15 +15,18 @@ static void initUnits(QComboBox* _b) |
|
|
|
_b->setCurrentIndex(6); |
|
|
|
} |
|
|
|
|
|
|
|
#define ETH_QUOTED(A) #A |
|
|
|
|
|
|
|
Main::Main(QWidget *parent) : |
|
|
|
QMainWindow(parent), |
|
|
|
ui(new Ui::Main), |
|
|
|
m_client("AlethZero/v0.1.1") |
|
|
|
ui(new Ui::Main) |
|
|
|
{ |
|
|
|
setWindowFlags(Qt::Window); |
|
|
|
ui->setupUi(this); |
|
|
|
initUnits(ui->valueUnits); |
|
|
|
initUnits(ui->feeUnits); |
|
|
|
g_logPost = [=](std::string const& s, char const*) { ui->log->addItem(QString::fromStdString(s)); }; |
|
|
|
m_client = new Client("AlethZero/v" ETH_QUOTED(ETH_VERSION)); |
|
|
|
|
|
|
|
readSettings(); |
|
|
|
refresh(); |
|
|
@ -44,7 +48,9 @@ Main::Main(QWidget *parent) : |
|
|
|
srand(time(0)); |
|
|
|
#endif |
|
|
|
|
|
|
|
g_logPost = [=](std::string const& s, char const*) { ui->log->addItem(QString::fromStdString(s)); }; |
|
|
|
statusBar()->addPermanentWidget(ui->balance); |
|
|
|
statusBar()->addPermanentWidget(ui->peerCount); |
|
|
|
statusBar()->addPermanentWidget(ui->blockChain); |
|
|
|
} |
|
|
|
|
|
|
|
Main::~Main() |
|
|
@ -89,7 +95,7 @@ void Main::readSettings() |
|
|
|
m_myKeys.append(KeyPair(k)); |
|
|
|
} |
|
|
|
} |
|
|
|
m_client.setAddress(m_myKeys.back().address()); |
|
|
|
m_client->setAddress(m_myKeys.back().address()); |
|
|
|
|
|
|
|
writeSettings(); |
|
|
|
|
|
|
@ -102,25 +108,25 @@ void Main::readSettings() |
|
|
|
|
|
|
|
void Main::refresh() |
|
|
|
{ |
|
|
|
m_client.lock(); |
|
|
|
if (m_client.changed()) |
|
|
|
m_client->lock(); |
|
|
|
if (m_client->changed()) |
|
|
|
{ |
|
|
|
ui->peerCount->setText(QString::fromStdString(toString(m_client.peerCount())) + " peer(s)"); |
|
|
|
ui->peerCount->setText(QString::fromStdString(toString(m_client->peerCount())) + " peer(s)"); |
|
|
|
ui->peers->clear(); |
|
|
|
for (PeerInfo const& i: m_client.peers()) |
|
|
|
for (PeerInfo const& i: m_client->peers()) |
|
|
|
ui->peers->addItem(QString("%3 ms - %1:%2 - %4").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast<chrono::milliseconds>(i.lastPing).count()).arg(i.clientVersion.c_str())); |
|
|
|
|
|
|
|
auto d = m_client.blockChain().details(); |
|
|
|
auto diff = BlockInfo(m_client.blockChain().block()).difficulty; |
|
|
|
auto d = m_client->blockChain().details(); |
|
|
|
auto diff = BlockInfo(m_client->blockChain().block()).difficulty; |
|
|
|
ui->blockChain->setText(QString("#%1 @%3 T%2").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff))); |
|
|
|
|
|
|
|
auto acs = m_client.state().addresses(); |
|
|
|
auto acs = m_client->state().addresses(); |
|
|
|
ui->accounts->clear(); |
|
|
|
for (auto i: acs) |
|
|
|
ui->accounts->addItem(QString("%1 @ %2").arg(formatBalance(i.second).c_str()).arg(asHex(i.first.asArray()).c_str())); |
|
|
|
|
|
|
|
ui->transactionQueue->clear(); |
|
|
|
for (pair<h256, bytes> const& i: m_client.transactionQueue().transactions()) |
|
|
|
for (pair<h256, bytes> const& i: m_client->transactionQueue().transactions()) |
|
|
|
{ |
|
|
|
Transaction t(i.second); |
|
|
|
ui->transactionQueue->addItem(QString("%1 (%2 fee) @ %3 <- %4") |
|
|
@ -131,7 +137,7 @@ void Main::refresh() |
|
|
|
} |
|
|
|
|
|
|
|
ui->transactions->clear(); |
|
|
|
auto const& bc = m_client.blockChain(); |
|
|
|
auto const& bc = m_client->blockChain(); |
|
|
|
for (auto h = bc.currentHash(); h != bc.genesisHash(); h = bc.details(h).parent) |
|
|
|
{ |
|
|
|
auto d = bc.details(h); |
|
|
@ -152,12 +158,12 @@ void Main::refresh() |
|
|
|
u256 totalBalance = 0; |
|
|
|
for (auto i: m_myKeys) |
|
|
|
{ |
|
|
|
u256 b = m_client.state().balance(i.address()); |
|
|
|
u256 b = m_client->state().balance(i.address()); |
|
|
|
ui->ourAccounts->addItem(QString("%1 @ %2").arg(formatBalance(b).c_str()).arg(asHex(i.address().asArray()).c_str())); |
|
|
|
totalBalance += b; |
|
|
|
} |
|
|
|
ui->balance->setText(QString::fromStdString(formatBalance(totalBalance))); |
|
|
|
m_client.unlock(); |
|
|
|
m_client->unlock(); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::on_ourAccounts_doubleClicked() |
|
|
@ -174,9 +180,9 @@ void Main::on_net_triggered() |
|
|
|
{ |
|
|
|
ui->port->setEnabled(!ui->net->isChecked()); |
|
|
|
if (ui->net->isChecked()) |
|
|
|
m_client.startNetwork(ui->port->value(), string(), 0, NodeMode::Full, 5, std::string(), ui->upnp->isChecked()); |
|
|
|
m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, 5, std::string(), ui->upnp->isChecked()); |
|
|
|
else |
|
|
|
m_client.stopNetwork(); |
|
|
|
m_client->stopNetwork(); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::on_connect_triggered() |
|
|
@ -189,7 +195,7 @@ void Main::on_connect_triggered() |
|
|
|
{ |
|
|
|
string host = s.section(":", 0, 0).toStdString(); |
|
|
|
short port = s.section(":", 1).toInt(); |
|
|
|
m_client.connect(host, port); |
|
|
|
m_client->connect(host, port); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -197,11 +203,11 @@ void Main::on_mine_triggered() |
|
|
|
{ |
|
|
|
if (ui->mine->isChecked()) |
|
|
|
{ |
|
|
|
m_client.setAddress(m_myKeys.last().address()); |
|
|
|
m_client.startMining(); |
|
|
|
m_client->setAddress(m_myKeys.last().address()); |
|
|
|
m_client->startMining(); |
|
|
|
} |
|
|
|
else |
|
|
|
m_client.stopMining(); |
|
|
|
m_client->stopMining(); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::on_send_clicked() |
|
|
@ -209,11 +215,11 @@ void Main::on_send_clicked() |
|
|
|
u256 value = ui->value->value() * units()[units().size() - 1 - ui->valueUnits->currentIndex()].first; |
|
|
|
u256 fee = ui->fee->value() * units()[units().size() - 1 - ui->feeUnits->currentIndex()].first; |
|
|
|
u256 totalReq = value + fee; |
|
|
|
m_client.lock(); |
|
|
|
m_client->lock(); |
|
|
|
for (auto i: m_myKeys) |
|
|
|
if (m_client.state().balance(i.address()) >= totalReq) |
|
|
|
if (m_client->state().balance(i.address()) >= totalReq) |
|
|
|
{ |
|
|
|
m_client.unlock(); |
|
|
|
m_client->unlock(); |
|
|
|
Secret s = m_myKeys.front().secret(); |
|
|
|
Address r = Address(fromUserHex(ui->destination->text().toStdString())); |
|
|
|
auto ds = ui->data->toPlainText().split(QRegExp("[^0-9a-fA-Fx]+")); |
|
|
@ -221,11 +227,11 @@ void Main::on_send_clicked() |
|
|
|
data.reserve(ds.size()); |
|
|
|
for (QString const& i: ds) |
|
|
|
data.push_back(u256(i.toStdString())); |
|
|
|
m_client.transact(s, r, value, fee, data); |
|
|
|
m_client->transact(s, r, value, fee, data); |
|
|
|
refresh(); |
|
|
|
return; |
|
|
|
} |
|
|
|
m_client.unlock(); |
|
|
|
m_client->unlock(); |
|
|
|
statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount."); |
|
|
|
} |
|
|
|
|
|
|
|