From 72c87a1241f55d4c311c73b2efa9ece954f6e88a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 4 Apr 2014 17:21:38 -0400 Subject: [PATCH] Version bump. Protocol bump. Support for configuration. --- alethzero/Main.ui | 7 +-- alethzero/MainWin.cpp | 95 +++++++++++++++++++++++++------------- libethereum/Client.cpp | 10 ++-- libethereum/PeerServer.cpp | 2 +- test/txTest.cpp | 6 +-- 5 files changed, 73 insertions(+), 47 deletions(-) diff --git a/alethzero/Main.ui b/alethzero/Main.ui index 2f0f8d502..60a22561b 100644 --- a/alethzero/Main.ui +++ b/alethzero/Main.ui @@ -457,13 +457,10 @@ Qt::Vertical - + Qt::NoFocus - - true - @@ -758,7 +755,7 @@ - + QDockWidget::DockWidgetFeatureMask diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index c5d0b2841..e358fc5d5 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -56,6 +56,31 @@ static void initUnits(QComboBox* _b) _b->addItem(QString::fromStdString(units()[n].second), n); } +string htmlDump(bytes const& _b, unsigned _w = 8) +{ + stringstream ret; + ret << "
";
+	for (unsigned i = 0; i < _b.size(); i += _w)
+	{
+		ret << hex << setw(4) << setfill('0') << i << " ";
+		for (unsigned j = i; j < i + _w; ++j)
+			if (j < _b.size())
+				if (_b[j] >= 32 && _b[j] < 128)
+					ret << (char)_b[j];
+				else ret << '?';
+			else
+				ret << ' ';
+		ret << " ";
+		for (unsigned j = i; j < i + _w && j < _b.size(); ++j)
+			ret << setfill('0') << setw(2) << hex << (unsigned)_b[j] << " ";
+		ret << "\n";
+	}
+	ret << "
"; + return ret.str(); +} + +Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250"); + Main::Main(QWidget *parent) : QMainWindow(parent), ui(new Ui::Main) @@ -98,6 +123,8 @@ Main::Main(QWidget *parent) : } #endif + ui->configDock->close(); + on_verbosity_sliderMoved(); initUnits(ui->gasPriceUnits); initUnits(ui->valueUnits); @@ -117,16 +144,17 @@ Main::~Main() writeSettings(); } -inline h256 fromAddress(Address _a) -{ - h256 ret; - memcpy(&ret, &_a, sizeof(_a)); - return ret; -} - QString Main::pretty(eth::Address _a) const { - if (h256 n = state().contractStorage(m_nameReg, fromAddress(_a))) + h256 n; + + if (h160 nameReg = (u160)state().contractStorage(c_config, 0)) + n = state().contractStorage(nameReg, (u160)(_a)); + + if (!n) + n = state().contractStorage(m_nameReg, (u160)(_a)); + + if (n) { std::string s((char const*)n.data(), 32); if (s.find_first_of('\0') != string::npos) @@ -153,8 +181,14 @@ Address Main::fromString(QString const& _a) const memcpy(n.data(), sn.data(), sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size()); if (_a.size()) + { + if (h160 nameReg = (u160)state().contractStorage(c_config, 0)) + if (h256 a = state().contractStorage(nameReg, n)) + return right160(a); + if (h256 a = state().contractStorage(m_nameReg, n)) return right160(a); + } if (_a.size() == 40) return Address(fromHex(_a.toStdString())); else @@ -223,10 +257,7 @@ void Main::readSettings() ui->clientName->setText(s.value("clientName", "").toString()); ui->idealPeers->setValue(s.value("idealPeers", ui->idealPeers->value()).toInt()); ui->port->setValue(s.value("port", ui->port->value()).toInt()); - if (s.value("nameReg").toString() == "c5c00217ce5acb4f0be2fb85929b11b8eeea0096") - s.remove("nameReg"); - ui->nameReg->setText(s.value("nameReg", "3f795321dd223e3d94c8f89b149ddab3b9c9b5d7").toString()); - + ui->nameReg->setText(s.value("NameReg", "").toString()); } void Main::on_nameReg_textChanged() @@ -237,6 +268,8 @@ void Main::on_nameReg_textChanged() m_nameReg = Address(fromHex(s)); refresh(true); } + else + m_nameReg = Address(); } void Main::refreshNetwork() @@ -411,20 +444,18 @@ void Main::on_blocks_currentItemChanged() s << "
Value: " << formatBalance(tx.value) << ""; s << "   #" << tx.nonce << ""; s << "
Gas price: " << formatBalance(tx.gasPrice) << ""; + s << "
Gas: " << tx.gas << ""; if (tx.isCreation()) { - s << "
Init:"; - s << "
" << disassemble(tx.init); - s << "
Code:"; - s << "
" << disassemble(tx.data); + if (tx.init.size()) + s << "

Init

" << disassemble(tx.init); + if (tx.data.size()) + s << "

Body

