Browse Source

Filter on block chain.

cl-refactor
Gav Wood 11 years ago
parent
commit
3fcea05035
  1. 17
      alethzero/Main.ui
  2. 123
      alethzero/MainWin.cpp
  3. 2
      alethzero/MainWin.h

17
alethzero/Main.ui

@ -117,7 +117,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1711</width> <width>1711</width>
<height>27</height> <height>25</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_File"> <widget class="QMenu" name="menu_File">
@ -808,7 +808,7 @@
<number>2</number> <number>2</number>
</attribute> </attribute>
<widget class="QWidget" name="dockWidgetContents_8"> <widget class="QWidget" name="dockWidgetContents_8">
<layout class="QHBoxLayout" name="horizontalLayout_8"> <layout class="QVBoxLayout" name="verticalLayout_7">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -821,6 +821,19 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QLineEdit" name="blockChainFilter">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QSplitter" name="splitter_2"> <widget class="QSplitter" name="splitter_2">
<property name="orientation"> <property name="orientation">

123
alethzero/MainWin.cpp

@ -558,6 +558,95 @@ void Main::updateBlockCount()
ui->blockCount->setText(QString("#%1 @%3 T%2").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff))); ui->blockCount->setText(QString("#%1 @%3 T%2").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)));
} }
void Main::on_blockChainFilter_textChanged()
{
static QTimer* s_delayed = nullptr;
if (!s_delayed)
{
s_delayed = new QTimer(this);
s_delayed->setSingleShot(true);
connect(s_delayed, SIGNAL(timeout()), SLOT(refreshBlockChain()));
}
s_delayed->stop();
s_delayed->start(200);
}
static bool blockMatch(string const& _f, eth::BlockDetails const& _b, h256 _h)
{
try
{
if (_f.size() > 1 && _f.size() < 10 && _f[0] == '#' && stoul(_f.substr(1)) == _b.number)
return true;
}
catch (...) {}
if (toHex(_h.ref()).find(_f) != string::npos)
return true;
return false;
}
static bool transactionMatch(string const& _f, Transaction const& _t)
{
string info = toHex(_t.receiveAddress.ref()) + " " + toHex(_t.sha3(true).ref()) + " " + toHex(_t.sha3(false).ref()) + " " + toHex(_t.sender().ref());
if (info.find(_f) != string::npos)
return true;
return false;
}
void Main::refreshBlockChain()
{
eth::ClientGuard g(m_client.get());
auto const& st = state();
QByteArray oldSelected = ui->blocks->count() ? ui->blocks->currentItem()->data(Qt::UserRole).toByteArray() : QByteArray();
ui->blocks->clear();
string filter = ui->blockChainFilter->text().toLower().toStdString();
auto const& bc = m_client->blockChain();
unsigned i = (ui->showAll->isChecked() || !filter.empty()) ? (unsigned)-1 : 10;
for (auto h = bc.currentHash(); h != bc.genesisHash() && i; h = bc.details(h).parent, --i)
{
auto d = bc.details(h);
if (blockMatch(filter, d, h))
{
QListWidgetItem* blockItem = new QListWidgetItem(QString("#%1 %2").arg(d.number).arg(h.abridged().c_str()), ui->blocks);
auto hba = QByteArray((char const*)h.data(), h.size);
blockItem->setData(Qt::UserRole, hba);
if (oldSelected == hba)
blockItem->setSelected(true);
}
int n = 0;
for (auto const& i: RLP(bc.block(h))[1])
{
Transaction t(i[0].data());
if (transactionMatch(filter, t))
{
QString s = t.receiveAddress ?
QString(" %2 %5> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
.arg(render(t.receiveAddress))
.arg((unsigned)t.nonce)
.arg(st.addressHasCode(t.receiveAddress) ? '*' : '-') :
QString(" %2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
.arg(render(right160(sha3(rlpList(t.safeSender(), t.nonce)))))
.arg((unsigned)t.nonce);
QListWidgetItem* txItem = new QListWidgetItem(s, ui->blocks);
auto hba = QByteArray((char const*)h.data(), h.size);
txItem->setData(Qt::UserRole, hba);
txItem->setData(Qt::UserRole + 1, n);
if (oldSelected == hba)
txItem->setSelected(true);
}
n++;
}
}
if (!ui->blocks->currentItem())
ui->blocks->setCurrentRow(0);
}
void Main::refresh(bool _override) void Main::refresh(bool _override)
{ {
eth::ClientGuard g(m_client.get()); eth::ClientGuard g(m_client.get());
@ -618,36 +707,7 @@ void Main::refresh(bool _override)
ui->transactionQueue->addItem(s); ui->transactionQueue->addItem(s);
} }
ui->blocks->clear(); refreshBlockChain();
auto const& bc = m_client->blockChain();
unsigned i = ui->showAll->isChecked() ? (unsigned)-1 : 100;
for (auto h = bc.currentHash(); h != bc.genesisHash() && i; h = bc.details(h).parent, --i)
{
auto d = bc.details(h);
QListWidgetItem* blockItem = new QListWidgetItem(QString("#%1 %2").arg(d.number).arg(h.abridged().c_str()), ui->blocks);
blockItem->setData(Qt::UserRole, QByteArray((char const*)h.data(), h.size));
int n = 0;
for (auto const& i: RLP(bc.block(h))[1])
{
Transaction t(i[0].data());
QString s = t.receiveAddress ?
QString(" %2 %5> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
.arg(render(t.receiveAddress))
.arg((unsigned)t.nonce)
.arg(st.addressHasCode(t.receiveAddress) ? '*' : '-') :
QString(" %2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender()))
.arg(render(right160(sha3(rlpList(t.safeSender(), t.nonce)))))
.arg((unsigned)t.nonce);
QListWidgetItem* txItem = new QListWidgetItem(s, ui->blocks);
txItem->setData(Qt::UserRole, QByteArray((char const*)h.data(), h.size));
txItem->setData(Qt::UserRole + 1, n);
n++;
}
}
} }
if (c || m_keysChanged || _override) if (c || m_keysChanged || _override)
@ -1145,11 +1205,8 @@ void Main::on_debug_clicked()
for (auto i: m_myKeys) for (auto i: m_myKeys)
if (m_client->state().balance(i.address()) >= totalReq) if (m_client->state().balance(i.address()) >= totalReq)
{ {
m_client->unlock();
Secret s = i.secret(); Secret s = i.secret();
m_client->lock();
m_executiveState = state(); m_executiveState = state();
m_client->unlock();
m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState)); m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState));
Transaction t; Transaction t;
t.nonce = m_executiveState.transactionsFrom(toAddress(s)); t.nonce = m_executiveState.transactionsFrom(toAddress(s));

2
alethzero/MainWin.h

@ -111,10 +111,12 @@ private slots:
void on_showAll_triggered() { refresh(true); } void on_showAll_triggered() { refresh(true); }
void on_showAllAccounts_triggered() { refresh(true); } void on_showAllAccounts_triggered() { refresh(true); }
void on_loadJS_triggered(); void on_loadJS_triggered();
void on_blockChainFilter_textChanged();
void refresh(bool _override = false); void refresh(bool _override = false);
void refreshNetwork(); void refreshNetwork();
void refreshMining(); void refreshMining();
void refreshBlockChain();
signals: signals:
void changed(); // TODO: manifest void changed(); // TODO: manifest

Loading…
Cancel
Save