Browse Source

Style fixes in MainWin of AZ.

- Basically just omitting all namespace prefixes that are declared to be
  used with the using directive
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
ab6c8f0f37
  1. 96
      alethzero/MainWin.cpp

96
alethzero/MainWin.cpp

@ -19,6 +19,7 @@
* @date 2014 * @date 2014
*/ */
#include "MainWin.h"
#include <fstream> #include <fstream>
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QtWidgets/QFileDialog> #include <QtWidgets/QFileDialog>
@ -51,7 +52,6 @@
#include "DownloadView.h" #include "DownloadView.h"
#include "MiningView.h" #include "MiningView.h"
#include "BuildInfo.h" #include "BuildInfo.h"
#include "MainWin.h"
#include "OurWebThreeStubServer.h" #include "OurWebThreeStubServer.h"
#include "ui_Main.h" #include "ui_Main.h"
using namespace std; using namespace std;
@ -66,11 +66,11 @@ static void initUnits(QComboBox* _b)
_b->addItem(QString::fromStdString(units()[n].second), n); _b->addItem(QString::fromStdString(units()[n].second), n);
} }
QString Main::fromRaw(dev::h256 _n, unsigned* _inc) QString Main::fromRaw(h256 _n, unsigned* _inc)
{ {
if (_n) if (_n)
{ {
std::string s((char const*)_n.data(), 32); string s((char const*)_n.data(), 32);
auto l = s.find_first_of('\0'); auto l = s.find_first_of('\0');
if (!l) if (!l)
return QString(); return QString();
@ -91,13 +91,13 @@ QString Main::fromRaw(dev::h256 _n, unsigned* _inc)
return QString(); return QString();
} }
static std::vector<dev::KeyPair> keysAsVector(QList<dev::KeyPair> const& keys) static vector<KeyPair> keysAsVector(QList<KeyPair> const& keys)
{ {
auto list = keys.toStdList(); auto list = keys.toStdList();
return {begin(list), end(list)}; return {begin(list), end(list)};
} }
static QString contentsOfQResource(std::string const& res) static QString contentsOfQResource(string const& res)
{ {
QFile file(QString::fromStdString(res)); QFile file(QString::fromStdString(res));
if (!file.open(QFile::ReadOnly)) if (!file.open(QFile::ReadOnly))
@ -116,7 +116,7 @@ Main::Main(QWidget *parent) :
{ {
setWindowFlags(Qt::Window); setWindowFlags(Qt::Window);
ui->setupUi(this); ui->setupUi(this);
g_logPost = [=](std::string const& s, char const* c) g_logPost = [=](string const& s, char const* c)
{ {
simpleDebugOut(s, c); simpleDebugOut(s, c);
m_logLock.lock(); m_logLock.lock();
@ -136,8 +136,8 @@ Main::Main(QWidget *parent) :
cerr << "Block Hash: " << BlockChain::genesis().hash << endl; cerr << "Block Hash: " << BlockChain::genesis().hash << endl;
cerr << "Block RLP: " << RLP(block) << endl; cerr << "Block RLP: " << RLP(block) << endl;
cerr << "Block Hex: " << toHex(block) << endl; cerr << "Block Hex: " << toHex(block) << endl;
cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl; cerr << "Network protocol version: " << c_protocolVersion << endl;
cerr << "Client database version: " << dev::eth::c_databaseVersion << endl; cerr << "Client database version: " << c_databaseVersion << endl;
ui->configDock->close(); ui->configDock->close();
on_verbosity_valueChanged(); on_verbosity_valueChanged();
@ -234,7 +234,7 @@ void Main::addNewId(QString _ids)
refreshWhisper(); refreshWhisper();
} }
dev::p2p::NetworkPreferences Main::netPrefs() const NetworkPreferences Main::netPrefs() const
{ {
return NetworkPreferences(ui->port->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), ui->localNetworking->isChecked()); return NetworkPreferences(ui->port->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), ui->localNetworking->isChecked());
} }
@ -244,7 +244,7 @@ void Main::onKeysChanged()
installBalancesWatch(); installBalancesWatch();
} }
unsigned Main::installWatch(dev::eth::LogFilter const& _tf, WatchHandler const& _f) unsigned Main::installWatch(LogFilter const& _tf, WatchHandler const& _f)
{ {
auto ret = ethereum()->installWatch(_tf); auto ret = ethereum()->installWatch(_tf);
m_handlers[ret] = _f; m_handlers[ret] = _f;
@ -266,10 +266,10 @@ void Main::uninstallWatch(unsigned _w)
void Main::installWatches() void Main::installWatches()
{ {
installWatch(dev::eth::LogFilter().address(c_newConfig), [=](LocalisedLogEntries const&) { installNameRegWatch(); }); installWatch(LogFilter().address(c_newConfig), [=](LocalisedLogEntries const&) { installNameRegWatch(); });
installWatch(dev::eth::LogFilter().address(c_newConfig), [=](LocalisedLogEntries const&) { installCurrenciesWatch(); }); installWatch(LogFilter().address(c_newConfig), [=](LocalisedLogEntries const&) { installCurrenciesWatch(); });
installWatch(dev::eth::PendingChangedFilter, [=](LocalisedLogEntries const&){ onNewPending(); }); installWatch(PendingChangedFilter, [=](LocalisedLogEntries const&){ onNewPending(); });
installWatch(dev::eth::ChainChangedFilter, [=](LocalisedLogEntries const&){ onNewBlock(); }); installWatch(ChainChangedFilter, [=](LocalisedLogEntries const&){ onNewBlock(); });
} }
Address Main::getNameReg() const Address Main::getNameReg() const
@ -285,18 +285,18 @@ Address Main::getCurrencies() const
void Main::installNameRegWatch() void Main::installNameRegWatch()
{ {
uninstallWatch(m_nameRegFilter); uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::LogFilter().address((u160)getNameReg()), [=](LocalisedLogEntries const&){ onNameRegChange(); }); m_nameRegFilter = installWatch(LogFilter().address((u160)getNameReg()), [=](LocalisedLogEntries const&){ onNameRegChange(); });
} }
void Main::installCurrenciesWatch() void Main::installCurrenciesWatch()
{ {
uninstallWatch(m_currenciesFilter); uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::LogFilter().address((u160)getCurrencies()), [=](LocalisedLogEntries const&){ onCurrenciesChange(); }); m_currenciesFilter = installWatch(LogFilter().address((u160)getCurrencies()), [=](LocalisedLogEntries const&){ onCurrenciesChange(); });
} }
void Main::installBalancesWatch() void Main::installBalancesWatch()
{ {
dev::eth::LogFilter tf; LogFilter tf;
vector<Address> altCoins; vector<Address> altCoins;
Address coinsAddr = getCurrencies(); Address coinsAddr = getCurrencies();
@ -467,7 +467,7 @@ static Public stringToPublic(QString const& _a)
QString Main::pretty(dev::Address _a) const QString Main::pretty(dev::Address _a) const
{ {
/* static std::map<Address, QString> s_memos; /* static map<Address, QString> s_memos;
if (!s_memos.count(_a)) if (!s_memos.count(_a))
{*/ {*/
@ -505,7 +505,7 @@ QString Main::render(dev::Address _a) const
return QString::fromStdString(_a.abridged()); return QString::fromStdString(_a.abridged());
} }
string32 fromString(std::string const& _s) string32 fromString(string const& _s)
{ {
string32 ret; string32 ret;
for (unsigned i = 0; i < 32 && i <= _s.size(); ++i) for (unsigned i = 0; i < 32 && i <= _s.size(); ++i)
@ -518,7 +518,7 @@ Address Main::fromString(QString const& _n) const
if (_n == "(Create Contract)") if (_n == "(Create Contract)")
return Address(); return Address();
/* static std::map<QString, Address> s_memos; /* static map<QString, Address> s_memos;
if (!s_memos.count(_n)) if (!s_memos.count(_n))
{*/ {*/
@ -860,18 +860,18 @@ void Main::on_preview_triggered()
void Main::refreshMining() void Main::refreshMining()
{ {
dev::eth::MineProgress p = ethereum()->miningProgress(); 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"); 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()) if (!ui->miningView->isVisible())
return; return;
list<dev::eth::MineInfo> l = ethereum()->miningHistory(); list<MineInfo> l = ethereum()->miningHistory();
static unsigned lh = 0; static unsigned lh = 0;
if (p.hashes < lh) if (p.hashes < lh)
ui->miningView->resetStats(); ui->miningView->resetStats();
lh = p.hashes; lh = p.hashes;
ui->miningView->appendStats(l, p); ui->miningView->appendStats(l, p);
/* if (p.ms) /* if (p.ms)
for (dev::eth::MineInfo const& i: l) for (MineInfo const& i: l)
cnote << i.hashes * 10 << "h/sec, need:" << i.requirement << " best:" << i.best << " best-so-far:" << p.best << " avg-speed:" << (p.hashes * 1000 / p.ms) << "h/sec"; cnote << i.hashes * 10 << "h/sec, need:" << i.requirement << " best:" << i.best << " best-so-far:" << p.best << " avg-speed:" << (p.hashes * 1000 / p.ms) << "h/sec";
*/ */
} }
@ -1026,10 +1026,10 @@ void Main::refreshBlockCount()
cwatch << "refreshBlockCount()"; cwatch << "refreshBlockCount()";
auto d = ethereum()->blockChain().details(); auto d = ethereum()->blockChain().details();
auto diff = BlockInfo(ethereum()->blockChain().block()).difficulty; auto diff = BlockInfo(ethereum()->blockChain().block()).difficulty;
ui->blockCount->setText(QString("%6 #%1 @%3 T%2 PV%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")); ui->blockCount->setText(QString("%6 #%1 @%3 T%2 PV%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(c_protocolVersion).arg(c_databaseVersion).arg(m_privateChain.size() ? "[" + m_privateChain + "] " : "testnet"));
} }
static bool blockMatch(string const& _f, dev::eth::BlockDetails const& _b, h256 _h, BlockChain const& _bc) static bool blockMatch(string const& _f, BlockDetails const& _b, h256 _h, BlockChain const& _bc)
{ {
try try
{ {
@ -1178,7 +1178,7 @@ void Main::timerEvent(QTimerEvent*)
} }
} }
string Main::renderDiff(dev::eth::StateDiff const& _d) const string Main::renderDiff(StateDiff const& _d) const
{ {
stringstream s; stringstream s;
@ -1187,24 +1187,24 @@ string Main::renderDiff(dev::eth::StateDiff const& _d) const
{ {
s << "<hr/>"; s << "<hr/>";
dev::eth::AccountDiff const& ad = i.second; AccountDiff const& ad = i.second;
s << "<code style=\"white-space: pre; font-weight: bold\">" << lead(ad.changeType()) << " </code>" << " <b>" << render(i.first).toStdString() << "</b>"; s << "<code style=\"white-space: pre; font-weight: bold\">" << lead(ad.changeType()) << " </code>" << " <b>" << render(i.first).toStdString() << "</b>";
if (!ad.exist.to()) if (!ad.exist.to())
continue; continue;
if (ad.balance) if (ad.balance)
{ {
s << "<br/>" << indent << "Balance " << std::dec << formatBalance(ad.balance.to()); s << "<br/>" << indent << "Balance " << dec << formatBalance(ad.balance.to());
s << " <b>" << std::showpos << (((dev::bigint)ad.balance.to()) - ((dev::bigint)ad.balance.from())) << std::noshowpos << "</b>"; s << " <b>" << showpos << (((dev::bigint)ad.balance.to()) - ((dev::bigint)ad.balance.from())) << noshowpos << "</b>";
} }
if (ad.nonce) if (ad.nonce)
{ {
s << "<br/>" << indent << "Count #" << std::dec << ad.nonce.to(); s << "<br/>" << indent << "Count #" << dec << ad.nonce.to();
s << " <b>" << std::showpos << (((dev::bigint)ad.nonce.to()) - ((dev::bigint)ad.nonce.from())) << std::noshowpos << "</b>"; s << " <b>" << showpos << (((dev::bigint)ad.nonce.to()) - ((dev::bigint)ad.nonce.from())) << noshowpos << "</b>";
} }
if (ad.code) if (ad.code)
{ {
s << "<br/>" << indent << "Code " << std::hex << ad.code.to().size() << " bytes"; s << "<br/>" << indent << "Code " << hex << ad.code.to().size() << " bytes";
if (ad.code.from().size()) if (ad.code.from().size())
s << " (" << ad.code.from().size() << " bytes)"; s << " (" << ad.code.from().size() << " bytes)";
} }
@ -1226,7 +1226,7 @@ string Main::renderDiff(dev::eth::StateDiff const& _d) const
else if (i.first > u160(1) << 150) else if (i.first > u160(1) << 150)
s << (h160)(u160)i.first; s << (h160)(u160)i.first;
else else
s << std::hex << i.first; s << hex << i.first;
*/ */
if (!i.second.from()) if (!i.second.from())
s << ": " << prettyU256(i.second.to()).toStdString(); s << ": " << prettyU256(i.second.to()).toStdString();
@ -1479,10 +1479,10 @@ void Main::populateDebugger(dev::bytesConstRef _r)
bytesConstRef lastData; bytesConstRef lastData;
h256 lastHash; h256 lastHash;
h256 lastDataHash; h256 lastDataHash;
auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, dev::eth::VM* voidVM, dev::eth::ExtVMFace const* voidExt) auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, VM* voidVM, ExtVMFace const* voidExt)
{ {
dev::eth::VM& vm = *voidVM; VM& vm = *voidVM;
dev::eth::ExtVM const& ext = *static_cast<dev::eth::ExtVM const*>(voidExt); ExtVM const& ext = *static_cast<ExtVM const*>(voidExt);
if (ext.code != lastExtCode) if (ext.code != lastExtCode)
{ {
lastExtCode = ext.code; lastExtCode = ext.code;
@ -1605,11 +1605,11 @@ static shh::Topic topicFromText(QString _s)
{ {
u256 v(d.cap(2).toStdString()); u256 v(d.cap(2).toStdString());
if (d.cap(6) == "szabo") if (d.cap(6) == "szabo")
v *= dev::eth::szabo; v *= szabo;
else if (d.cap(5) == "finney") else if (d.cap(5) == "finney")
v *= dev::eth::finney; v *= finney;
else if (d.cap(4) == "ether") else if (d.cap(4) == "ether")
v *= dev::eth::ether; v *= ether;
bytes bs = dev::toCompactBigEndian(v); bytes bs = dev::toCompactBigEndian(v);
if (d.cap(1) != "$") if (d.cap(1) != "$")
for (auto i = bs.size(); i < 32; ++i) for (auto i = bs.size(); i < 32; ++i)
@ -1636,7 +1636,7 @@ static shh::Topic topicFromText(QString _s)
} }
bool Main::sourceIsSolidity(std::string const& _source) bool Main::sourceIsSolidity(string const& _source)
{ {
// TODO: Improve this heuristic // TODO: Improve this heuristic
return (_source.substr(0, 8) == "contract" || _source.substr(0, 5) == "//sol"); return (_source.substr(0, 8) == "contract" || _source.substr(0, 5) == "//sol");
@ -1695,7 +1695,7 @@ void Main::on_data_textChanged()
} }
else else
{ {
m_data = dev::eth::compileLLL(src, m_enableOptimizer, &errors); m_data = compileLLL(src, m_enableOptimizer, &errors);
if (errors.size()) if (errors.size())
{ {
try try
@ -1711,11 +1711,11 @@ void Main::on_data_textChanged()
} }
else else
{ {
auto asmcode = dev::eth::compileLLLToAsm(src, false); auto asmcode = compileLLLToAsm(src, false);
lll = "<h4>Pre</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>"; lll = "<h4>Pre</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>";
if (m_enableOptimizer) if (m_enableOptimizer)
{ {
asmcode = dev::eth::compileLLLToAsm(src, true); asmcode = compileLLLToAsm(src, true);
lll = "<h4>Opt</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>" + lll; lll = "<h4>Opt</h4><pre>" + QString::fromStdString(asmcode).toHtmlEscaped() + "</pre>" + lll;
} }
} }
@ -1906,7 +1906,7 @@ void Main::on_send_clicked()
{ {
dev::solidity::CompilerStack compiler; dev::solidity::CompilerStack compiler;
m_data = compiler.compile(src, m_enableOptimizer); m_data = compiler.compile(src, m_enableOptimizer);
for (std::string& s: compiler.getContractNames()) for (string& s: compiler.getContractNames())
{ {
h256 contractHash = compiler.getContractCodeHash(s); h256 contractHash = compiler.getContractCodeHash(s);
m_natspecDB.add(contractHash, m_natspecDB.add(contractHash,
@ -2053,7 +2053,7 @@ void Main::on_dumpTracePretty_triggered()
f << " STORAGE" << endl; f << " STORAGE" << endl;
for (auto const& i: ws.storage) for (auto const& i: ws.storage)
f << showbase << hex << i.first << ": " << i.second << endl; f << showbase << hex << i.first << ": " << i.second << endl;
f << dec << ws.levels.size() << " | " << ws.cur << " | #" << ws.steps << " | " << hex << setw(4) << setfill('0') << ws.curPC << " : " << dev::eth::instructionInfo(ws.inst).name << " | " << dec << ws.gas << " | -" << dec << ws.gasCost << " | " << ws.newMemSize << "x32"; f << dec << ws.levels.size() << " | " << ws.cur << " | #" << ws.steps << " | " << hex << setw(4) << setfill('0') << ws.curPC << " : " << instructionInfo(ws.inst).name << " | " << dec << ws.gas << " | -" << dec << ws.gasCost << " | " << ws.newMemSize << "x32";
} }
} }
@ -2280,7 +2280,7 @@ void Main::updateDebugger()
cwarn << "PC (" << (unsigned)ws.curPC << ") is after code range (" << m_codes[ws.code].size() << ")"; cwarn << "PC (" << (unsigned)ws.curPC << ") is after code range (" << m_codes[ws.code].size() << ")";
ostringstream ss; ostringstream ss;
ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << dev::eth::instructionInfo(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas; ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << instructionInfo(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas;
ui->debugStateInfo->setText(QString::fromStdString(ss.str())); ui->debugStateInfo->setText(QString::fromStdString(ss.str()));
stringstream s; stringstream s;
for (auto const& i: ws.storage) for (auto const& i: ws.storage)
@ -2302,12 +2302,12 @@ void Main::on_post_clicked()
whisper()->inject(m.seal(from, topicFromText(ui->shhTopic->toPlainText()), ui->shhTtl->value(), ui->shhWork->value())); whisper()->inject(m.seal(from, topicFromText(ui->shhTopic->toPlainText()), ui->shhTtl->value(), ui->shhWork->value()));
} }
std::string Main::lookupNatSpec(dev::h256 const& _contractHash) const string Main::lookupNatSpec(dev::h256 const& _contractHash) const
{ {
return m_natspecDB.retrieve(_contractHash); return m_natspecDB.retrieve(_contractHash);
} }
std::string Main::lookupNatSpecUserNotice(dev::h256 const& _contractHash, dev::bytes const& _transactionData) string Main::lookupNatSpecUserNotice(dev::h256 const& _contractHash, dev::bytes const& _transactionData)
{ {
return m_natspecDB.getUserNotice(_contractHash, _transactionData); return m_natspecDB.getUserNotice(_contractHash, _transactionData);
} }

Loading…
Cancel
Save