" << disassemble(tx.data); } else { - s << "
Gas: " << tx.gas << ""; - s << "
Data:    0x..." << setw(2) << setfill('0') << hex; - unsigned c = 0; - for (auto i: tx.data) - s << i << (c % 8 ? "" : " "); + if (tx.data.size()) + s << htmlDump(tx.data, 16); } } @@ -448,8 +479,7 @@ void Main::on_contracts_currentItemChanged() auto mem = state().contractStorage(h); for (auto const& i: mem) s << "@" << showbase << hex << i.first << "    " << showbase << hex << i.second << "
"; - s << "
Code:"; - s << "
" << disassemble(state().contractCode(h)); + s << "

Body Code

" << disassemble(state().contractCode(h)); ui->contractInfo->appendHtml(QString::fromStdString(s.str())); } m_client->unlock(); @@ -507,7 +537,7 @@ void Main::on_data_textChanged() string code = ui->data->toPlainText().toStdString(); m_init.clear(); m_data = compileLisp(code, true, m_init); - ui->code->setPlainText(QString::fromStdString(disassemble(m_data)) + "\n; Init:" + QString::fromStdString(disassemble(m_init))); + ui->code->setHtml((m_init.size() ? ("

Init

" + QString::fromStdString(disassemble(m_init)) + "
") : "") + "

Body

" + QString::fromStdString(disassemble(m_data)) + "
"); ui->gas->setMinimum((qint64)state().createGas(m_data.size() + m_init.size(), 0)); if (!ui->gas->isEnabled()) ui->gas->setValue(m_backupGas); @@ -526,27 +556,26 @@ void Main::on_data_textChanged() for (auto i: r.cap(1)) m_data.push_back((byte)i.toLatin1()); if (s[0] == '@') - m_data.push_back(0); - else for (int i = r.cap(1).size(); i < 32; ++i) m_data.push_back(0); + else + m_data.push_back(0); s = r.cap(2); } else if (h.exactMatch(s)) { + bytes bs = fromHex(h.cap(2).toStdString()); if (s[0] == '@') - { - bytes bs = fromHex(h.cap(2).toStdString()); - - for (auto b: bs) - m_data.push_back(b); - } + for (auto i = bs.size(); i < 32; ++i) + m_data.push_back(0); + for (auto b: bs) + m_data.push_back(b); s = h.cap(4); } else s = s.mid(1); } - ui->code->setPlainText(QString::fromStdString(toHex(m_data))); + ui->code->setHtml(QString::fromStdString(htmlDump(m_data))); if (m_client->postState().isContractAddress(fromString(ui->destination->text()))) { ui->gas->setMinimum((qint64)state().callGas(m_data.size(), 1)); diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8a35f4e9c..187f3dfad 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -62,11 +62,6 @@ Client::Client(std::string const& _clientVersion, Address _us, std::string const if (_dbPath.size()) Defaults::setDBPath(_dbPath); m_vc.setOk(); - - // Synchronise the state according to the head of the block chain. - // TODO: currently it contains keys for *all* blocks. Make it remove old ones. - m_preMine.sync(m_bc); - m_postMine = m_preMine; m_changed = true; static const char* c_threadName = "eth"; @@ -76,6 +71,11 @@ Client::Client(std::string const& _clientVersion, Address _us, std::string const while (m_workState.load(std::memory_order_acquire) != Deleting) work(); m_workState.store(Deleted, std::memory_order_release); + + // Synchronise the state according to the head of the block chain. + // TODO: currently it contains keys for *all* blocks. Make it remove old ones. + m_preMine.sync(m_bc); + m_postMine = m_preMine; })); } diff --git a/libethereum/PeerServer.cpp b/libethereum/PeerServer.cpp index e16bae671..b27a93e28 100644 --- a/libethereum/PeerServer.cpp +++ b/libethereum/PeerServer.cpp @@ -96,7 +96,7 @@ PeerServer::~PeerServer() unsigned PeerServer::protocolVersion() { - return 10; + return 11; } void PeerServer::determinePublic(string const& _publicAddress, bool _upnp) diff --git a/test/txTest.cpp b/test/txTest.cpp index d1a5566d1..02aa990d5 100644 --- a/test/txTest.cpp +++ b/test/txTest.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(mine_local_simple_tx) auto txAmount = c1bal / 2u; auto gasPrice = 10 * szabo; auto gas = eth::c_callGas; - c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes()); + c1.transact(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice); //mine some more to include the transaction on chain mine(c1, 1); @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(mine_and_send_to_peer) auto txAmount = c1bal / 2u; auto gasPrice = 10 * szabo; auto gas = eth::c_callGas; - c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes()); + c1.transact(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice); //mine some more to include the transaction on chain mine(c1, 1); @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(mine_and_send_to_peer_fee_check) auto txAmount = c1StartBalance / 2u; auto gasPrice = 10 * szabo; auto gas = eth::c_callGas; - c1.transact(kp1.secret(), txAmount, gasPrice, gas, c2.address(), bytes()); + c1.transact(kp1.secret(), txAmount, c2.address(), bytes(), gas, gasPrice); //mine some more, this time with second client (so he can get fees from first client's tx) mine(c2, 1);