Browse Source

Preview button to preview mined state.

New NameReg.
cl-refactor
Gav Wood 11 years ago
parent
commit
57ec5abf7b
  1. 2
      CMakeLists.txt
  2. 96
      alethzero/Main.ui
  3. 59
      alethzero/MainWin.cpp
  4. 7
      alethzero/MainWin.h
  5. 2
      libethereum/Client.h

2
CMakeLists.txt

@ -5,7 +5,7 @@ set(CMAKE_AUTOMOC ON)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
set(ETH_VERSION 0.3.5) set(ETH_VERSION 0.3.6)
set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE}) set(ETH_BUILD_TYPE ${CMAKE_BUILD_TYPE})
# Default HEADLESS to 0. # Default HEADLESS to 0.

96
alethzero/Main.ui

@ -40,6 +40,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -51,6 +54,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -70,6 +76,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -81,6 +90,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -142,10 +154,11 @@
</widget> </widget>
<widget class="QMenu" name="menu_Tools"> <widget class="QMenu" name="menu_Tools">
<property name="title"> <property name="title">
<string>&amp;Tools</string> <string>T&amp;ools</string>
</property> </property>
<addaction name="mine"/> <addaction name="mine"/>
<addaction name="create"/> <addaction name="create"/>
<addaction name="preview"/>
</widget> </widget>
<widget class="QMenu" name="menu_Help"> <widget class="QMenu" name="menu_Help">
<property name="title"> <property name="title">
@ -176,6 +189,9 @@
</property> </property>
<item> <item>
<widget class="QListWidget" name="accounts"> <widget class="QListWidget" name="accounts">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -205,6 +221,9 @@
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<widget class="QListWidget" name="peers"> <widget class="QListWidget" name="peers">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -237,21 +256,30 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Ideal Peers</string> <string>Ideal &amp;Peers</string>
</property>
<property name="buddy">
<cstring>idealPeers</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>Client Name</string> <string>&amp;Client Name</string>
</property>
<property name="buddy">
<cstring>clientName</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Listen on</string> <string>&amp;Listen on</string>
</property>
<property name="buddy">
<cstring>port</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -292,6 +320,9 @@
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -336,6 +367,9 @@
</property> </property>
<item> <item>
<widget class="QListWidget" name="transactionQueue"> <widget class="QListWidget" name="transactionQueue">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -356,6 +390,7 @@
</attribute> </attribute>
<addaction name="net"/> <addaction name="net"/>
<addaction name="connect"/> <addaction name="connect"/>
<addaction name="preview"/>
<addaction name="mine"/> <addaction name="mine"/>
</widget> </widget>
<widget class="QDockWidget" name="dockWidget_5"> <widget class="QDockWidget" name="dockWidget_5">
@ -391,14 +426,20 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>To</string> <string>&amp;To</string>
</property>
<property name="buddy">
<cstring>destination</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label5_2"> <widget class="QLabel" name="label5_2">
<property name="text"> <property name="text">
<string>Amount</string> <string>&amp;Amount</string>
</property>
<property name="buddy">
<cstring>value</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -411,11 +452,14 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Data</string> <string>&amp;Data</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property> </property>
<property name="buddy">
<cstring>data</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="4"> <item row="4" column="0" colspan="4">
@ -425,6 +469,9 @@
</property> </property>
<widget class="QPlainTextEdit" name="data"/> <widget class="QPlainTextEdit" name="data"/>
<widget class="QPlainTextEdit" name="code"> <widget class="QPlainTextEdit" name="code">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -434,7 +481,7 @@
<item row="5" column="3"> <item row="5" column="3">
<widget class="QPushButton" name="send"> <widget class="QPushButton" name="send">
<property name="text"> <property name="text">
<string>Send</string> <string>&amp;Send</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -517,6 +564,9 @@
</property> </property>
<item> <item>
<widget class="QListWidget" name="ourAccounts"> <widget class="QListWidget" name="ourAccounts">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
@ -589,8 +639,38 @@
<string>&amp;About...</string> <string>&amp;About...</string>
</property> </property>
</action> </action>
<action name="preview">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Preview</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>destination</tabstop>
<tabstop>calculatedName</tabstop>
<tabstop>value</tabstop>
<tabstop>valueUnits</tabstop>
<tabstop>data</tabstop>
<tabstop>code</tabstop>
<tabstop>send</tabstop>
<tabstop>idealPeers</tabstop>
<tabstop>port</tabstop>
<tabstop>clientName</tabstop>
<tabstop>verbosity</tabstop>
<tabstop>transactionQueue</tabstop>
<tabstop>accounts</tabstop>
<tabstop>peers</tabstop>
<tabstop>log</tabstop>
<tabstop>blocks</tabstop>
<tabstop>info</tabstop>
<tabstop>contractInfo</tabstop>
<tabstop>contracts</tabstop>
<tabstop>ourAccounts</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

59
alethzero/MainWin.cpp

@ -75,6 +75,8 @@ Main::Main(QWidget *parent) :
connect(m_refreshNetwork, SIGNAL(timeout()), SLOT(refreshNetwork())); connect(m_refreshNetwork, SIGNAL(timeout()), SLOT(refreshNetwork()));
m_refreshNetwork->start(1000); m_refreshNetwork->start(1000);
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved()));
#if ETH_DEBUG #if ETH_DEBUG
m_servers.append("192.168.0.10:30301"); m_servers.append("192.168.0.10:30301");
#else #else
@ -103,10 +105,11 @@ Main::~Main()
writeSettings(); writeSettings();
} }
static const Address c_nameContract(fromUserHex("1f4b51662f3d7aaefa3f71df914f5d17428d6240"));
QString Main::pretty(eth::Address _a) const QString Main::pretty(eth::Address _a) const
{ {
static const Address c_nameContract(fromUserHex("f28e4d396cfc7bae483e464221b0d2bd3c27f21f")); if (h256 n = state().contractMemory(c_nameContract, (h256)(u256)(u160)_a))
if (h256 n = m_client->state().contractMemory(c_nameContract, (h256)(u256)(u160)_a))
{ {
std::string s((char const*)n.data(), 32); std::string s((char const*)n.data(), 32);
s.resize(s.find_first_of('\0')); s.resize(s.find_first_of('\0'));
@ -125,7 +128,6 @@ QString Main::render(eth::Address _a) const
Address Main::fromString(QString const& _a) const Address Main::fromString(QString const& _a) const
{ {
static const Address c_nameContract(fromUserHex("f28e4d396cfc7bae483e464221b0d2bd3c27f21f"));
string sn = _a.toStdString(); string sn = _a.toStdString();
if (sn.size() > 32) if (sn.size() > 32)
sn.resize(32); sn.resize(32);
@ -133,7 +135,7 @@ Address Main::fromString(QString const& _a) const
memcpy(n.data(), sn.data(), sn.size()); memcpy(n.data(), sn.data(), sn.size());
memset(n.data() + sn.size(), 0, 32 - sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size());
if (_a.size()) if (_a.size())
if (h256 a = m_client->state().contractMemory(c_nameContract, n)) if (h256 a = state().contractMemory(c_nameContract, n))
return right160(a); return right160(a);
if (_a.size() == 40) if (_a.size() == 40)
return Address(fromUserHex(_a.toStdString())); return Address(fromUserHex(_a.toStdString()));
@ -214,17 +216,24 @@ void Main::refreshNetwork()
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())); 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()));
} }
void Main::refresh() eth::State const& Main::state() const
{
return ui->preview->isChecked() ? m_client->postState() : m_client->state();
}
void Main::refresh(bool _override)
{ {
m_client->lock(); m_client->lock();
auto const& st = state();
bool c = m_client->changed(); bool c = m_client->changed();
if (c) if (c || _override)
{ {
auto d = m_client->blockChain().details(); auto d = m_client->blockChain().details();
auto diff = BlockInfo(m_client->blockChain().block()).difficulty; auto diff = BlockInfo(m_client->blockChain().block()).difficulty;
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)));
auto acs = m_client->state().addresses(); auto acs = st.addresses();
ui->accounts->clear(); ui->accounts->clear();
ui->contracts->clear(); ui->contracts->clear();
for (auto n = 0; n < 2; ++n) for (auto n = 0; n < 2; ++n)
@ -233,10 +242,10 @@ void Main::refresh()
auto r = render(i.first); auto r = render(i.first);
if (r.contains('(') == !n) if (r.contains('(') == !n)
{ {
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(i.second).c_str()).arg(r).arg((unsigned)m_client->state().transactionsFrom(i.first)), ui->accounts)) (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(i.second).c_str()).arg(r).arg((unsigned)state().transactionsFrom(i.first)), ui->accounts))
->setData(Qt::UserRole, QByteArray((char const*)i.first.data(), Address::size)); ->setData(Qt::UserRole, QByteArray((char const*)i.first.data(), Address::size));
if (m_client->state().isContractAddress(i.first)) if (st.isContractAddress(i.first))
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(i.second).c_str()).arg(r).arg((unsigned)m_client->state().transactionsFrom(i.first)), ui->contracts)) (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(i.second).c_str()).arg(r).arg((unsigned)st.transactionsFrom(i.first)), ui->contracts))
->setData(Qt::UserRole, QByteArray((char const*)i.first.data(), Address::size)); ->setData(Qt::UserRole, QByteArray((char const*)i.first.data(), Address::size));
} }
} }
@ -250,7 +259,7 @@ void Main::refresh()
.arg(render(t.safeSender())) .arg(render(t.safeSender()))
.arg(render(t.receiveAddress)) .arg(render(t.receiveAddress))
.arg((unsigned)t.nonce) .arg((unsigned)t.nonce)
.arg(m_client->state().isContractAddress(t.receiveAddress) ? '*' : '-') : .arg(st.isContractAddress(t.receiveAddress) ? '*' : '-') :
QString("%2 +> %3: %1 [%4]") QString("%2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str()) .arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender())) .arg(render(t.safeSender()))
@ -276,7 +285,7 @@ void Main::refresh()
.arg(render(t.safeSender())) .arg(render(t.safeSender()))
.arg(render(t.receiveAddress)) .arg(render(t.receiveAddress))
.arg((unsigned)t.nonce) .arg((unsigned)t.nonce)
.arg(m_client->state().isContractAddress(t.receiveAddress) ? '*' : '-') : .arg(st.isContractAddress(t.receiveAddress) ? '*' : '-') :
QString(" %2 +> %3: %1 [%4]") QString(" %2 +> %3: %1 [%4]")
.arg(formatBalance(t.value).c_str()) .arg(formatBalance(t.value).c_str())
.arg(render(t.safeSender())) .arg(render(t.safeSender()))
@ -297,8 +306,8 @@ void Main::refresh()
u256 totalBalance = 0; u256 totalBalance = 0;
for (auto i: m_myKeys) for (auto i: m_myKeys)
{ {
u256 b = m_client->state().balance(i.address()); u256 b = st.balance(i.address());
(new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)m_client->state().transactionsFrom(i.address())), ui->ourAccounts)) (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(b).c_str()).arg(render(i.address())).arg((unsigned)st.transactionsFrom(i.address())), ui->ourAccounts))
->setData(Qt::UserRole, QByteArray((char const*)i.address().data(), Address::size)); ->setData(Qt::UserRole, QByteArray((char const*)i.address().data(), Address::size));
totalBalance += b; totalBalance += b;
} }
@ -307,6 +316,20 @@ void Main::refresh()
m_client->unlock(); m_client->unlock();
} }
void Main::ourAccountsRowsMoved()
{
QVector<KeyPair> myKeys;
for (int i = 0; i < ui->ourAccounts->count(); ++i)
{
auto hba = ui->ourAccounts->item(i)->data(Qt::UserRole).toByteArray();
auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer);
for (auto i: m_myKeys)
if (i.address() == h)
myKeys.push_back(i);
}
m_myKeys = myKeys;
}
void Main::on_blocks_currentItemChanged() void Main::on_blocks_currentItemChanged()
{ {
ui->info->clear(); ui->info->clear();
@ -380,7 +403,7 @@ void Main::on_contracts_currentItemChanged()
auto h = h160((byte const*)hba.data(), h160::ConstructFromPointer); auto h = h160((byte const*)hba.data(), h160::ConstructFromPointer);
stringstream s; stringstream s;
auto mem = m_client->state().contractMemory(h); auto mem = state().contractMemory(h);
u256 next = 0; u256 next = 0;
unsigned numerics = 0; unsigned numerics = 0;
bool unexpectedNumeric = false; bool unexpectedNumeric = false;
@ -476,7 +499,7 @@ void Main::on_data_textChanged()
u256 Main::fee() const u256 Main::fee() const
{ {
return (ui->destination->text().isEmpty() || !ui->destination->text().toInt()) ? m_client->state().fee(m_data.size()) : m_client->state().fee(); return (ui->destination->text().isEmpty() || !ui->destination->text().toInt()) ? state().fee(m_data.size()) : state().fee();
} }
u256 Main::value() const u256 Main::value() const
@ -497,7 +520,7 @@ void Main::updateFee()
bool ok = false; bool ok = false;
for (auto i: m_myKeys) for (auto i: m_myKeys)
if (m_client->state().balance(i.address()) >= totalReq) if (state().balance(i.address()) >= totalReq)
{ {
ok = true; ok = true;
break; break;
@ -565,7 +588,7 @@ void Main::on_send_clicked()
u256 totalReq = value() + fee(); u256 totalReq = value() + fee();
m_client->lock(); m_client->lock();
for (auto i: m_myKeys) for (auto i: m_myKeys)
if (m_client->state().balance(i.address()) >= totalReq/* && i.address() != Address(fromUserHex(ui->destination->text().toStdString()))*/) if (m_client->state().balance(i.address()) >= totalReq )
{ {
m_client->unlock(); m_client->unlock();
Secret s = i.secret(); Secret s = i.secret();

7
alethzero/MainWin.h

@ -13,6 +13,7 @@ class Main;
namespace eth { namespace eth {
class Client; class Client;
class State;
} }
class Main : public QMainWindow class Main : public QMainWindow
@ -31,6 +32,7 @@ private slots:
void on_net_triggered(); void on_net_triggered();
void on_verbosity_sliderMoved(); void on_verbosity_sliderMoved();
void on_ourAccounts_doubleClicked(); void on_ourAccounts_doubleClicked();
void ourAccountsRowsMoved();
void on_accounts_doubleClicked(); void on_accounts_doubleClicked();
void on_destination_textChanged(); void on_destination_textChanged();
void on_data_textChanged(); void on_data_textChanged();
@ -42,9 +44,10 @@ private slots:
void on_contracts_doubleClicked(); void on_contracts_doubleClicked();
void on_contracts_currentItemChanged(); void on_contracts_currentItemChanged();
void on_about_triggered(); void on_about_triggered();
void on_preview_triggered() { refresh(true); }
void on_quit_triggered() { close(); } void on_quit_triggered() { close(); }
void refresh(); void refresh(bool _override = false);
void refreshNetwork(); void refreshNetwork();
private: private:
@ -53,6 +56,8 @@ private:
QString render(eth::Address _a) const; QString render(eth::Address _a) const;
eth::Address fromString(QString const& _a) const; eth::Address fromString(QString const& _a) const;
eth::State const& state() const;
void updateFee(); void updateFee();
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();

2
libethereum/Client.h

@ -99,6 +99,8 @@ public:
/// Get the object representing the current state of Ethereum. /// Get the object representing the current state of Ethereum.
State const& state() const { return m_preMine; } State const& state() const { return m_preMine; }
/// Get the object representing the current state of Ethereum.
State const& postState() const { return m_postMine; }
/// Get the object representing the current canonical blockchain. /// Get the object representing the current canonical blockchain.
BlockChain const& blockChain() const { return m_bc; } BlockChain const& blockChain() const { return m_bc; }
/// Get a map containing each of the pending transactions. /// Get a map containing each of the pending transactions.

Loading…
Cancel
Save