From 4cb79936558282a805f306d4db75f6063d1d5dd8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 5 Sep 2014 17:09:58 +0200 Subject: [PATCH] Project-wide reorganisation of namespaces. --- CMakeLists.txt | 4 +- alethzero/MainWin.cpp | 184 +++++++++++++++---------------- alethzero/MainWin.h | 72 ++++++------ alethzero/MiningView.cpp | 13 ++- alethzero/MiningView.h | 9 +- eth/CommonJS.cpp | 11 +- eth/CommonJS.h | 33 +++--- eth/EthStubServer.cpp | 5 +- eth/EthStubServer.h | 11 +- eth/main.cpp | 55 ++++----- exp/main.cpp | 12 +- libethcore/BlockInfo.cpp | 7 +- libethcore/BlockInfo.h | 5 +- libethcore/CommonEth.cpp | 23 ++-- libethcore/CommonEth.h | 3 + libethcore/Dagger.cpp | 8 +- libethcore/Dagger.h | 16 +-- libethcore/Exceptions.h | 67 +++++------ libethcore/FileSystem.cpp | 5 +- libethcore/FileSystem.h | 3 + libethcore/MemoryDB.cpp | 6 +- libethcore/MemoryDB.h | 5 +- libethcore/OverlayDB.cpp | 6 +- libethcore/OverlayDB.h | 8 ++ libethcore/SHA3.cpp | 20 +++- libethcore/SHA3.h | 3 + libethcore/TrieCommon.cpp | 29 ++--- libethcore/TrieCommon.h | 29 ++--- libethcore/TrieDB.cpp | 9 +- libethcore/TrieDB.h | 24 +++- libethential/Common.cpp | 7 +- libethential/Common.h | 19 ++-- libethential/CommonData.cpp | 16 +-- libethential/CommonData.h | 18 +-- libethential/CommonIO.cpp | 8 +- libethential/CommonIO.h | 2 +- libethential/Exceptions.h | 2 +- libethential/FixedHash.cpp | 4 +- libethential/FixedHash.h | 10 +- libethential/Guards.cpp | 4 +- libethential/Guards.h | 2 +- libethential/Log.cpp | 12 +- libethential/Log.h | 18 +-- libethential/RLP.cpp | 42 +++---- libethential/RLP.h | 68 ++++++------ libethential/vector_ref.h | 12 +- libethereum/AccountDiff.cpp | 13 ++- libethereum/AccountDiff.h | 9 +- libethereum/AddressState.cpp | 3 +- libethereum/AddressState.h | 4 +- libethereum/BlockChain.cpp | 25 +++-- libethereum/BlockChain.h | 12 +- libethereum/BlockDetails.cpp | 5 +- libethereum/BlockDetails.h | 12 +- libethereum/BlockQueue.cpp | 3 +- libethereum/BlockQueue.h | 5 +- libethereum/Client.cpp | 3 +- libethereum/Client.h | 28 +++-- libethereum/CommonNet.cpp | 3 +- libethereum/CommonNet.h | 11 +- libethereum/Defaults.cpp | 3 +- libethereum/Defaults.h | 3 + libethereum/EthereumHost.cpp | 5 +- libethereum/EthereumHost.h | 7 +- libethereum/EthereumPeer.cpp | 9 +- libethereum/EthereumPeer.h | 5 +- libethereum/Executive.cpp | 7 +- libethereum/Executive.h | 3 + libethereum/ExtVM.h | 4 +- libethereum/Manifest.cpp | 3 +- libethereum/Manifest.h | 3 + libethereum/MessageFilter.cpp | 5 +- libethereum/MessageFilter.h | 3 + libethereum/Miner.cpp | 3 +- libethereum/Miner.h | 7 +- libethereum/PastMessage.cpp | 3 +- libethereum/PastMessage.h | 3 + libethereum/State.cpp | 11 +- libethereum/State.h | 6 +- libethereum/Transaction.cpp | 5 +- libethereum/Transaction.h | 9 +- libethereum/TransactionQueue.cpp | 3 +- libethereum/TransactionQueue.h | 4 +- libethereum/Utility.cpp | 13 ++- libethereum/Utility.h | 3 + libethereumx/Ethereum.cpp | 3 +- libethereumx/Ethereum.h | 3 + libevm/ExtVMFace.cpp | 3 +- libevm/ExtVMFace.h | 3 + libevm/FeeStructure.cpp | 23 ++-- libevm/FeeStructure.h | 3 + libevm/VM.cpp | 3 +- libevm/VM.h | 10 +- libevmface/Instruction.cpp | 11 +- libevmface/Instruction.h | 3 + liblll/Assembly.cpp | 17 +-- liblll/Assembly.h | 3 + liblll/CodeFragment.cpp | 3 +- liblll/CodeFragment.h | 3 + liblll/Compiler.cpp | 9 +- liblll/Compiler.h | 4 +- liblll/CompilerState.cpp | 3 +- liblll/CompilerState.h | 3 + liblll/Exceptions.h | 7 +- liblll/Parser.cpp | 15 +-- liblll/Parser.h | 4 +- libp2p/CMakeLists.txt | 1 + libp2p/Capability.cpp | 4 +- libp2p/Capability.h | 3 + libp2p/Common.cpp | 4 +- libp2p/Common.h | 13 +-- libp2p/Host.cpp | 4 +- libp2p/Host.h | 8 +- libp2p/HostCapability.cpp | 4 +- libp2p/HostCapability.h | 5 + libp2p/Session.cpp | 6 +- libp2p/Session.h | 6 +- libp2p/UPnP.cpp | 4 +- libp2p/UPnP.h | 3 + libqethereum/QEthereum.cpp | 103 ++++++++--------- libqethereum/QEthereum.h | 90 +++++++-------- libqethereum/QmlEthereum.cpp | 60 +++++----- libqethereum/QmlEthereum.h | 168 ++++++++++++++-------------- libwebthree/CMakeLists.txt | 69 ++++++++++++ libwebthree/Client.cpp | 172 +++++++++++++++++++++++++++++ libwebthree/Client.h | 101 +++++++++++++++++ libwhisper/Common.cpp | 6 +- libwhisper/Common.h | 21 ++-- libwhisper/WhisperPeer.cpp | 8 +- libwhisper/WhisperPeer.h | 23 ++-- lllc/main.cpp | 7 +- neth/main.cpp | 31 +++--- test/MemTrie.cpp | 14 ++- test/MemTrie.h | 2 +- test/TestHelper.cpp | 6 +- test/TestHelper.h | 5 + test/TrieHash.cpp | 13 ++- test/TrieHash.h | 2 +- test/crypto.cpp | 5 +- test/dagger.cpp | 3 +- test/fork.cpp | 3 +- test/genesis.cpp | 3 +- test/hexPrefix.cpp | 3 +- test/main.cpp | 3 +- test/network.cpp | 3 +- test/peer.cpp | 4 +- test/rlp.cpp | 18 +-- test/state.cpp | 3 +- test/trie.cpp | 23 ++-- test/txTest.cpp | 9 +- test/vm.cpp | 13 ++- third/MainWin.cpp | 104 ++++++++--------- third/MainWin.h | 22 ++-- walleth/MainWin.cpp | 74 ++++++------- walleth/MainWin.h | 24 ++-- 155 files changed, 1602 insertions(+), 1012 deletions(-) create mode 100644 libwebthree/CMakeLists.txt create mode 100644 libwebthree/Client.cpp create mode 100644 libwebthree/Client.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fcadd4be5..92d2986e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,9 +343,9 @@ if (NOT LANGUAGES) add_subdirectory(libethcore) add_subdirectory(libevm) add_subdirectory(libethereum) - add_subdirectory(libethereumx) # TODO remove +# add_subdirectory(libethereumx) # TODO remove - #add_subdirectory(libwebthree) + add_subdirectory(libwebthree) add_subdirectory(test) add_subdirectory(eth) if("x${CMAKE_BUILD_TYPE}" STREQUAL "xDebug") diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 8a78a2e7f..374f8a209 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -45,51 +45,51 @@ using namespace std; // types -using eth::bytes; -using eth::bytesConstRef; -using eth::h160; -using eth::h256; -using eth::u160; -using eth::u256; -using eth::Address; -using eth::BlockInfo; -using eth::Client; -using eth::Instruction; -using eth::KeyPair; -using eth::NodeMode; -using eth::BlockChain; -using p2p::PeerInfo; -using eth::RLP; -using eth::Secret; -using eth::Transaction; -using eth::Executive; +using dev::bytes; +using dev::bytesConstRef; +using dev::h160; +using dev::h256; +using dev::u160; +using dev::u256; +using dev::eth::Address; +using dev::eth::BlockInfo; +using dev::eth::Client; +using dev::eth::Instruction; +using dev::eth::KeyPair; +using dev::eth::NodeMode; +using dev::eth::BlockChain; +using dev::p2p::PeerInfo; +using dev::RLP; +using dev::eth::Secret; +using dev::eth::Transaction; +using dev::eth::Executive; // functions -using eth::toHex; -using eth::compileLLL; -using eth::disassemble; -using eth::formatBalance; -using eth::fromHex; -using eth::sha3; -using eth::left160; -using eth::right160; -using eth::simpleDebugOut; -using eth::toLog2; -using eth::toString; -using eth::units; -using eth::operator<<; +using dev::toHex; +using dev::fromHex; +using dev::left160; +using dev::right160; +using dev::simpleDebugOut; +using dev::toLog2; +using dev::toString; +using dev::operator<<; +using dev::eth::units; +using dev::eth::sha3; +using dev::eth::compileLLL; +using dev::eth::disassemble; +using dev::eth::formatBalance; // vars -using eth::g_logPost; -using eth::g_logVerbosity; +using dev::g_logPost; +using dev::g_logVerbosity; static void initUnits(QComboBox* _b) { - for (auto n = (::uint)units().size(); n-- != 0; ) + for (auto n = (unsigned)units().size(); n-- != 0; ) _b->addItem(QString::fromStdString(units()[n].second), n); } -static QString fromRaw(eth::h256 _n, unsigned* _inc = nullptr) +static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr) { if (_n) { @@ -136,7 +136,7 @@ Main::Main(QWidget *parent) : #if 0&Ð_DEBUG m_servers.append("192.168.0.10:30301"); #else - int pocnumber = QString(eth::EthVersion).section('.', 1, 1).toInt(); + int pocnumber = QString(dev::Version).section('.', 1, 1).toInt(); if (pocnumber == 5) m_servers.push_back("54.72.69.180:30303"); else if (pocnumber == 6) @@ -158,8 +158,8 @@ Main::Main(QWidget *parent) : cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl; cerr << "Block RLP: " << RLP(BlockChain::createGenesisBlock()) << endl; cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl; - cerr << "Network protocol version: " << eth::c_protocolVersion << endl; - cerr << "Client database version: " << eth::c_databaseVersion << endl; + cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl; + cerr << "Client database version: " << dev::eth::c_databaseVersion << endl; ui->configDock->close(); on_verbosity_valueChanged(); @@ -231,14 +231,14 @@ void Main::onKeysChanged() installBalancesWatch(); } -unsigned Main::installWatch(eth::MessageFilter const& _tf, std::function const& _f) +unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function const& _f) { auto ret = m_client->installWatch(_tf); m_handlers[ret] = _f; return ret; } -unsigned Main::installWatch(eth::h256 _tf, std::function const& _f) +unsigned Main::installWatch(dev::h256 _tf, std::function const& _f) { auto ret = m_client->installWatch(_tf); m_handlers[ret] = _f; @@ -247,27 +247,27 @@ unsigned Main::installWatch(eth::h256 _tf, std::function const& _f) void Main::installWatches() { - installWatch(eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); }); - installWatch(eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); }); - installWatch(eth::PendingChangedFilter, [=](){ onNewPending(); }); - installWatch(eth::ChainChangedFilter, [=](){ onNewBlock(); }); + installWatch(dev::eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); }); + installWatch(dev::eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); }); + installWatch(dev::eth::PendingChangedFilter, [=](){ onNewPending(); }); + installWatch(dev::eth::ChainChangedFilter, [=](){ onNewBlock(); }); } void Main::installNameRegWatch() { m_client->uninstallWatch(m_nameRegFilter); - m_nameRegFilter = installWatch(eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 0)), [=](){ onNameRegChange(); }); + m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 0)), [=](){ onNameRegChange(); }); } void Main::installCurrenciesWatch() { m_client->uninstallWatch(m_currenciesFilter); - m_currenciesFilter = installWatch(eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); }); + m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); }); } void Main::installBalancesWatch() { - eth::MessageFilter tf; + dev::eth::MessageFilter tf; vector
altCoins; Address coinsAddr = right160(m_client->stateAt(c_config, 1)); @@ -417,7 +417,7 @@ void Main::eval(QString const& _js) ui->jsConsole->setHtml(s); } -QString Main::pretty(eth::Address _a) const +QString Main::pretty(dev::eth::Address _a) const { h256 n; @@ -430,7 +430,7 @@ QString Main::pretty(eth::Address _a) const return fromRaw(n); } -QString Main::render(eth::Address _a) const +QString Main::render(dev::eth::Address _a) const { QString p = pretty(_a); if (!p.isNull()) @@ -500,7 +500,7 @@ QString Main::lookup(QString const& _a) const void Main::on_about_triggered() { - QMessageBox::about(this, "About AlethZero PoC-" + QString(eth::EthVersion).section('.', 1, 1), QString("AlethZero/v") + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM) "\n" ETH_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); + QMessageBox::about(this, "About AlethZero PoC-" + QString(dev::Version).section('.', 1, 1), QString("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); } void Main::on_paranoia_triggered() @@ -670,18 +670,18 @@ void Main::on_preview_triggered() void Main::refreshMining() { - eth::MineProgress p = m_client->miningProgress(); + dev::eth::MineProgress p = m_client->miningProgress(); ui->mineStatus->setText(m_client->isMining() ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Not mining"); if (!ui->miningView->isVisible()) return; - list l = m_client->miningHistory(); - static uint lh = 0; + list l = m_client->miningHistory(); + static unsigned lh = 0; if (p.hashes < lh) ui->miningView->resetStats(); lh = p.hashes; ui->miningView->appendStats(l, p); /* if (p.ms) - for (eth::MineInfo const& i: l) + for (dev::eth::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"; */ } @@ -808,10 +808,10 @@ void Main::refreshBlockCount() cwatch << "refreshBlockCount()"; auto d = m_client->blockChain().details(); auto diff = BlockInfo(m_client->blockChain().block()).difficulty; - ui->blockCount->setText(QString("%6 #%1 @%3 T%2 N%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(eth::c_protocolVersion).arg(eth::c_databaseVersion).arg(m_privateChain.size() ? "[" + m_privateChain + "] " : "testnet")); + ui->blockCount->setText(QString("%6 #%1 @%3 T%2 N%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")); } -static bool blockMatch(string const& _f, eth::BlockDetails const& _b, h256 _h, BlockChain const& _bc) +static bool blockMatch(string const& _f, dev::eth::BlockDetails const& _b, h256 _h, BlockChain const& _bc) { try { @@ -951,7 +951,7 @@ void Main::timerEvent(QTimerEvent*) i.second(); } -string Main::renderDiff(eth::StateDiff const& _d) const +string Main::renderDiff(dev::eth::StateDiff const& _d) const { stringstream s; @@ -960,7 +960,7 @@ string Main::renderDiff(eth::StateDiff const& _d) const { s << "
"; - eth::AccountDiff const& ad = i.second; + dev::eth::AccountDiff const& ad = i.second; s << "" << ad.lead() << " " << " " << render(i.first).toStdString() << ""; if (!ad.exist.to()) continue; @@ -968,12 +968,12 @@ string Main::renderDiff(eth::StateDiff const& _d) const if (ad.balance) { s << "
" << indent << "Balance " << std::dec << formatBalance(ad.balance.to()); - s << " " << std::showpos << (((eth::bigint)ad.balance.to()) - ((eth::bigint)ad.balance.from())) << std::noshowpos << ""; + s << " " << std::showpos << (((dev::bigint)ad.balance.to()) - ((dev::bigint)ad.balance.from())) << std::noshowpos << ""; } if (ad.nonce) { s << "
" << indent << "Count #" << std::dec << ad.nonce.to(); - s << " " << std::showpos << (((eth::bigint)ad.nonce.to()) - ((eth::bigint)ad.nonce.from())) << std::noshowpos << ""; + s << " " << std::showpos << (((dev::bigint)ad.nonce.to()) - ((dev::bigint)ad.nonce.from())) << std::noshowpos << ""; } if (ad.code) { @@ -982,7 +982,7 @@ string Main::renderDiff(eth::StateDiff const& _d) const s << " (" << ad.code.from().size() << " bytes)"; } - for (pair> const& i: ad.storage) + for (pair> const& i: ad.storage) { s << "
"; if (!i.second.from()) @@ -1041,7 +1041,7 @@ void Main::on_transactionQueue_currentItemChanged() else { if (tx.data.size()) - s << eth::memDump(tx.data, 16, true); + s << dev::memDump(tx.data, 16, true); } s << "
"; @@ -1148,7 +1148,7 @@ void Main::on_blocks_currentItemChanged() else { if (tx.data.size()) - s << eth::memDump(tx.data, 16, true); + s << dev::memDump(tx.data, 16, true); } s << renderDiff(m_client->diff(txi, h)); ui->debugCurrent->setEnabled(true); @@ -1209,7 +1209,7 @@ void Main::on_debugDumpStatePre_triggered() on_debugDumpState_triggered(0); } -void Main::populateDebugger(eth::bytesConstRef _r) +void Main::populateDebugger(dev::bytesConstRef _r) { bool done = m_currentExecution->setup(_r); if (!done) @@ -1221,10 +1221,10 @@ void Main::populateDebugger(eth::bytesConstRef _r) bytesConstRef lastData; h256 lastHash; h256 lastDataHash; - auto onOp = [&](uint64_t steps, Instruction inst, eth::bigint newMemSize, eth::bigint gasCost, void* voidVM, void const* voidExt) + auto onOp = [&](uint64_t steps, Instruction inst, dev::bigint newMemSize, dev::bigint gasCost, void* voidVM, void const* voidExt) { - eth::VM& vm = *(eth::VM*)voidVM; - eth::ExtVM const& ext = *(eth::ExtVM const*)voidExt; + dev::eth::VM& vm = *(dev::eth::VM*)voidVM; + dev::eth::ExtVM const& ext = *(dev::eth::ExtVM const*)voidExt; if (ext.code != lastExtCode) { lastExtCode = ext.code; @@ -1270,7 +1270,7 @@ void Main::on_contracts_currentItemChanged() s << "

Body Code

" << disassemble(m_client->codeAt(address)); ui->contractInfo->appendHtml(QString::fromStdString(s.str())); } - catch (eth::InvalidTrie) + catch (dev::eth::InvalidTrie) { ui->contractInfo->appendHtml("Corrupted trie."); } @@ -1337,12 +1337,12 @@ void Main::on_data_textChanged() } else { - m_data = eth::compileLLL(src, m_enableOptimizer, &errors); + m_data = dev::eth::compileLLL(src, m_enableOptimizer, &errors); if (errors.size()) { try { - m_data = eth::asBytes(::compile(src)); + m_data = dev::asBytes(::compile(src)); for (auto& i: errors) i = "(LLL " + i + ")"; } @@ -1353,11 +1353,11 @@ void Main::on_data_textChanged() } else { - auto asmcode = eth::compileLLLToAsm(src, false); + auto asmcode = dev::eth::compileLLLToAsm(src, false); lll = "

Pre

" + QString::fromStdString(asmcode).toHtmlEscaped() + "
"; if (m_enableOptimizer) { - asmcode = eth::compileLLLToAsm(src, true); + asmcode = dev::eth::compileLLLToAsm(src, true); lll = "

Opt

" + QString::fromStdString(asmcode).toHtmlEscaped() + "
" + lll; } } @@ -1399,12 +1399,12 @@ void Main::on_data_textChanged() { u256 v(d.cap(2).toStdString()); if (d.cap(6) == "szabo") - v *= eth::szabo; + v *= dev::eth::szabo; else if (d.cap(5) == "finney") - v *= eth::finney; + v *= dev::eth::finney; else if (d.cap(4) == "ether") - v *= eth::ether; - bytes bs = eth::toCompactBigEndian(v); + v *= dev::eth::ether; + bytes bs = dev::toCompactBigEndian(v); if (d.cap(1) != "$") for (auto i = bs.size(); i < 32; ++i) m_data.push_back(0); @@ -1425,7 +1425,7 @@ void Main::on_data_textChanged() else s = s.mid(1); } - ui->code->setHtml(QString::fromStdString(eth::memDump(m_data, 8, true))); + ui->code->setHtml(QString::fromStdString(dev::memDump(m_data, 8, true))); if (m_client->codeAt(fromString(ui->destination->currentText()), 0).size()) { ui->gas->setMinimum((qint64)Client::txGas(m_data.size(), 1)); @@ -1509,10 +1509,10 @@ void Main::on_net_triggered() { ui->port->setEnabled(!ui->net->isChecked()); ui->clientName->setEnabled(!ui->net->isChecked()); - string n = string("AlethZero/v") + eth::EthVersion; + string n = string("AlethZero/v") + dev::Version; if (ui->clientName->text().size()) n += "/" + ui->clientName->text().toStdString(); - n += "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM); + n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM); m_client->setClientVersion(n); if (ui->net->isChecked()) { @@ -1588,7 +1588,7 @@ void Main::on_debug_clicked() m_executiveState = m_client->postState(); m_currentExecution = unique_ptr(new Executive(m_executiveState)); Transaction t; - t.nonce = m_executiveState.transactionsFrom(toAddress(s)); + t.nonce = m_executiveState.transactionsFrom(dev::eth::toAddress(s)); t.value = value(); t.gasPrice = gasPrice(); t.gas = ui->gas->value(); @@ -1602,7 +1602,7 @@ void Main::on_debug_clicked() } statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount."); } - catch (eth::Exception const& _e) + catch (dev::Exception const& _e) { statusBar()->showMessage("Error running transaction: " + QString::fromStdString(_e.description())); } @@ -1684,7 +1684,7 @@ void Main::on_dumpTrace_triggered() ofstream f(fn.toStdString()); if (f.is_open()) for (WorldState const& ws: m_history) - f << ws.cur << " " << hex << toHex(eth::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(eth::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(eth::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl; + f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl; } void Main::on_dumpTracePretty_triggered() @@ -1697,11 +1697,11 @@ void Main::on_dumpTracePretty_triggered() f << endl << " STACK" << endl; for (auto i: ws.stack) f << (h256)i << endl; - f << " MEMORY" << endl << eth::memDump(ws.memory); + f << " MEMORY" << endl << dev::memDump(ws.memory); f << " STORAGE" << endl; for (auto const& i: ws.storage) f << showbase << hex << i.first << ": " << i.second << endl; - f << dec << ws.levels.size() << " | " << ws.cur << " | #" << ws.steps << " | " << hex << setw(4) << setfill('0') << ws.curPC << " : " << 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 << " : " << dev::eth::instructionInfo(ws.inst).name << " | " << dec << ws.gas << " | -" << dec << ws.gasCost << " | " << ws.newMemSize << "x32"; } } @@ -1714,8 +1714,8 @@ void Main::on_dumpTraceStorage_triggered() { if (ws.inst == Instruction::STOP || ws.inst == Instruction::RETURN || ws.inst == Instruction::SUICIDE) for (auto i: ws.storage) - f << toHex(eth::toCompactBigEndian(i.first, 1)) << " " << toHex(eth::toCompactBigEndian(i.second, 1)) << endl; - f << ws.cur << " " << hex << toHex(eth::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(eth::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(eth::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl; + f << toHex(dev::toCompactBigEndian(i.first, 1)) << " " << toHex(dev::toCompactBigEndian(i.second, 1)) << endl; + f << ws.cur << " " << hex << toHex(dev::toCompactBigEndian(ws.curPC, 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)ws.inst, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)ws.gas, 1)) << endl; } } @@ -1773,7 +1773,7 @@ void Main::on_debugTimeline_valueChanged() updateDebugger(); } -QString Main::prettyU256(eth::u256 _n) const +QString Main::prettyU256(dev::u256 _n) const { unsigned inc = 0; QString raw; @@ -1817,7 +1817,7 @@ void Main::updateDebugger() bytes out(size, 0); for (; o < size && from + o < ws.memory.size(); ++o) out[o] = ws.memory[from + o]; - ui->debugMemory->setHtml("

RETURN

" + QString::fromStdString(eth::memDump(out, 16, true))); + ui->debugMemory->setHtml("

RETURN

" + QString::fromStdString(dev::memDump(out, 16, true))); } else if (ws.inst == Instruction::STOP) ui->debugMemory->setHtml("

STOP

"); @@ -1827,7 +1827,7 @@ void Main::updateDebugger() ui->debugMemory->setHtml("

EXCEPTION

"); ostringstream ss; - ss << dec << "EXIT | GAS: " << dec << max(0, (eth::bigint)ws.gas - ws.gasCost); + ss << dec << "EXIT | GAS: " << dec << max(0, (dev::bigint)ws.gas - ws.gasCost); ui->debugStateInfo->setText(QString::fromStdString(ss.str())); ui->debugStorage->setHtml(""); ui->debugCallData->setHtml(""); @@ -1892,7 +1892,7 @@ void Main::updateDebugger() if (ws.callData) { assert(m_codes.count(ws.callData)); - ui->debugCallData->setHtml(QString::fromStdString(eth::memDump(m_codes[ws.callData], 16, true))); + ui->debugCallData->setHtml(QString::fromStdString(dev::memDump(m_codes[ws.callData], 16, true))); } else ui->debugCallData->setHtml(""); @@ -1902,7 +1902,7 @@ void Main::updateDebugger() for (auto i: ws.stack) stack.prepend("
" + prettyU256(i) + "
"); ui->debugStack->setHtml(stack); - ui->debugMemory->setHtml(QString::fromStdString(eth::memDump(ws.memory, 16, true))); + ui->debugMemory->setHtml(QString::fromStdString(dev::memDump(ws.memory, 16, true))); assert(m_codes.count(ws.code)); if (m_codes[ws.code].size() >= (unsigned)ws.curPC) @@ -1916,7 +1916,7 @@ void Main::updateDebugger() cwarn << "PC (" << (unsigned)ws.curPC << ") is after code range (" << m_codes[ws.code].size() << ")"; ostringstream ss; - ss << dec << "STEP: " << ws.steps << " | PC: 0x" << hex << ws.curPC << " : " << 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 << " : " << dev::eth::instructionInfo(ws.inst).name << " | ADDMEM: " << dec << ws.newMemSize << " words | COST: " << dec << ws.gasCost << " | GAS: " << dec << ws.gas; ui->debugStateInfo->setText(QString::fromStdString(ss.str())); stringstream s; for (auto const& i: ws.storage) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 0474bb85d..e15f5ce2e 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -36,28 +36,28 @@ namespace Ui { class Main; } -namespace eth { +namespace dev { namespace eth { class Client; class State; class MessageFilter; -} +}} class QQuickView; struct WorldState { uint64_t steps; - eth::Address cur; - eth::u256 curPC; - eth::Instruction inst; - eth::bigint newMemSize; - eth::u256 gas; - eth::h256 code; - eth::h256 callData; - eth::u256s stack; - eth::bytes memory; - eth::bigint gasCost; - std::map storage; + dev::eth::Address cur; + dev::u256 curPC; + dev::eth::Instruction inst; + dev::bigint newMemSize; + dev::u256 gas; + dev::h256 code; + dev::h256 callData; + dev::u256s stack; + dev::bytes memory; + dev::bigint gasCost; + std::map storage; std::vector levels; }; @@ -69,9 +69,9 @@ public: explicit Main(QWidget *parent = 0); ~Main(); - eth::Client* client() { return m_client.get(); } + dev::eth::Client* client() { return m_client.get(); } - QList const& owned() const { return m_myKeys; } + QList const& owned() const { return m_myKeys; } public slots: void load(QString _file); @@ -146,18 +146,18 @@ signals: void poll(); private: - QString pretty(eth::Address _a) const; - QString prettyU256(eth::u256 _n) const; + QString pretty(dev::eth::Address _a) const; + QString prettyU256(dev::u256 _n) const; QString lookup(QString const& _n) const; - void populateDebugger(eth::bytesConstRef r); + void populateDebugger(dev::bytesConstRef r); void initDebugger(); void updateDebugger(); void debugFinished(); - QString render(eth::Address _a) const; - eth::Address fromString(QString const& _a) const; - std::string renderDiff(eth::StateDiff const& _d) const; + QString render(dev::eth::Address _a) const; + dev::eth::Address fromString(QString const& _a) const; + std::string renderDiff(dev::eth::StateDiff const& _d) const; void alterDebugStateGroup(bool _enable) const; @@ -166,13 +166,13 @@ private: void writeSettings(); bool isCreation() const; - eth::u256 fee() const; - eth::u256 total() const; - eth::u256 value() const; - eth::u256 gasPrice() const; + dev::u256 fee() const; + dev::u256 total() const; + dev::u256 value() const; + dev::u256 gasPrice() const; - unsigned installWatch(eth::MessageFilter const& _tf, std::function const& _f); - unsigned installWatch(eth::h256 _tf, std::function const& _f); + unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function const& _f); + unsigned installWatch(dev::h256 _tf, std::function const& _f); void onNewPending(); void onNewBlock(); @@ -200,7 +200,7 @@ private: std::unique_ptr ui; - std::unique_ptr m_client; + std::unique_ptr m_client; std::map> m_handlers; unsigned m_nameRegFilter = (unsigned)-1; unsigned m_currenciesFilter = (unsigned)-1; @@ -208,23 +208,23 @@ private: QByteArray m_peers; QStringList m_servers; - QList m_myKeys; + QList m_myKeys; QString m_privateChain; bool m_keysChanged = false; - eth::bytes m_data; - eth::Address m_nameReg; + dev::bytes m_data; + dev::eth::Address m_nameReg; unsigned m_backupGas; - eth::State m_executiveState; - std::unique_ptr m_currentExecution; - eth::h256 m_lastCode; - eth::h256 m_lastData; + dev::eth::State m_executiveState; + std::unique_ptr m_currentExecution; + dev::h256 m_lastCode; + dev::h256 m_lastData; std::vector m_lastLevels; QMap m_pcWarp; QList m_history; - std::map m_codes; // and pcWarps + std::map m_codes; // and pcWarps bool m_enableOptimizer = true; QNetworkAccessManager m_webCtrl; diff --git a/alethzero/MiningView.cpp b/alethzero/MiningView.cpp index f09fe425f..fa6da737b 100644 --- a/alethzero/MiningView.cpp +++ b/alethzero/MiningView.cpp @@ -29,17 +29,18 @@ using namespace std; using namespace lb; -// do *not* use eth since eth::uint conflicts with Qt's global unit definition -// using namespace eth; +// do *not* use eth since unsigned conflicts with Qt's global unit definition +// using namespace dev; +using namespace dev::eth; // types -using eth::MineInfo; -using eth::MineProgress; +using dev::eth::MineInfo; +using dev::eth::MineProgress; // functions -using eth::toString; -using eth::trimFront; +using dev::toString; +using dev::trimFront; string id(float _y) { return toString(_y); } string s(float _x){ return toString(round(_x * 1000) / 1000) + (!_x ? "s" : ""); } diff --git a/alethzero/MiningView.h b/alethzero/MiningView.h index 91e17e029..8f3135f75 100644 --- a/alethzero/MiningView.h +++ b/alethzero/MiningView.h @@ -31,10 +31,9 @@ #include #endif -namespace eth -{ +namespace dev { namespace eth { struct MineInfo; -} +}} class MiningView: public QWidget { @@ -43,14 +42,14 @@ class MiningView: public QWidget public: MiningView(QWidget* _p = nullptr); - void appendStats(std::list const& _l, eth::MineProgress const& _p); + void appendStats(std::list const& _l, dev::eth::MineProgress const& _p); void resetStats(); protected: virtual void paintEvent(QPaintEvent*); private: - eth::MineProgress m_progress; + dev::eth::MineProgress m_progress; unsigned m_duration = 300; std::vector m_values; std::vector m_bests; diff --git a/eth/CommonJS.cpp b/eth/CommonJS.cpp index e4c60a120..57958a117 100644 --- a/eth/CommonJS.cpp +++ b/eth/CommonJS.cpp @@ -22,9 +22,10 @@ #include "CommonJS.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -bytes eth::jsToBytes(string const& _s) +bytes dev::eth::jsToBytes(string const& _s) { if (_s.substr(0, 2) == "0x") // Hex @@ -37,7 +38,7 @@ bytes eth::jsToBytes(string const& _s) return asBytes(_s); } -string eth::jsPadded(string const& _s, unsigned _l, unsigned _r) +string dev::eth::jsPadded(string const& _s, unsigned _l, unsigned _r) { bytes b = jsToBytes(_s); while (b.size() < _l) @@ -47,7 +48,7 @@ string eth::jsPadded(string const& _s, unsigned _l, unsigned _r) return asString(b).substr(b.size() - max(_l, _r)); } -string eth::jsPadded(string const& _s, unsigned _l) +string dev::eth::jsPadded(string const& _s, unsigned _l) { if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == string::npos) // Numeric: pad to right @@ -57,7 +58,7 @@ string eth::jsPadded(string const& _s, unsigned _l) return jsPadded(_s, 0, _l); } -string eth::jsUnpadded(string _s) +string dev::eth::jsUnpadded(string _s) { auto p = _s.find_last_not_of((char)0); _s.resize(p == string::npos ? 0 : (p + 1)); diff --git a/eth/CommonJS.h b/eth/CommonJS.h index 57f2db39f..71a0c46d8 100644 --- a/eth/CommonJS.h +++ b/eth/CommonJS.h @@ -29,60 +29,63 @@ #include #include +namespace dev +{ namespace eth { -eth::bytes jsToBytes(std::string const& _s); +bytes jsToBytes(std::string const& _s); std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r); std::string jsPadded(std::string const& _s, unsigned _l); std::string jsUnpadded(std::string _s); -template eth::FixedHash jsToFixed(std::string const& _s) +template FixedHash jsToFixed(std::string const& _s) { if (_s.substr(0, 2) == "0x") // Hex - return eth::FixedHash(_s.substr(2)); + return FixedHash(_s.substr(2)); else if (_s.find_first_not_of("0123456789") == std::string::npos) // Decimal - return (typename eth::FixedHash::Arith)(_s); + return (typename FixedHash::Arith)(_s); else // Binary - return eth::FixedHash(asBytes(jsPadded(_s, N))); + return FixedHash(asBytes(jsPadded(_s, N))); } template boost::multiprecision::number> jsToInt(std::string const& _s) { if (_s.substr(0, 2) == "0x") // Hex - return eth::fromBigEndian>>(eth::fromHex(_s.substr(2))); + return fromBigEndian>>(fromHex(_s.substr(2))); else if (_s.find_first_not_of("0123456789") == std::string::npos) // Decimal return boost::multiprecision::number>(_s); else // Binary - return eth::fromBigEndian>>(asBytes(jsPadded(_s, N))); + return fromBigEndian>>(asBytes(jsPadded(_s, N))); } -inline eth::Address jsToAddress(std::string const& _s) { return jsToFixed<20>(_s); } -inline eth::Secret jsToSecret(std::string const& _s) { return jsToFixed<32>(_s); } -inline eth::u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } +inline Address jsToAddress(std::string const& _s) { return jsToFixed<20>(_s); } +inline Secret jsToSecret(std::string const& _s) { return jsToFixed<32>(_s); } +inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } -template std::string toJS(eth::FixedHash const& _h) { return "0x" + toHex(_h.ref()); } -template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + eth::toHex(eth::toCompactBigEndian(_n)); } +template std::string toJS(FixedHash const& _h) { return "0x" + toHex(_h.ref()); } +template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + toHex(toCompactBigEndian(_n)); } inline std::string jsToBinary(std::string const& _s) { - return eth::asString(jsToBytes(_s)); + return asString(jsToBytes(_s)); } inline std::string jsToDecimal(std::string const& _s) { - return eth::toString(jsToU256(_s)); + return toString(jsToU256(_s)); } inline std::string jsToHex(std::string const& _s) { - return "0x" + eth::toHex(asBytes(_s)); + return "0x" + toHex(asBytes(_s)); } } +} diff --git a/eth/EthStubServer.cpp b/eth/EthStubServer.cpp index 666a658f1..86bb1ba58 100644 --- a/eth/EthStubServer.cpp +++ b/eth/EthStubServer.cpp @@ -27,7 +27,8 @@ #include #include "CommonJS.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, Client& _client): AbstractEthStubServer(_conn), @@ -89,7 +90,7 @@ std::string EthStubServer::create(const std::string& _bCode, const std::string& std::string EthStubServer::lll(const std::string& _s) { - return "0x" + toHex(eth::compileLLL(_s)); + return "0x" + toHex(dev::eth::compileLLL(_s)); } std::string EthStubServer::gasPrice() diff --git a/eth/EthStubServer.h b/eth/EthStubServer.h index bd7041d3d..1805cb410 100644 --- a/eth/EthStubServer.h +++ b/eth/EthStubServer.h @@ -28,13 +28,12 @@ #include "abstractethstubserver.h" #pragma GCC diagnostic pop -namespace eth { class Client; } -namespace eth { class KeyPair; } +namespace dev { namespace eth { class Client; class KeyPair; } } class EthStubServer: public AbstractEthStubServer { public: - EthStubServer(jsonrpc::AbstractServerConnector* _conn, eth::Client& _client); + EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::eth::Client& _client); virtual Json::Value procedures(); virtual std::string balanceAt(std::string const& _a); @@ -55,10 +54,10 @@ public: virtual Json::Value lastBlock(); virtual std::string lll(const std::string& s); virtual Json::Value block(const std::string&); - void setKeys(std::vector _keys) { m_keys = _keys; } + void setKeys(std::vector _keys) { m_keys = _keys; } private: - eth::Client& m_client; - std::vector m_keys; + dev::eth::Client& m_client; + std::vector m_keys; Json::Value jsontypeToValue(int); Json::Value blockJson(const std::string&); }; diff --git a/eth/main.cpp b/eth/main.cpp index bf474440e..576423a5f 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -42,9 +42,10 @@ #endif #include "BuildInfo.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace boost::algorithm; -using eth::Instruction; +using dev::eth::Instruction; #undef RETURN @@ -124,13 +125,13 @@ string credits(bool _interactive = false) { std::ostringstream cout; cout - << "Ethereum (++) " << eth::EthVersion << endl + << "Ethereum (++) " << dev::Version << endl << " Code by Gav Wood, (c) 2013, 2014." << endl << " Based on a design by Vitalik Buterin." << endl << endl; if (_interactive) { - string vs = toString(eth::EthVersion); + string vs = toString(dev::Version); vs = vs.substr(vs.find_first_of('.') + 1)[0]; int pocnumber = stoi(vs); string m_servers; @@ -148,13 +149,13 @@ string credits(bool _interactive = false) void version() { - cout << "eth version " << eth::EthVersion << endl; - cout << "Build: " << ETH_QUOTED(ETH_BUILD_PLATFORM) << "/" << ETH_QUOTED(ETH_BUILD_TYPE) << endl; + cout << "eth version " << dev::Version << endl; + cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; exit(0); } Address c_config = Address("ccdeac59d35627b7de09332e819d5159e7bb7250"); -string pretty(h160 _a, eth::State _st) +string pretty(h160 _a, dev::eth::State _st) { string ns; h256 n; @@ -176,7 +177,7 @@ int main(int argc, char** argv) string remoteHost; unsigned short remotePort = 30303; string dbPath; - eth::uint mining = ~(eth::uint)0; + unsigned mining = ~(unsigned)0; NodeMode mode = NodeMode::Full; unsigned peers = 5; bool interactive = false; @@ -246,7 +247,7 @@ int main(int argc, char** argv) { string m = argv[++i]; if (isTrue(m)) - mining = ~(eth::uint)0; + mining = ~(unsigned)0; else if (isFalse(m)) mining = 0; else if (int i = stoi(m)) @@ -295,7 +296,7 @@ int main(int argc, char** argv) if (!clientName.empty()) clientName += "/"; - Client c("Ethereum(++)/" + clientName + "v" + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); + Client c("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); c.setForceMining(true); @@ -348,14 +349,14 @@ int main(int argc, char** argv) iss >> cmd; if (cmd == "netstart") { - eth::uint port; + unsigned port; iss >> port; c.startNetwork((short)port); } else if (cmd == "connect") { string addr; - eth::uint port; + unsigned port; iss >> addr >> port; c.connect(addr, (short)port); } @@ -449,7 +450,7 @@ int main(int argc, char** argv) cnote << "Data:"; cnote << sdata; - bytes data = eth::parseData(sdata); + bytes data = dev::eth::parseData(sdata); cnote << "Bytes:"; string sbd = asString(data); bytes bbd = asBytes(sbd); @@ -587,7 +588,7 @@ int main(int argc, char** argv) ofstream f; f.open(filename); - eth::State state = c.state(index + 1, c.blockChain().numberHash(block)); + dev::eth::State state = c.state(index + 1, c.blockChain().numberHash(block)); if (index < state.pending().size()) { Executive e(state); @@ -600,33 +601,33 @@ int main(int argc, char** argv) if (format == "pretty") oof = [&](uint64_t steps, Instruction instr, bigint newMemSize, bigint gasCost, void* vvm, void const* vextVM) { - eth::VM* vm = (VM*)vvm; - eth::ExtVM const* ext = (ExtVM const*)vextVM; + dev::eth::VM* vm = (VM*)vvm; + dev::eth::ExtVM const* ext = (ExtVM const*)vextVM; f << endl << " STACK" << endl; for (auto i: vm->stack()) f << (h256)i << endl; - f << " MEMORY" << endl << eth::memDump(vm->memory()); + f << " MEMORY" << endl << dev::memDump(vm->memory()); f << " STORAGE" << endl; for (auto const& i: ext->state().storage(ext->myAddress)) f << showbase << hex << i.first << ": " << i.second << endl; - f << dec << ext->level << " | " << ext->myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm->curPC() << " : " << eth::instructionInfo(instr).name << " | " << dec << vm->gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32"; + f << dec << ext->level << " | " << ext->myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm->curPC() << " : " << dev::eth::instructionInfo(instr).name << " | " << dec << vm->gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32"; }; else if (format == "standard") oof = [&](uint64_t, Instruction instr, bigint, bigint, void* vvm, void const* vextVM) { - eth::VM* vm = (VM*)vvm; - eth::ExtVM const* ext = (ExtVM const*)vextVM; - f << ext->myAddress << " " << hex << toHex(eth::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(eth::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(eth::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; + dev::eth::VM* vm = (VM*)vvm; + dev::eth::ExtVM const* ext = (ExtVM const*)vextVM; + f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; }; else if (format == "standard+") oof = [&](uint64_t, Instruction instr, bigint, bigint, void* vvm, void const* vextVM) { - eth::VM* vm = (VM*)vvm; - eth::ExtVM const* ext = (ExtVM const*)vextVM; + dev::eth::VM* vm = (VM*)vvm; + dev::eth::ExtVM const* ext = (ExtVM const*)vextVM; if (instr == Instruction::STOP || instr == Instruction::RETURN || instr == Instruction::SUICIDE) for (auto const& i: ext->state().storage(ext->myAddress)) - f << toHex(eth::toCompactBigEndian(i.first, 1)) << " " << toHex(eth::toCompactBigEndian(i.second, 1)) << endl; - f << ext->myAddress << " " << hex << toHex(eth::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(eth::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(eth::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; + f << toHex(dev::toCompactBigEndian(i.first, 1)) << " " << toHex(dev::toCompactBigEndian(i.second, 1)) << endl; + f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; }; e.go(oof); e.finalize(oof); @@ -659,7 +660,7 @@ int main(int argc, char** argv) cnote << "Saved" << rechex << "to" << outFile; } - catch (eth::InvalidTrie) + catch (dev::eth::InvalidTrie) { cwarn << "Corrupted trie."; } @@ -736,7 +737,7 @@ int main(int argc, char** argv) } else { - eth::uint n = c.blockChain().details().number; + unsigned n = c.blockChain().details().number; if (mining) c.startMining(); while (true) diff --git a/exp/main.cpp b/exp/main.cpp index 6c3e21af6..1de09e4ac 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -37,9 +37,10 @@ #include "BuildInfo.h" #endif using namespace std; -using namespace p2p; -using namespace eth; -using namespace shh; +using namespace dev; +using namespace dev::eth; +using namespace dev::p2p; +using namespace dev::shh; #if 0 #if 0 namespace qi = boost::spirit::qi; @@ -218,6 +219,7 @@ void debugOutAST(ostream& _out, sp::utree const& _this) } } +namespace dev { namespace eth { namespace parseTreeLLL_ { @@ -230,13 +232,13 @@ struct tagNode } }; -}} +}}} void parseTree(string const& _s, sp::utree& o_out) { using qi::standard::space; using qi::standard::space_type; - using eth::parseTreeLLL_::tagNode; + using dev::eth::parseTreeLLL_::tagNode; typedef sp::basic_string symbol_type; typedef string::const_iterator it; diff --git a/libethcore/BlockInfo.cpp b/libethcore/BlockInfo.cpp index 55026f670..d1028c21e 100644 --- a/libethcore/BlockInfo.cpp +++ b/libethcore/BlockInfo.cpp @@ -28,9 +28,10 @@ #include "Exceptions.h" #include "BlockInfo.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -u256 eth::c_genesisDifficulty = (u256)1 << 17; +u256 dev::eth::c_genesisDifficulty = (u256)1 << 17; BlockInfo::BlockInfo(): timestamp(Invalid256) { @@ -71,7 +72,7 @@ h256 BlockInfo::headerHash(bytesConstRef _block) void BlockInfo::populateFromHeader(RLP const& _header, bool _checkNonce) { - hash = eth::sha3(_header.data()); + hash = dev::eth::sha3(_header.data()); int field = 0; try diff --git a/libethcore/BlockInfo.h b/libethcore/BlockInfo.h index d88b9d09f..54efd8c29 100644 --- a/libethcore/BlockInfo.h +++ b/libethcore/BlockInfo.h @@ -25,6 +25,8 @@ #include #include "CommonEth.h" +namespace dev +{ namespace eth { @@ -121,5 +123,4 @@ inline std::ostream& operator<<(std::ostream& _out, BlockInfo const& _bi) } } - - +} diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 3fc817c72..c8632274c 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -25,12 +25,17 @@ #include #include "Exceptions.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; //#define ETH_ADDRESS_DEBUG 1 +namespace dev +{ +namespace eth +{ -const unsigned eth::c_protocolVersion = 32; -const unsigned eth::c_databaseVersion = 1; +const unsigned c_protocolVersion = 32; +const unsigned c_databaseVersion = 1; static const vector> g_units = { @@ -55,12 +60,12 @@ static const vector> g_units = {u256(1), "wei"} }; -vector> const& eth::units() +vector> const& units() { return g_units; } -std::string eth::formatBalance(u256 _b) +std::string formatBalance(u256 _b) { ostringstream ret; if (_b > g_units[0].first * 10000) @@ -79,7 +84,7 @@ std::string eth::formatBalance(u256 _b) return ret.str(); } -Address eth::toAddress(Secret _private) +Address toAddress(Secret _private) { secp256k1_start(); @@ -95,7 +100,7 @@ Address eth::toAddress(Secret _private) ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65); if (!ok) return Address(); - auto ret = right160(eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + auto ret = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- ADDRESS -------------------------------" << endl; cout << "SEC: " << _private << endl; @@ -105,6 +110,8 @@ Address eth::toAddress(Secret _private) return ret; } +}} + KeyPair KeyPair::create() { secp256k1_start(); @@ -143,7 +150,7 @@ KeyPair::KeyPair(h256 _sec): m_secret = m_secret; memcpy(m_public.data(), &(pubkey[1]), 64); - m_address = right160(eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + m_address = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- ADDRESS -------------------------------" << endl; diff --git a/libethcore/CommonEth.h b/libethcore/CommonEth.h index d336165cb..49b8a0c4f 100644 --- a/libethcore/CommonEth.h +++ b/libethcore/CommonEth.h @@ -26,6 +26,8 @@ #include #include +namespace dev +{ namespace eth { @@ -117,3 +119,4 @@ private: }; } +} diff --git a/libethcore/Dagger.cpp b/libethcore/Dagger.cpp index 8be21bdbb..cc37fb98d 100644 --- a/libethcore/Dagger.cpp +++ b/libethcore/Dagger.cpp @@ -32,12 +32,14 @@ using namespace std; using namespace std::chrono; +namespace dev +{ namespace eth { #if FAKE_DAGGER -MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool _continue, bool _turbo) +MineInfo Dagger::mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, unsigned _msTimeout, bool _continue, bool _turbo) { MineInfo ret; static std::mt19937_64 s_eng((time(0) + (unsigned)m_last)); @@ -91,7 +93,7 @@ bool Dagger::verify(h256 const& _root, u256 const& _nonce, u256 const& _difficul return eval(_root, _nonce) < bound(_difficulty); } -bool Dagger::mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout, bool const& _continue) +bool Dagger::mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, unsigned _msTimeout, bool const& _continue) { // restart search if root has changed if (m_root != _root) @@ -185,5 +187,5 @@ h256 Dagger::eval(h256 const& _root, u256 const& _nonce) #endif } - +} #endif diff --git a/libethcore/Dagger.h b/libethcore/Dagger.h index 61848f8c9..58f6e3f80 100644 --- a/libethcore/Dagger.h +++ b/libethcore/Dagger.h @@ -28,20 +28,17 @@ #define FAKE_DAGGER 1 -namespace eth +namespace dev { - -inline uint toLog2(u256 _d) +namespace eth { - return (uint)log2((double)_d); -} struct MineInfo { void combine(MineInfo const& _m) { requirement = std::max(requirement, _m.requirement); best = std::min(best, _m.best); hashes += _m.hashes; completed = completed || _m.completed; } double requirement = 0; double best = 1e99; - uint hashes = 0; + unsigned hashes = 0; bool completed = false; }; @@ -53,7 +50,7 @@ public: static h256 eval(h256 const& _root, h256 const& _nonce) { h256 b[2] = { _root, _nonce }; return sha3(bytesConstRef((byte const*)&b[0], 64)); } static bool verify(h256 const& _root, h256 const& _nonce, u256 const& _difficulty) { return (bigint)(u256)eval(_root, _nonce) <= (bigint(1) << 256) / _difficulty; } - MineInfo mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool _continue = true, bool _turbo = false); + MineInfo mine(h256& o_solution, h256 const& _root, u256 const& _difficulty, unsigned _msTimeout = 100, bool _continue = true, bool _turbo = false); h256 m_last; }; @@ -71,7 +68,7 @@ public: static h256 eval(h256 const& _root, u256 const& _nonce); static bool verify(h256 const& _root, u256 const& _nonce, u256 const& _difficulty); - bool mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, uint _msTimeout = 100, bool const& _continue = bool(true)); + bool mine(u256& o_solution, h256 const& _root, u256 const& _difficulty, unsigned _msTimeout = 100, bool const& _continue = bool(true)); private: @@ -84,5 +81,4 @@ private: #endif } - - +} diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h index e11aff26a..175add708 100644 --- a/libethcore/Exceptions.h +++ b/libethcore/Exceptions.h @@ -2,42 +2,45 @@ #include +namespace dev +{ namespace eth { -class DatabaseAlreadyOpen: public Exception {}; +class DatabaseAlreadyOpen: public dev::Exception {}; -class NotEnoughCash: public Exception {}; +class NotEnoughCash: public dev::Exception {}; -class GasPriceTooLow: public Exception {}; -class BlockGasLimitReached: public Exception {}; -class NoSuchContract: public Exception {}; -class ContractAddressCollision: public Exception {}; -class FeeTooSmall: public Exception {}; -class TooMuchGasUsed: public Exception {}; -class ExtraDataTooBig: public Exception {}; -class InvalidSignature: public Exception {}; -class InvalidTransactionFormat: public Exception { public: InvalidTransactionFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid transaction format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; -class InvalidBlockFormat: public Exception { public: InvalidBlockFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; -class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block header format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; -class InvalidUnclesHash: public Exception {}; -class InvalidUncle: public Exception {}; -class UncleTooOld: public Exception {}; -class UncleInChain: public Exception {}; -class DuplicateUncleNonce: public Exception {}; -class InvalidStateRoot: public Exception {}; -class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } }; -class InvalidTransaction: public Exception {}; -class InvalidDifficulty: public Exception {}; -class InvalidGasLimit: public Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _valid = 0): provided(_provided), valid(_valid) {} u256 provided; u256 valid; virtual std::string description() const { return "Invalid gas limit (provided: " + toString(provided) + " valid:" + toString(valid) + ")"; } }; -class InvalidMinGasPrice: public Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual std::string description() const { return "Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"; } }; -class InvalidTransactionGasUsed: public Exception {}; -class InvalidTransactionStateRoot: public Exception {}; -class InvalidTimestamp: public Exception {}; -class InvalidNonce: public Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; virtual std::string description() const { return "Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"; } }; -class InvalidBlockNonce: public Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } }; -class InvalidParentHash: public Exception {}; -class InvalidNumber: public Exception {}; -class InvalidContractAddress: public Exception {}; +class GasPriceTooLow: public dev::Exception {}; +class BlockGasLimitReached: public dev::Exception {}; +class NoSuchContract: public dev::Exception {}; +class ContractAddressCollision: public dev::Exception {}; +class FeeTooSmall: public dev::Exception {}; +class TooMuchGasUsed: public dev::Exception {}; +class ExtraDataTooBig: public dev::Exception {}; +class InvalidSignature: public dev::Exception {}; +class InvalidTransactionFormat: public dev::Exception { public: InvalidTransactionFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid transaction format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; +class InvalidBlockFormat: public dev::Exception { public: InvalidBlockFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; +class InvalidBlockHeaderFormat: public dev::Exception { public: InvalidBlockHeaderFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block header format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; +class InvalidUnclesHash: public dev::Exception {}; +class InvalidUncle: public dev::Exception {}; +class UncleTooOld: public dev::Exception {}; +class UncleInChain: public dev::Exception {}; +class DuplicateUncleNonce: public dev::Exception {}; +class InvalidStateRoot: public dev::Exception {}; +class InvalidTransactionsHash: public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } }; +class InvalidTransaction: public dev::Exception {}; +class InvalidDifficulty: public dev::Exception {}; +class InvalidGasLimit: public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _valid = 0): provided(_provided), valid(_valid) {} u256 provided; u256 valid; virtual std::string description() const { return "Invalid gas limit (provided: " + toString(provided) + " valid:" + toString(valid) + ")"; } }; +class InvalidMinGasPrice: public dev::Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual std::string description() const { return "Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"; } }; +class InvalidTransactionGasUsed: public dev::Exception {}; +class InvalidTransactionStateRoot: public dev::Exception {}; +class InvalidTimestamp: public dev::Exception {}; +class InvalidNonce: public dev::Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; virtual std::string description() const { return "Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"; } }; +class InvalidBlockNonce: public dev::Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } }; +class InvalidParentHash: public dev::Exception {}; +class InvalidNumber: public dev::Exception {}; +class InvalidContractAddress: public dev::Exception {}; } +} diff --git a/libethcore/FileSystem.cpp b/libethcore/FileSystem.cpp index 6d7044753..953789d9b 100644 --- a/libethcore/FileSystem.cpp +++ b/libethcore/FileSystem.cpp @@ -30,9 +30,10 @@ #endif #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -std::string eth::getDataDir() +std::string dev::eth::getDataDir() { #ifdef _WIN32 char path[1024] = ""; diff --git a/libethcore/FileSystem.h b/libethcore/FileSystem.h index a6ce93fb0..9c597c421 100644 --- a/libethcore/FileSystem.h +++ b/libethcore/FileSystem.h @@ -25,6 +25,8 @@ #include +namespace dev +{ namespace eth { @@ -32,3 +34,4 @@ namespace eth std::string getDataDir(); } +} diff --git a/libethcore/MemoryDB.cpp b/libethcore/MemoryDB.cpp index 8755266c3..6fe8091d6 100644 --- a/libethcore/MemoryDB.cpp +++ b/libethcore/MemoryDB.cpp @@ -22,8 +22,11 @@ #include #include "MemoryDB.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; +namespace dev +{ namespace eth { @@ -113,3 +116,4 @@ set MemoryDB::keys() const } } +} diff --git a/libethcore/MemoryDB.h b/libethcore/MemoryDB.h index 33cd71fcd..76c7e6c6b 100644 --- a/libethcore/MemoryDB.h +++ b/libethcore/MemoryDB.h @@ -27,6 +27,8 @@ #include #include +namespace dev +{ namespace eth { @@ -54,7 +56,7 @@ public: protected: std::map m_over; - std::map m_refCount; + std::map m_refCount; mutable bool m_enforceRefs = false; }; @@ -83,3 +85,4 @@ inline std::ostream& operator<<(std::ostream& _out, MemoryDB const& _m) } } +} diff --git a/libethcore/OverlayDB.cpp b/libethcore/OverlayDB.cpp index a8941e9ef..b009841cd 100644 --- a/libethcore/OverlayDB.cpp +++ b/libethcore/OverlayDB.cpp @@ -22,8 +22,11 @@ #include #include "OverlayDB.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; +namespace dev +{ namespace eth { @@ -97,3 +100,4 @@ void OverlayDB::kill(h256 _h) } } +} diff --git a/libethcore/OverlayDB.h b/libethcore/OverlayDB.h index e2a5aba1a..c13b20e6b 100644 --- a/libethcore/OverlayDB.h +++ b/libethcore/OverlayDB.h @@ -21,12 +21,19 @@ #pragma once +#pragma warning(push) +#pragma warning(disable: 4100 4267) +#include +#pragma warning(pop) + #include #include #include #include "MemoryDB.h" namespace ldb = leveldb; +namespace dev +{ namespace eth { @@ -56,3 +63,4 @@ private: }; } +} diff --git a/libethcore/SHA3.cpp b/libethcore/SHA3.cpp index 90e85f4ef..cdd1002e6 100644 --- a/libethcore/SHA3.cpp +++ b/libethcore/SHA3.cpp @@ -23,11 +23,17 @@ #include "CryptoHeaders.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -h256 eth::EmptySHA3 = sha3(bytesConstRef()); +namespace dev +{ +namespace eth +{ + +h256 EmptySHA3 = sha3(bytesConstRef()); -std::string eth::sha3(std::string const& _input, bool _hex) +std::string sha3(std::string const& _input, bool _hex) { if (!_hex) { @@ -44,7 +50,7 @@ std::string eth::sha3(std::string const& _input, bool _hex) return ret; } -void eth::sha3(bytesConstRef _input, bytesRef _output) +void sha3(bytesConstRef _input, bytesRef _output) { CryptoPP::SHA3_256 ctx; ctx.Update((byte*)_input.data(), _input.size()); @@ -52,17 +58,19 @@ void eth::sha3(bytesConstRef _input, bytesRef _output) ctx.Final(_output.data()); } -bytes eth::sha3Bytes(bytesConstRef _input) +bytes sha3Bytes(bytesConstRef _input) { bytes ret(32); sha3(_input, &ret); return ret; } -h256 eth::sha3(bytesConstRef _input) +h256 sha3(bytesConstRef _input) { h256 ret; sha3(_input, bytesRef(&ret[0], 32)); return ret; } +} +} diff --git a/libethcore/SHA3.h b/libethcore/SHA3.h index 5972c0e47..2a76ea56f 100644 --- a/libethcore/SHA3.h +++ b/libethcore/SHA3.h @@ -27,6 +27,8 @@ #include #include +namespace dev +{ namespace eth { @@ -59,3 +61,4 @@ inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)) extern h256 EmptySHA3; } +} diff --git a/libethcore/TrieCommon.cpp b/libethcore/TrieCommon.cpp index fedf3b095..bad29059e 100644 --- a/libethcore/TrieCommon.cpp +++ b/libethcore/TrieCommon.cpp @@ -21,6 +21,8 @@ #include "TrieCommon.h" +namespace dev +{ namespace eth { @@ -42,8 +44,8 @@ namespace eth std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf, int _begin, int _end) { - uint begin = _begin; - uint end = _end < 0 ? _hexVector.size() + 1 + _end : _end; + unsigned begin = _begin; + unsigned end = _end < 0 ? _hexVector.size() + 1 + _end : _end; bool odd = ((end - begin) % 2) != 0; std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); @@ -52,21 +54,21 @@ std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf, int _begin, int ret[0] |= _hexVector[begin]; ++begin; } - for (uint i = begin; i < end; i += 2) + for (unsigned i = begin; i < end; i += 2) ret += _hexVector[i] * 16 + _hexVector[i + 1]; return ret; } -std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, uint _offset) +std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, unsigned _offset) { - uint begin = _beginNibble + _offset; - uint end = (_endNibble < 0 ? (_data.size() * 2 - _offset) + 1 + _endNibble : _endNibble) + _offset; + unsigned begin = _beginNibble + _offset; + unsigned end = (_endNibble < 0 ? (_data.size() * 2 - _offset) + 1 + _endNibble : _endNibble) + _offset; bool odd = (end - begin) & 1; std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); ret.reserve((end - begin) / 2 + 1); - uint d = odd ? 1 : 2; + unsigned d = odd ? 1 : 2; for (auto i = begin; i < end; ++i, ++d) { byte n = nibble(_data, i); @@ -78,19 +80,19 @@ std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, i return ret; } -std::string hexPrefixEncode(bytesConstRef _d1, uint _o1, bytesConstRef _d2, uint _o2, bool _leaf) +std::string hexPrefixEncode(bytesConstRef _d1, unsigned _o1, bytesConstRef _d2, unsigned _o2, bool _leaf) { - uint begin1 = _o1; - uint end1 = _d1.size() * 2; - uint begin2 = _o2; - uint end2 = _d2.size() * 2; + unsigned begin1 = _o1; + unsigned end1 = _d1.size() * 2; + unsigned begin2 = _o2; + unsigned end2 = _d2.size() * 2; bool odd = (end1 - begin1 + end2 - begin2) & 1; std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); ret.reserve((end1 - begin1 + end2 - begin2) / 2 + 1); - uint d = odd ? 1 : 2; + unsigned d = odd ? 1 : 2; for (auto i = begin1; i < end1; ++i, ++d) { byte n = nibble(_d1, i); @@ -125,3 +127,4 @@ byte uniqueInUse(RLP const& _orig, byte except) } } +} diff --git a/libethcore/TrieCommon.h b/libethcore/TrieCommon.h index c748fd8d0..afe527e3b 100644 --- a/libethcore/TrieCommon.h +++ b/libethcore/TrieCommon.h @@ -24,40 +24,42 @@ #include #include +namespace dev +{ namespace eth { -inline byte nibble(bytesConstRef _data, uint _i) +inline byte nibble(bytesConstRef _data, unsigned _i) { return (_i & 1) ? (_data[_i / 2] & 15) : (_data[_i / 2] >> 4); } -inline uint sharedNibbles(bytesConstRef _a, uint _ab, uint _ae, bytesConstRef _b, uint _bb, uint _be) +inline unsigned sharedNibbles(bytesConstRef _a, unsigned _ab, unsigned _ae, bytesConstRef _b, unsigned _bb, unsigned _be) { - uint ret = 0; - for (uint ai = _ab, bi = _bb; ai < _ae && bi < _be && nibble(_a, ai) == nibble(_b, bi); ++ai, ++bi, ++ret) {} + unsigned ret = 0; + for (unsigned ai = _ab, bi = _bb; ai < _ae && bi < _be && nibble(_a, ai) == nibble(_b, bi); ++ai, ++bi, ++ret) {} return ret; } struct NibbleSlice { bytesConstRef data; - uint offset; + unsigned offset; - NibbleSlice(bytesConstRef _d = bytesConstRef(), uint _o = 0): data(_d), offset(_o) {} - byte operator[](uint _index) const { return nibble(data, offset + _index); } - uint size() const { return data.size() * 2 - offset; } - NibbleSlice mid(uint _index) const { return NibbleSlice(data, offset + _index); } + NibbleSlice(bytesConstRef _d = bytesConstRef(), unsigned _o = 0): data(_d), offset(_o) {} + byte operator[](unsigned _index) const { return nibble(data, offset + _index); } + unsigned size() const { return data.size() * 2 - offset; } + NibbleSlice mid(unsigned _index) const { return NibbleSlice(data, offset + _index); } bool contains(NibbleSlice _k) const { return shared(_k) == _k.size(); } - uint shared(NibbleSlice _k) const { return sharedNibbles(data, offset, offset + size(), _k.data, _k.offset, _k.offset + _k.size()); } + unsigned shared(NibbleSlice _k) const { return sharedNibbles(data, offset, offset + size(), _k.data, _k.offset, _k.offset + _k.size()); } bool operator==(NibbleSlice _k) const { return _k.size() == size() && shared(_k) == _k.size(); } bool operator!=(NibbleSlice _s) const { return !operator==(_s); } }; inline std::ostream& operator<<(std::ostream& _out, NibbleSlice const& _m) { - for (uint i = 0; i < _m.size(); ++i) + for (unsigned i = 0; i < _m.size(); ++i) _out << std::hex << (int)_m[i] << std::dec; return _out; } @@ -86,8 +88,8 @@ inline NibbleSlice keyOf(RLP const& _twoItem) byte uniqueInUse(RLP const& _orig, byte except); std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf = false, int _begin = 0, int _end = -1); -std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, uint _offset); -std::string hexPrefixEncode(bytesConstRef _d1, uint _o1, bytesConstRef _d2, uint _o2, bool _leaf); +std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, unsigned _offset); +std::string hexPrefixEncode(bytesConstRef _d1, unsigned _o1, bytesConstRef _d2, unsigned _o2, bool _leaf); inline std::string hexPrefixEncode(NibbleSlice _s, bool _leaf, int _begin = 0, int _end = -1) { @@ -100,3 +102,4 @@ inline std::string hexPrefixEncode(NibbleSlice _s1, NibbleSlice _s2, bool _leaf) } } +} diff --git a/libethcore/TrieDB.cpp b/libethcore/TrieDB.cpp index c0562889f..c6c1262bc 100644 --- a/libethcore/TrieDB.cpp +++ b/libethcore/TrieDB.cpp @@ -22,14 +22,11 @@ #include #include "TrieDB.h" using namespace std; -using namespace eth; - -namespace eth -{ +using namespace dev; +using namespace dev::eth; #if !ETH_LANGUAGES -const h256 c_shaNull = sha3(rlp("")); +const h256 dev::eth::c_shaNull = sha3(rlp("")); #endif -} diff --git a/libethcore/TrieDB.h b/libethcore/TrieDB.h index c6114b95d..ff87cc4f8 100644 --- a/libethcore/TrieDB.h +++ b/libethcore/TrieDB.h @@ -21,6 +21,11 @@ #pragma once +#pragma warning(push) +#pragma warning(disable: 4100 4267) +#include +#pragma warning(pop) + #include #include #include @@ -31,6 +36,8 @@ #include "TrieCommon.h" namespace ldb = leveldb; +namespace dev +{ namespace eth { @@ -223,7 +230,7 @@ private: // in: [K1 & K2, V] (DEL) : nibbles(K1) == _s, 0 < _s <= nibbles(K1 & K2) // out: [K1, H] ; [K2, V] => H (INS) (being [K1, [K2, V]] if necessary) - bytes cleve(RLP const& _orig, uint _s); + bytes cleve(RLP const& _orig, unsigned _s); // in: [K1, H] (DEL) ; H <= [K2, V] (DEL) (being [K1, [K2, V]] (DEL) if necessary) // out: [K1 & K2, V] @@ -308,9 +315,12 @@ std::ostream& operator<<(std::ostream& _out, TrieDB const& _db) return _out; } +} } // Template implementations... +namespace dev +{ namespace eth { @@ -756,7 +766,7 @@ template bytes GenericTrieDB::place(RLP const& _orig, NibbleSlice return (RLPStream(2) << _orig[0] << _s).out(); auto s = RLPStream(17); - for (uint i = 0; i < 16; ++i) + for (unsigned i = 0; i < 16; ++i) s << _orig[i]; s << _s; return s.out(); @@ -778,7 +788,7 @@ template bytes GenericTrieDB::remove(RLP const& _orig) if (_orig.itemCount() == 2) return RLPNull; RLPStream r(17); - for (uint i = 0; i < 16; ++i) + for (unsigned i = 0; i < 16; ++i) r << _orig[i]; r << ""; return r.out(); @@ -793,7 +803,7 @@ template RLPStream& GenericTrieDB::streamNode(RLPStream& _s, byte return _s; } -template bytes GenericTrieDB::cleve(RLP const& _orig, uint _s) +template bytes GenericTrieDB::cleve(RLP const& _orig, unsigned _s) { #if ETH_PARANOIA tdebug << "cleve " << _orig << _s; @@ -874,14 +884,14 @@ template bytes GenericTrieDB::branch(RLP const& _orig) if (k.size() == 0) { assert(isLeaf(_orig)); - for (uint i = 0; i < 16; ++i) + for (unsigned i = 0; i < 16; ++i) r << ""; r << _orig[1]; } else { byte b = k[0]; - for (uint i = 0; i < 16; ++i) + for (unsigned i = 0; i < 16; ++i) if (i == b) if (isLeaf(_orig) || k.size() > 1) { @@ -899,3 +909,5 @@ template bytes GenericTrieDB::branch(RLP const& _orig) } } +} + diff --git a/libethential/Common.cpp b/libethential/Common.cpp index 2f6feb9e5..665a663f3 100644 --- a/libethential/Common.cpp +++ b/libethential/Common.cpp @@ -22,11 +22,12 @@ #include "Common.h" using namespace std; -using namespace eth; +using namespace dev; -namespace eth +namespace dev { -char const* EthVersion = "0.6.8"; +char const* Version = "0.6.8"; } + diff --git a/libethential/Common.h b/libethential/Common.h index c06ede0c0..132429010 100644 --- a/libethential/Common.h +++ b/libethential/Common.h @@ -23,7 +23,7 @@ #pragma once -// way to many uint to size_t warnings in 32 bit build +// way to many unsigned to size_t warnings in 32 bit build #ifdef _M_IX86 #pragma warning(disable:4244) #endif @@ -43,13 +43,13 @@ using byte = uint8_t; // Quote a given token stream to turn it into a string. -#define ETH_QUOTED_HELPER(s) #s -#define ETH_QUOTED(s) ETH_QUOTED_HELPER(s) +#define DEV_QUOTED_HELPER(s) #s +#define DEV_QUOTED(s) DEV_QUOTED_HELPER(s) -namespace eth +namespace dev { -extern char const* EthVersion; +extern char const* Version; // Binary data types. using bytes = std::vector; @@ -62,8 +62,6 @@ using u256 = boost::multiprecision::number>; using u160 = boost::multiprecision::number>; using s160 = boost::multiprecision::number>; -using uint = uint64_t; -using sint = int64_t; using u256s = std::vector; using u160s = std::vector; using u256Set = std::set; @@ -98,4 +96,11 @@ inline u256 s2u(s256 _u) return (u256)(c_end + _u); } +inline unsigned int toLog2(u256 _x) +{ + unsigned ret; + for (ret = 0; _x >>= 1; ++ret) {} + return ret; +} + } diff --git a/libethential/CommonData.cpp b/libethential/CommonData.cpp index 3d4d9bdbe..96269bbc1 100644 --- a/libethential/CommonData.cpp +++ b/libethential/CommonData.cpp @@ -24,9 +24,9 @@ #include #include "Exceptions.h" using namespace std; -using namespace eth; +using namespace dev; -std::string eth::escaped(std::string const& _s, bool _all) +std::string dev::escaped(std::string const& _s, bool _all) { std::string ret; ret.reserve(_s.size()); @@ -48,7 +48,7 @@ std::string eth::escaped(std::string const& _s, bool _all) return ret; } -std::string eth::randomWord() +std::string dev::randomWord() { static std::mt19937_64 s_eng(0); std::string ret(std::uniform_int_distribution(1, 5)(s_eng), ' '); @@ -59,7 +59,7 @@ std::string eth::randomWord() return ret; } -int eth::fromHex(char _i) +int dev::fromHex(char _i) { if (_i >= '0' && _i <= '9') return _i - '0'; @@ -70,9 +70,9 @@ int eth::fromHex(char _i) throw BadHexCharacter(); } -bytes eth::fromHex(std::string const& _s) +bytes dev::fromHex(std::string const& _s) { - uint s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; + unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; std::vector ret; ret.reserve((_s.size() - s + 1) / 2); @@ -82,7 +82,7 @@ bytes eth::fromHex(std::string const& _s) ret.push_back(fromHex(_s[s++])); } catch (...){ ret.push_back(0); } - for (uint i = s; i < _s.size(); i += 2) + for (unsigned i = s; i < _s.size(); i += 2) try { ret.push_back((byte)(fromHex(_s[i]) * 16 + fromHex(_s[i + 1]))); @@ -91,7 +91,7 @@ bytes eth::fromHex(std::string const& _s) return ret; } -bytes eth::asNibbles(std::string const& _s) +bytes dev::asNibbles(std::string const& _s) { std::vector ret; ret.reserve(_s.size() * 2); diff --git a/libethential/CommonData.h b/libethential/CommonData.h index 6840194fc..1181e07e8 100644 --- a/libethential/CommonData.h +++ b/libethential/CommonData.h @@ -30,7 +30,7 @@ #include #include "Common.h" -namespace eth +namespace dev { // String conversion functions, mainly to/from hex/nibble/byte representations. @@ -79,7 +79,7 @@ bytes asNibbles(std::string const& _s); /// The size of the collection object will be unchanged. If it is too small, it will not represent the /// value properly, if too big then the additional elements will be zeroed out. /// @a _Out will typically be either std::string or bytes. -/// @a _T will typically by uint, u160, u256 or bigint. +/// @a _T will typically by unsigned, u160, u256 or bigint. template inline void toBigEndian(_T _val, _Out& o_out) { @@ -89,7 +89,7 @@ inline void toBigEndian(_T _val, _Out& o_out) /// Converts a big-endian byte-stream represented on a templated collection to a templated integer value. /// @a _In will typically be either std::string or bytes. -/// @a _T will typically by uint, u160, u256 or bigint. +/// @a _T will typically by unsigned, u160, u256 or bigint. template inline _T fromBigEndian(_In const& _bytes) { @@ -140,10 +140,10 @@ std::string escaped(std::string const& _s, bool _all = true); /// @returns the number of elements both @a _t and @a _u share, in order, at the beginning. /// @example commonPrefix("Hello world!", "Hello, world!") == 5 template -uint commonPrefix(_T const& _t, _U const& _u) +unsigned commonPrefix(_T const& _t, _U const& _u) { - uint s = std::min(_t.size(), _u.size()); - for (uint i = 0;; ++i) + unsigned s = std::min(_t.size(), _u.size()); + for (unsigned i = 0;; ++i) if (i == s || _t[i] != _u[i]) return i; return s; @@ -157,9 +157,9 @@ std::string randomWord(); /// Determine bytes required to encode the given integer value. @returns 0 if @a _i is zero. template -inline uint bytesRequired(_T _i) +inline unsigned bytesRequired(_T _i) { - uint i = 0; + unsigned i = 0; for (; _i != 0; ++i, _i >>= 8) {} return i; } @@ -167,7 +167,7 @@ inline uint bytesRequired(_T _i) /// Trims a given number of elements from the front of a collection. /// Only works for POD element types. template -void trimFront(_T& _t, uint _elements) +void trimFront(_T& _t, unsigned _elements) { static_assert(std::is_pod::value, ""); memmove(_t.data(), _t.data() + _elements, (_t.size() - _elements) * sizeof(_t[0])); diff --git a/libethential/CommonIO.cpp b/libethential/CommonIO.cpp index c2e2306d0..5797e44dc 100644 --- a/libethential/CommonIO.cpp +++ b/libethential/CommonIO.cpp @@ -24,9 +24,9 @@ #include #include "Exceptions.h" using namespace std; -using namespace eth; +using namespace dev; -string eth::memDump(bytes const& _b, unsigned _w, bool _html) +string dev::memDump(bytes const& _b, unsigned _w, bool _html) { stringstream ret; if (_html) @@ -57,7 +57,7 @@ string eth::memDump(bytes const& _b, unsigned _w, bool _html) return ret.str(); } -bytes eth::contents(std::string const& _file) +bytes dev::contents(std::string const& _file) { std::ifstream is(_file, std::ifstream::binary); if (!is) @@ -72,7 +72,7 @@ bytes eth::contents(std::string const& _file) return ret; } -void eth::writeFile(std::string const& _file, bytes const& _data) +void dev::writeFile(std::string const& _file, bytes const& _data) { ofstream(_file, ios::trunc).write((char const*)_data.data(), _data.size()); } diff --git a/libethential/CommonIO.h b/libethential/CommonIO.h index 824f2c270..068c5c777 100644 --- a/libethential/CommonIO.h +++ b/libethential/CommonIO.h @@ -37,7 +37,7 @@ #include #include "Common.h" -namespace eth +namespace dev { /// Retrieve and returns the contents of the given file. If the file doesn't exist or isn't readable, returns an empty bytes. diff --git a/libethential/Exceptions.h b/libethential/Exceptions.h index 18ddfe5e8..15ef2019f 100644 --- a/libethential/Exceptions.h +++ b/libethential/Exceptions.h @@ -26,7 +26,7 @@ #include "CommonData.h" #include "FixedHash.h" -namespace eth +namespace dev { class Exception: public std::exception diff --git a/libethential/FixedHash.cpp b/libethential/FixedHash.cpp index 885d593e5..0369ea854 100644 --- a/libethential/FixedHash.cpp +++ b/libethential/FixedHash.cpp @@ -23,6 +23,6 @@ #include "FixedHash.h" using namespace std; -using namespace eth; +using namespace dev; -std::mt19937_64 eth::s_fixedHashEngine(time(0)); +std::mt19937_64 dev::s_fixedHashEngine(time(0)); diff --git a/libethential/FixedHash.h b/libethential/FixedHash.h index 828e3aef6..f979f0b68 100644 --- a/libethential/FixedHash.h +++ b/libethential/FixedHash.h @@ -28,7 +28,7 @@ #include #include "CommonData.h" -namespace eth +namespace dev { extern std::mt19937_64 s_fixedHashEngine; @@ -65,13 +65,13 @@ public: FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); } /// Explicitly construct, copying from a byte array. - explicit FixedHash(bytes const& _b) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); } + explicit FixedHash(bytes const& _b) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); } /// Explicitly construct, copying from a bytes in memory with given pointer. explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); } /// Explicitly construct, copying from a string. - explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex): FixedHash(_t == FromHex ? fromHex(_s) : eth::asBytes(_s)) {} + explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex): FixedHash(_t == FromHex ? fromHex(_s) : dev::asBytes(_s)) {} /// Convert to arithmetic type. operator Arith() const { return fromBigEndian(m_data); } @@ -221,6 +221,6 @@ inline h160 left160(h256 const& _t) namespace std { - /// Forward std::hash to eth::h256::hash. - template<> struct hash: eth::h256::hash {}; + /// Forward std::hash to dev::h256::hash. + template<> struct hash: dev::h256::hash {}; } diff --git a/libethential/Guards.cpp b/libethential/Guards.cpp index b2e12f98e..69ae6c03a 100644 --- a/libethential/Guards.cpp +++ b/libethential/Guards.cpp @@ -21,9 +21,9 @@ #include "Guards.h" using namespace std; -using namespace eth; +using namespace dev; -namespace eth +namespace dev { } diff --git a/libethential/Guards.h b/libethential/Guards.h index b509b45ed..f5c64b041 100644 --- a/libethential/Guards.h +++ b/libethential/Guards.h @@ -24,7 +24,7 @@ #include #include -namespace eth +namespace dev { using Mutex = std::mutex; diff --git a/libethential/Log.cpp b/libethential/Log.cpp index 952069830..d3e00d683 100644 --- a/libethential/Log.cpp +++ b/libethential/Log.cpp @@ -24,20 +24,20 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; // Logging -int eth::g_logVerbosity = 5; -map eth::g_logOverride; +int dev::g_logVerbosity = 5; +map dev::g_logOverride; -ThreadLocalLogName eth::t_logThreadName("main"); +ThreadLocalLogName dev::t_logThreadName("main"); // foward declare without all of Windows.h #ifdef _WIN32 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString); #endif -void eth::simpleDebugOut(std::string const& _s, char const*) +void dev::simpleDebugOut(std::string const& _s, char const*) { cout << _s << endl << flush; @@ -50,5 +50,5 @@ void eth::simpleDebugOut(std::string const& _s, char const*) #endif } -std::function eth::g_logPost = simpleDebugOut; +std::function dev::g_logPost = simpleDebugOut; diff --git a/libethential/Log.h b/libethential/Log.h index 77a84333c..704660276 100644 --- a/libethential/Log.h +++ b/libethential/Log.h @@ -28,7 +28,7 @@ #include #include "vector_ref.h" -namespace eth +namespace dev { /// The null output stream. Used when logging is disabled. @@ -107,19 +107,19 @@ private: // Simple cout-like stream objects for accessing common log channels. // Dirties the global namespace, but oh so convenient... -#define cnote eth::LogOutputStream() -#define cwarn eth::LogOutputStream() +#define cnote dev::LogOutputStream() +#define cwarn dev::LogOutputStream() // Null stream-like objects. -#define ndebug if (true) {} else eth::NullOutputStream() -#define nlog(X) if (true) {} else eth::NullOutputStream() -#define nslog(X) if (true) {} else eth::NullOutputStream() +#define ndebug if (true) {} else dev::NullOutputStream() +#define nlog(X) if (true) {} else dev::NullOutputStream() +#define nslog(X) if (true) {} else dev::NullOutputStream() // Kill debugging log channel when we're in release mode. #if NDEBUG #define cdebug ndebug #else -#define cdebug eth::LogOutputStream() +#define cdebug dev::LogOutputStream() #endif // Kill all logs when when NLOG is defined. @@ -127,8 +127,8 @@ private: #define clog(X) nlog(X) #define cslog(X) nslog(X) #else -#define clog(X) eth::LogOutputStream() -#define cslog(X) eth::LogOutputStream() +#define clog(X) dev::LogOutputStream() +#define cslog(X) dev::LogOutputStream() #endif } diff --git a/libethential/RLP.cpp b/libethential/RLP.cpp index e8647e8de..68ae02065 100644 --- a/libethential/RLP.cpp +++ b/libethential/RLP.cpp @@ -21,10 +21,10 @@ #include "RLP.h" using namespace std; -using namespace eth; +using namespace dev; -bytes eth::RLPNull = rlp(""); -bytes eth::RLPEmptyList = rlpList(); +bytes dev::RLPNull = rlp(""); +bytes dev::RLPEmptyList = rlpList(); RLP::iterator& RLP::iterator::operator++() { @@ -32,7 +32,7 @@ RLP::iterator& RLP::iterator::operator++() { m_lastItem.retarget(m_lastItem.next().data(), m_remaining); m_lastItem = m_lastItem.cropped(0, RLP(m_lastItem).actualSize()); - m_remaining -= std::min(m_remaining, m_lastItem.size()); + m_remaining -= std::min(m_remaining, m_lastItem.size()); } else m_lastItem.retarget(m_lastItem.next().data(), 0); @@ -54,7 +54,7 @@ RLP::iterator::iterator(RLP const& _parent, bool _begin) } } -RLP RLP::operator[](uint _i) const +RLP RLP::operator[](unsigned _i) const { if (_i < m_lastIndex) { @@ -81,7 +81,7 @@ RLPs RLP::toList() const return ret; } -eth::uint RLP::actualSize() const +unsigned RLP::actualSize() const { if (isNull()) return 0; @@ -118,11 +118,11 @@ bool RLP::isInt() const return false; } -eth::uint RLP::length() const +unsigned RLP::length() const { if (isNull()) return 0; - uint ret = 0; + unsigned ret = 0; byte n = m_data[0]; if (n < c_rlpDataImmLenStart) return 1; @@ -147,12 +147,12 @@ eth::uint RLP::length() const return ret; } -eth::uint RLP::items() const +unsigned RLP::items() const { if (isList()) { bytesConstRef d = payload().cropped(0, length()); - eth::uint i = 0; + unsigned i = 0; for (; d.size(); ++i) d = d.cropped(RLP(d).actualSize()); return i; @@ -160,16 +160,16 @@ eth::uint RLP::items() const return 0; } -RLPStream& RLPStream::appendRaw(bytesConstRef _s, uint _itemCount) +RLPStream& RLPStream::appendRaw(bytesConstRef _s, unsigned _itemCount) { - uint os = m_out.size(); + unsigned os = m_out.size(); m_out.resize(os + _s.size()); memcpy(m_out.data() + os, _s.data(), _s.size()); noteAppended(_itemCount); return *this; } -void RLPStream::noteAppended(uint _itemCount) +void RLPStream::noteAppended(unsigned _itemCount) { if (!_itemCount) return; @@ -184,9 +184,9 @@ void RLPStream::noteAppended(uint _itemCount) { auto p = m_listStack.back().second; m_listStack.pop_back(); - uint s = m_out.size() - p; // list size + unsigned s = m_out.size() - p; // list size auto brs = bytesRequired(s); - uint encodeSize = s < c_rlpListImmLenCount ? 1 : (1 + brs); + unsigned encodeSize = s < c_rlpListImmLenCount ? 1 : (1 + brs); // cdebug << "s: " << s << ", p: " << p << ", m_out.size(): " << m_out.size() << ", encodeSize: " << encodeSize << " (br: " << brs << ")"; auto os = m_out.size(); m_out.resize(os + encodeSize); @@ -205,7 +205,7 @@ void RLPStream::noteAppended(uint _itemCount) } } -RLPStream& RLPStream::appendList(uint _items) +RLPStream& RLPStream::appendList(unsigned _items) { // cdebug << "appendList(" << _items << ")"; if (_items) @@ -227,7 +227,7 @@ RLPStream& RLPStream::appendList(bytesConstRef _rlp) RLPStream& RLPStream::append(bytesConstRef _s, bool _compact) { - uint s = _s.size(); + unsigned s = _s.size(); byte const* d = _s.data(); if (_compact) for (unsigned i = 0; i < _s.size() && !*d; ++i, --s, ++d) {} @@ -254,7 +254,7 @@ RLPStream& RLPStream::append(bigint _i) m_out.push_back((byte)_i); else { - uint br = bytesRequired(_i); + unsigned br = bytesRequired(_i); if (br < c_rlpDataImmLenCount) m_out.push_back((byte)(br + c_rlpDataImmLenStart)); else @@ -269,21 +269,21 @@ RLPStream& RLPStream::append(bigint _i) return *this; } -void RLPStream::pushCount(uint _count, byte _base) +void RLPStream::pushCount(unsigned _count, byte _base) { auto br = bytesRequired(_count); m_out.push_back((byte)(br + _base)); // max 8 bytes. pushInt(_count, br); } -std::ostream& eth::operator<<(std::ostream& _out, eth::RLP const& _d) +std::ostream& dev::operator<<(std::ostream& _out, RLP const& _d) { if (_d.isNull()) _out << "null"; else if (_d.isInt()) _out << std::showbase << std::hex << std::nouppercase << _d.toInt(RLP::LaisezFaire) << dec; else if (_d.isData()) - _out << eth::escaped(_d.toString(), false); + _out << escaped(_d.toString(), false); else if (_d.isList()) { _out << "["; diff --git a/libethential/RLP.h b/libethential/RLP.h index 6d388763f..0398467e7 100644 --- a/libethential/RLP.h +++ b/libethential/RLP.h @@ -33,16 +33,16 @@ #include #include -namespace eth +namespace dev { class RLP; typedef std::vector RLPs; -template struct intTraits { static const uint maxSize = sizeof(_T); }; -template <> struct intTraits { static const uint maxSize = 20; }; -template <> struct intTraits { static const uint maxSize = 32; }; -template <> struct intTraits { static const uint maxSize = ~(uint)0; }; +template struct intTraits { static const unsigned maxSize = sizeof(_T); }; +template <> struct intTraits { static const unsigned maxSize = 20; }; +template <> struct intTraits { static const unsigned maxSize = 32; }; +template <> struct intTraits { static const unsigned maxSize = ~(unsigned)0; }; static const byte c_rlpMaxLengthBytes = 8; static const byte c_rlpDataImmLenStart = 0x80; @@ -72,7 +72,7 @@ public: explicit RLP(bytes const& _d): m_data(&_d) {} /// Construct a node to read RLP data in the bytes given. - RLP(byte const* _b, uint _s): m_data(bytesConstRef(_b, _s)) {} + RLP(byte const* _b, unsigned _s): m_data(bytesConstRef(_b, _s)) {} /// Construct a node to read RLP data in the string. explicit RLP(std::string const& _s): m_data(bytesConstRef((byte const*)_s.data(), _s.size())) {} @@ -99,12 +99,12 @@ public: bool isInt() const; /// @returns the number of items in the list, or zero if it isn't a list. - uint itemCount() const { return isList() ? items() : 0; } - uint itemCountStrict() const { if (!isList()) throw BadCast(); return items(); } + unsigned itemCount() const { return isList() ? items() : 0; } + unsigned itemCountStrict() const { if (!isList()) throw BadCast(); return items(); } /// @returns the number of bytes in the data, or zero if it isn't data. - uint size() const { return isData() ? length() : 0; } - uint sizeStrict() const { if (!isData()) throw BadCast(); return length(); } + unsigned size() const { return isData() ? length() : 0; } + unsigned sizeStrict() const { if (!isData()) throw BadCast(); return length(); } /// Equality operators; does best-effort conversion and checks for equality. bool operator==(char const* _s) const { return isData() && toString() == _s; } @@ -113,8 +113,8 @@ public: bool operator!=(std::string const& _s) const { return isData() && toString() != _s; } template bool operator==(FixedHash<_N> const& _h) const { return isData() && toHash<_N>() == _h; } template bool operator!=(FixedHash<_N> const& _s) const { return isData() && toHash<_N>() != _s; } - bool operator==(uint const& _i) const { return isInt() && toInt() == _i; } - bool operator!=(uint const& _i) const { return isInt() && toInt() != _i; } + bool operator==(unsigned const& _i) const { return isInt() && toInt() == _i; } + bool operator!=(unsigned const& _i) const { return isInt() && toInt() != _i; } bool operator==(u256 const& _i) const { return isInt() && toInt() == _i; } bool operator!=(u256 const& _i) const { return isInt() && toInt() != _i; } bool operator==(bigint const& _i) const { return isInt() && toInt() == _i; } @@ -123,7 +123,7 @@ public: /// Subscript operator. /// @returns the list item @a _i if isList() and @a _i < listItems(), or RLP() otherwise. /// @note if used to access items in ascending order, this is efficient. - RLP operator[](uint _i) const; + RLP operator[](unsigned _i) const; typedef RLP element_type; @@ -146,7 +146,7 @@ public: iterator() {} iterator(RLP const& _parent, bool _begin); - uint m_remaining = 0; + unsigned m_remaining = 0; bytesConstRef m_lastItem; }; @@ -160,7 +160,7 @@ public: explicit operator std::string() const { return toString(); } explicit operator RLPs() const { return toList(); } explicit operator byte() const { return toInt(); } - explicit operator uint() const { return toInt(); } + explicit operator unsigned() const { return toInt(); } explicit operator u256() const { return toInt(); } explicit operator bigint() const { return toInt(); } template explicit operator FixedHash<_N>() const { return toHash>(); } @@ -181,7 +181,7 @@ public: template std::vector toVector() const { std::vector ret; if (isList()) { ret.reserve(itemCount()); for (auto const& i: *this) ret.push_back((T)i); } return ret; } template std::set toSet() const { std::set ret; if (isList()) { for (auto const& i: *this) ret.insert((T)i); } return ret; } template std::pair toPair() const { std::pair ret; if (isList()) { ret.first = (T)((*this)[0]); ret.second = (U)((*this)[1]); } return ret; } - template std::array toArray() const { if (itemCount() != N || !isList()) throw BadCast(); std::array ret; for (uint i = 0; i < N; ++i) ret[i] = (T)operator[](i); return ret; } + template std::array toArray() const { if (itemCount() != N || !isList()) throw BadCast(); std::array ret; for (unsigned i = 0; i < N; ++i) ret[i] = (T)operator[](i); return ret; } /// Int conversion flags enum @@ -194,7 +194,7 @@ public: }; /// Converts to int of type given; if isString(), decodes as big-endian bytestream. @returns 0 if not an int or string. - template _T toInt(int _flags = Strict) const + template _T toInt(int _flags = Strict) const { if ((!isInt() && !(_flags & AllowNonCanon)) || isList() || isNull()) if (_flags & ThrowOnFail) @@ -237,27 +237,27 @@ public: /// @returns the theoretical size of this item. /// @note Under normal circumstances, is equivalent to m_data.size() - use that unless you know it won't work. - uint actualSize() const; + unsigned actualSize() const; private: /// Single-byte data payload. bool isSingleByte() const { return !isNull() && m_data[0] < c_rlpDataImmLenStart; } /// @returns the bytes used to encode the length of the data. Valid for all types. - uint lengthSize() const { if (isData() && m_data[0] > c_rlpDataIndLenZero) return m_data[0] - c_rlpDataIndLenZero; if (isList() && m_data[0] > c_rlpListIndLenZero) return m_data[0] - c_rlpListIndLenZero; return 0; } + unsigned lengthSize() const { if (isData() && m_data[0] > c_rlpDataIndLenZero) return m_data[0] - c_rlpDataIndLenZero; if (isList() && m_data[0] > c_rlpListIndLenZero) return m_data[0] - c_rlpListIndLenZero; return 0; } /// @returns the size in bytes of the payload, as given by the RLP as opposed to as inferred from m_data. - uint length() const; + unsigned length() const; /// @returns the number of data items. - uint items() const; + unsigned items() const; /// Our byte data. bytesConstRef m_data; /// The list-indexing cache. - mutable uint m_lastIndex = (uint)-1; - mutable uint m_lastEnd = 0; + mutable unsigned m_lastIndex = (unsigned)-1; + mutable unsigned m_lastEnd = 0; mutable bytesConstRef m_lastItem; }; @@ -271,12 +271,12 @@ public: RLPStream() {} /// Initializes the RLPStream as a list of @a _listItems items. - explicit RLPStream(uint _listItems) { appendList(_listItems); } + explicit RLPStream(unsigned _listItems) { appendList(_listItems); } ~RLPStream() {} /// Append given datum to the byte stream. - RLPStream& append(uint _s) { return append(bigint(_s)); } + RLPStream& append(unsigned _s) { return append(bigint(_s)); } RLPStream& append(u160 _s) { return append(bigint(_s)); } RLPStream& append(u256 _s) { return append(bigint(_s)); } RLPStream& append(bigint _s); @@ -287,7 +287,7 @@ public: template RLPStream& append(FixedHash _s, bool _compact = false, bool _allOrNothing = false) { return _allOrNothing && !_s ? append(bytesConstRef()) : append(_s.ref(), _compact); } /// Appends an arbitrary RLP fragment - this *must* be a single item. - RLPStream& append(RLP const& _rlp, uint _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); } + RLPStream& append(RLP const& _rlp, unsigned _itemCount = 1) { return appendRaw(_rlp.data(), _itemCount); } /// Appends a sequence of data to the stream as a list. template RLPStream& append(std::vector<_T> const& _s) { return appendVector(_s); } @@ -297,14 +297,14 @@ public: template RLPStream& append(std::pair const& _s) { appendList(2); append(_s.first); append(_s.second); return *this; } /// Appends a list. - RLPStream& appendList(uint _items); + RLPStream& appendList(unsigned _items); RLPStream& appendList(bytesConstRef _rlp); RLPStream& appendList(bytes const& _rlp) { return appendList(&_rlp); } RLPStream& appendList(RLPStream const& _s) { return appendList(&_s.out()); } /// Appends raw (pre-serialised) RLP data. Use with caution. - RLPStream& appendRaw(bytesConstRef _rlp, uint _itemCount = 1); - RLPStream& appendRaw(bytes const& _rlp, uint _itemCount = 1) { return appendRaw(&_rlp, _itemCount); } + RLPStream& appendRaw(bytesConstRef _rlp, unsigned _itemCount = 1); + RLPStream& appendRaw(bytes const& _rlp, unsigned _itemCount = 1) { return appendRaw(&_rlp, _itemCount); } /// Shift operators for appending data items. template RLPStream& operator<<(T _data) { return append(_data); } @@ -319,14 +319,14 @@ public: void swapOut(bytes& _dest) { assert(m_listStack.empty()); swap(m_out, _dest); } private: - void noteAppended(uint _itemCount = 1); + void noteAppended(unsigned _itemCount = 1); /// Push the node-type byte (using @a _base) along with the item count @a _count. /// @arg _count is number of characters for strings, data-bytes for ints, or items for lists. - void pushCount(uint _count, byte _offset); + void pushCount(unsigned _count, byte _offset); /// Push an integer as a raw big-endian byte-stream. - template void pushInt(_T _i, uint _br) + template void pushInt(_T _i, unsigned _br) { m_out.resize(m_out.size() + _br); byte* b = &m_out.back(); @@ -337,7 +337,7 @@ private: /// Our output byte stream. bytes m_out; - std::vector> m_listStack; + std::vector> m_listStack; }; template void rlpListAux(RLPStream& _out, _T _t) { _out << _t; } @@ -362,6 +362,6 @@ extern bytes RLPNull; extern bytes RLPEmptyList; /// Human readable version of RLP. -std::ostream& operator<<(std::ostream& _out, eth::RLP const& _d); +std::ostream& operator<<(std::ostream& _out, dev::RLP const& _d); } diff --git a/libethential/vector_ref.h b/libethential/vector_ref.h index 4bde3f582..be2fea13c 100644 --- a/libethential/vector_ref.h +++ b/libethential/vector_ref.h @@ -5,12 +5,7 @@ #include #include -#pragma warning(push) -#pragma warning(disable: 4100 4267) -#include -#pragma warning(pop) - -namespace eth +namespace dev { template @@ -26,8 +21,9 @@ public: vector_ref(std::string* _data): m_data((_T*)_data->data()), m_count(_data->size() / sizeof(_T)) {} vector_ref(typename std::conditional::value, std::vector::type> const*, std::vector<_T>*>::type _data): m_data(_data->data()), m_count(_data->size()) {} vector_ref(typename std::conditional::value, std::string const&, std::string&>::type _data): m_data((_T*)_data.data()), m_count(_data.size() / sizeof(_T)) {} +#ifdef STORAGE_LEVELDB_INCLUDE_DB_H_ vector_ref(leveldb::Slice const& _s): m_data(_s.data()), m_count(_s.size() / sizeof(_T)) {} - +#endif explicit operator bool() const { return m_data && m_count; } bool contentsEqual(std::vector const& _c) const { return _c.size() == m_count && !memcmp(_c.data(), m_data, m_count); } @@ -56,7 +52,9 @@ public: bool operator==(vector_ref<_T> const& _cmp) const { return m_data == _cmp.m_data && m_count == _cmp.m_count; } bool operator!=(vector_ref<_T> const& _cmp) const { return !operator==(_cmp); } +#ifdef STORAGE_LEVELDB_INCLUDE_DB_H_ operator leveldb::Slice() const { return leveldb::Slice((char const*)m_data, m_count * sizeof(_T)); } +#endif void reset() { m_data = nullptr; m_count = 0; } diff --git a/libethereum/AccountDiff.cpp b/libethereum/AccountDiff.cpp index 5b469508f..08d6d8859 100644 --- a/libethereum/AccountDiff.cpp +++ b/libethereum/AccountDiff.cpp @@ -23,7 +23,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; AccountChange AccountDiff::changeType() const { @@ -39,7 +40,9 @@ char const* AccountDiff::lead() const return exist ? exist.from() ? "XXX" : "+++" : (bn && sc) ? "***" : bn ? " * " : sc ? "* *" : " "; } -std::ostream& eth::operator<<(std::ostream& _out, AccountDiff const& _s) +namespace dev { + +std::ostream& operator<<(std::ostream& _out, dev::eth::AccountDiff const& _s) { if (!_s.exist.to()) return _out; @@ -68,10 +71,14 @@ std::ostream& eth::operator<<(std::ostream& _out, AccountDiff const& _s) return _out; } -std::ostream& eth::operator<<(std::ostream& _out, StateDiff const& _s) +std::ostream& operator<<(std::ostream& _out, dev::eth::StateDiff const& _s) { _out << _s.accounts.size() << " accounts changed:" << endl; + dev::eth::AccountDiff d; + _out << d; for (auto const& i: _s.accounts) _out << i.second.lead() << " " << i.first << ": " << i.second << endl; return _out; } + +} diff --git a/libethereum/AccountDiff.h b/libethereum/AccountDiff.h index a4a074e04..4d8f63f0a 100644 --- a/libethereum/AccountDiff.h +++ b/libethereum/AccountDiff.h @@ -24,6 +24,8 @@ #include #include +namespace dev +{ namespace eth { @@ -65,9 +67,10 @@ struct StateDiff std::map accounts; }; -std::ostream& operator<<(std::ostream& _out, StateDiff const& _s); -std::ostream& operator<<(std::ostream& _out, AccountDiff const& _s); - } +std::ostream& operator<<(std::ostream& _out, dev::eth::StateDiff const& _s); +std::ostream& operator<<(std::ostream& _out, dev::eth::AccountDiff const& _s); + +} diff --git a/libethereum/AddressState.cpp b/libethereum/AddressState.cpp index a3eb65acb..268440314 100644 --- a/libethereum/AddressState.cpp +++ b/libethereum/AddressState.cpp @@ -22,7 +22,8 @@ #include "AddressState.h" #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; #pragma GCC diagnostic ignored "-Wunused-variable" namespace { char dummy; }; diff --git a/libethereum/AddressState.h b/libethereum/AddressState.h index 3425dc4d1..c7df6523b 100644 --- a/libethereum/AddressState.h +++ b/libethereum/AddressState.h @@ -25,6 +25,8 @@ #include #include +namespace dev +{ namespace eth { @@ -78,5 +80,5 @@ private: }; } - +} diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 97d69eb41..e9dfa0519 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -31,11 +31,12 @@ #include "State.h" #include "Defaults.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; #define ETH_CATCH 1 -std::ostream& eth::operator<<(std::ostream& _out, BlockChain const& _bc) +std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc) { string cmp = toBigEndianString(_bc.currentHash()); auto it = _bc.m_extrasDB->NewIterator(_bc.m_readOptions); @@ -49,7 +50,7 @@ std::ostream& eth::operator<<(std::ostream& _out, BlockChain const& _bc) return _out; } -std::map const& eth::genesisState() +std::map const& dev::eth::genesisState() { static std::map s_ret; if (s_ret.empty()) @@ -71,7 +72,7 @@ std::map const& eth::genesisState() BlockInfo* BlockChain::s_genesis = nullptr; boost::shared_mutex BlockChain::x_genesis; -ldb::Slice eth::toSlice(h256 _h, unsigned _sub) +ldb::Slice dev::eth::toSlice(h256 _h, unsigned _sub) { #if ALL_COMPILERS_ARE_CPP11_COMPLIANT static thread_local h256 h = _h ^ h256(u256(_sub)); @@ -95,12 +96,12 @@ bytes BlockChain::createGenesisBlock() MemoryDB db; TrieDB state(&db); state.init(); - eth::commit(genesisState(), db, state); + dev::eth::commit(genesisState(), db, state); stateRoot = state.root(); } block.appendList(13) << h256() << sha3EmptyList << h160(); - block.append(stateRoot, false, true) << bytes() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (uint)0 << string() << sha3(bytes(1, 42)); + block.append(stateRoot, false, true) << bytes() << c_genesisDifficulty << 0 << 0 << 1000000 << 0 << (unsigned)0 << string() << sha3(bytes(1, 42)); block.appendRaw(RLPEmptyList); block.appendRaw(RLPEmptyList); return block.out(); @@ -135,7 +136,7 @@ BlockChain::BlockChain(std::string _path, bool _killExisting) // Insert details of genesis block. m_details[m_genesisHash] = BlockDetails(0, c_genesisDifficulty, h256(), {}, h256()); auto r = m_details[m_genesisHash].rlp(); - m_extrasDB->Put(m_writeOptions, ldb::Slice((char const*)&m_genesisHash, 32), (ldb::Slice)eth::ref(r)); + m_extrasDB->Put(m_writeOptions, ldb::Slice((char const*)&m_genesisHash, 32), (ldb::Slice)dev::ref(r)); } checkConsistency(); @@ -287,7 +288,7 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db) // All ok - insert into DB { WriteGuard l(x_details); - m_details[newHash] = BlockDetails((uint)pd.number + 1, td, bi.parentHash, {}, b); + m_details[newHash] = BlockDetails((unsigned)pd.number + 1, td, bi.parentHash, {}, b); m_details[bi.parentHash].children.push_back(newHash); } { @@ -299,10 +300,10 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db) m_traces[newHash] = bt; } - m_extrasDB->Put(m_writeOptions, toSlice(newHash), (ldb::Slice)eth::ref(m_details[newHash].rlp())); - m_extrasDB->Put(m_writeOptions, toSlice(bi.parentHash), (ldb::Slice)eth::ref(m_details[bi.parentHash].rlp())); - m_extrasDB->Put(m_writeOptions, toSlice(newHash, 1), (ldb::Slice)eth::ref(m_blooms[newHash].rlp())); - m_extrasDB->Put(m_writeOptions, toSlice(newHash, 2), (ldb::Slice)eth::ref(m_traces[newHash].rlp())); + m_extrasDB->Put(m_writeOptions, toSlice(newHash), (ldb::Slice)dev::ref(m_details[newHash].rlp())); + m_extrasDB->Put(m_writeOptions, toSlice(bi.parentHash), (ldb::Slice)dev::ref(m_details[bi.parentHash].rlp())); + m_extrasDB->Put(m_writeOptions, toSlice(newHash, 1), (ldb::Slice)dev::ref(m_blooms[newHash].rlp())); + m_extrasDB->Put(m_writeOptions, toSlice(newHash, 2), (ldb::Slice)dev::ref(m_traces[newHash].rlp())); m_db->Put(m_writeOptions, toSlice(newHash), (ldb::Slice)ref(_block)); #if ETH_PARANOIA diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index cbae012ba..200740782 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -21,6 +21,11 @@ #pragma once +#pragma warning(push) +#pragma warning(disable: 4100 4267) +#include +#pragma warning(pop) + #include #include #include @@ -31,6 +36,8 @@ #include "BlockQueue.h" namespace ldb = leveldb; +namespace dev +{ namespace eth { @@ -95,8 +102,8 @@ public: bytes block() const { return block(currentHash()); } /// Get a number for the given hash (or the most recent mined if none given). Thread-safe. - uint number(h256 _hash) const { return details(_hash).number; } - uint number() const { return number(currentHash()); } + unsigned number(h256 _hash) const { return details(_hash).number; } + unsigned number() const { return number(currentHash()); } /// Get a given block (RLP format). Thread-safe. h256 currentHash() const { ReadGuard l(x_lastBlockHash); return m_lastBlockHash; } @@ -195,3 +202,4 @@ private: std::ostream& operator<<(std::ostream& _out, BlockChain const& _bc); } +} diff --git a/libethereum/BlockDetails.cpp b/libethereum/BlockDetails.cpp index ae107fa68..eac40920e 100644 --- a/libethereum/BlockDetails.cpp +++ b/libethereum/BlockDetails.cpp @@ -23,11 +23,12 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; BlockDetails::BlockDetails(RLP const& _r) { - number = _r[0].toInt(); + number = _r[0].toInt(); totalDifficulty = _r[1].toInt(); parent = _r[2].toHash(); children = _r[3].toVector(); diff --git a/libethereum/BlockDetails.h b/libethereum/BlockDetails.h index 6db2171ee..21e5e7d13 100644 --- a/libethereum/BlockDetails.h +++ b/libethereum/BlockDetails.h @@ -21,25 +21,32 @@ #pragma once +#pragma warning(push) +#pragma warning(disable: 4100 4267) +#include +#pragma warning(pop) + #include #include #include "Manifest.h" namespace ldb = leveldb; +namespace dev +{ namespace eth { struct BlockDetails { BlockDetails(): number(0), totalDifficulty(0) {} - BlockDetails(uint _n, u256 _tD, h256 _p, h256s _c, h256 _bloom): number(_n), totalDifficulty(_tD), parent(_p), children(_c), bloom(_bloom) {} + BlockDetails(unsigned _n, u256 _tD, h256 _p, h256s _c, h256 _bloom): number(_n), totalDifficulty(_tD), parent(_p), children(_c), bloom(_bloom) {} BlockDetails(RLP const& _r); bytes rlp() const; bool isNull() const { return !totalDifficulty; } explicit operator bool() const { return !isNull(); } - uint number; // TODO: remove? + unsigned number; // TODO: remove? u256 totalDifficulty; h256 parent; h256s children; @@ -74,3 +81,4 @@ static const BlockBlooms NullBlockBlooms; static const BlockTraces NullBlockTraces; } +} diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 1aca07847..00b64c8bc 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -26,7 +26,8 @@ #include #include "BlockChain.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; bool BlockQueue::import(bytesConstRef _block, BlockChain const& _bc) { diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index 30686d192..b8586a553 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -26,6 +26,8 @@ #include "libethcore/CommonEth.h" #include +namespace dev +{ namespace eth { @@ -67,5 +69,4 @@ private: }; } - - +} diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 872892b23..afefa1d4f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -29,7 +29,8 @@ #include "Defaults.h" #include "EthereumHost.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace p2p; VersionChecker::VersionChecker(string const& _dbPath): diff --git a/libethereum/Client.h b/libethereum/Client.h index 4eb65b7ba..254fd1631 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -40,6 +40,8 @@ #include "MessageFilter.h" #include "Miner.h" +namespace dev +{ namespace eth { @@ -94,13 +96,13 @@ struct ClientWatch }; struct WatchChannel: public LogChannel { static const char* name() { return "(o)"; } static const int verbosity = 7; }; -#define cwatch eth::LogOutputStream() +#define cwatch dev::LogOutputStream() struct WorkInChannel: public LogChannel { static const char* name() { return ">W>"; } static const int verbosity = 16; }; struct WorkOutChannel: public LogChannel { static const char* name() { return "() -#define cworkin eth::LogOutputStream() -#define cworkout eth::LogOutputStream() +#define cwork dev::LogOutputStream() +#define cworkin dev::LogOutputStream() +#define cworkout dev::LogOutputStream() /** * @brief Main API hub for interfacing with Ethereum. @@ -176,19 +178,19 @@ public: std::vector
addresses(int _block) const; /// Get the fee associated for a transaction with the given data. - static u256 txGas(uint _dataCount, u256 _gas = 0) { return c_txDataGas * _dataCount + c_txGas + _gas; } + static u256 txGas(unsigned _dataCount, u256 _gas = 0) { return c_txDataGas * _dataCount + c_txGas + _gas; } /// Get the remaining gas limit in this block. u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); } // [PRIVATE API - only relevant for base clients, not available in general] - eth::State state(unsigned _txi, h256 _block) const; - eth::State state(h256 _block) const; - eth::State state(unsigned _txi) const; + dev::eth::State state(unsigned _txi, h256 _block) const; + dev::eth::State state(h256 _block) const; + dev::eth::State state(unsigned _txi) const; /// Get the object representing the current state of Ethereum. - eth::State postState() const { ReadGuard l(x_stateDB); return m_postMine; } + dev::eth::State postState() const { ReadGuard l(x_stateDB); return m_postMine; } /// Get the object representing the current canonical blockchain. BlockChain const& blockChain() const { return m_bc; } @@ -325,10 +327,13 @@ private: class Watch; +} } -namespace std { void swap(eth::Watch& _a, eth::Watch& _b); } +namespace std { void swap(dev::eth::Watch& _a, dev::eth::Watch& _b); } +namespace dev +{ namespace eth { @@ -351,12 +356,13 @@ private: unsigned m_id; }; +} } namespace std { -inline void swap(eth::Watch& _a, eth::Watch& _b) +inline void swap(dev::eth::Watch& _a, dev::eth::Watch& _b) { swap(_a.m_c, _b.m_c); swap(_a.m_id, _b.m_id); diff --git a/libethereum/CommonNet.cpp b/libethereum/CommonNet.cpp index 9bc277f86..acf8e220f 100644 --- a/libethereum/CommonNet.cpp +++ b/libethereum/CommonNet.cpp @@ -21,4 +21,5 @@ #include "CommonNet.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; diff --git a/libethereum/CommonNet.h b/libethereum/CommonNet.h index a6c6217d7..a4484ffb8 100644 --- a/libethereum/CommonNet.h +++ b/libethereum/CommonNet.h @@ -28,13 +28,15 @@ #include #include +namespace dev +{ namespace eth { -static const eth::uint c_maxHashes = 32; ///< Maximum number of hashes BlockHashes will ever send. -static const eth::uint c_maxHashesAsk = 32; ///< Maximum number of hashes GetBlockHashes will ever ask for. -static const eth::uint c_maxBlocks = 16; ///< Maximum number of blocks Blocks will ever send. -static const eth::uint c_maxBlocksAsk = 16; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). +static const unsigned c_maxHashes = 32; ///< Maximum number of hashes BlockHashes will ever send. +static const unsigned c_maxHashesAsk = 32; ///< Maximum number of hashes GetBlockHashes will ever ask for. +static const unsigned c_maxBlocks = 16; ///< Maximum number of blocks Blocks will ever send. +static const unsigned c_maxBlocksAsk = 16; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). class OverlayDB; class BlockChain; @@ -54,3 +56,4 @@ enum EthereumPacket }; } +} diff --git a/libethereum/Defaults.cpp b/libethereum/Defaults.cpp index e78156094..17d773427 100644 --- a/libethereum/Defaults.cpp +++ b/libethereum/Defaults.cpp @@ -23,7 +23,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; Defaults* Defaults::s_this = nullptr; diff --git a/libethereum/Defaults.h b/libethereum/Defaults.h index d4bd5322f..e0478455d 100644 --- a/libethereum/Defaults.h +++ b/libethereum/Defaults.h @@ -23,6 +23,8 @@ #include +namespace dev +{ namespace eth { @@ -45,3 +47,4 @@ private: }; } +} diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 0f63712bb..0ba544248 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -35,7 +35,8 @@ #include "BlockQueue.h" #include "EthereumPeer.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace p2p; EthereumHost::EthereumHost(BlockChain const& _ch, u256 _networkId): @@ -139,7 +140,7 @@ void EthereumHost::maintainTransactions(TransactionQueue& _tq, h256 _currentHash { auto ep = p->cap(); bytes b; - uint n = 0; + unsigned n = 0; for (auto const& i: _tq.transactions()) if ((!m_transactionsSent.count(i.first) && !ep->m_knownTransactions.count(i.first)) || ep->m_requireTransactions || resendAll) { diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index 0ee56b9cf..e0cf5200b 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -34,10 +34,14 @@ #include "CommonNet.h" #include "EthereumPeer.h" -namespace eth +namespace dev { class RLPStream; + +namespace eth +{ + class TransactionQueue; class BlockQueue; @@ -103,3 +107,4 @@ private: }; } +} diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 3dc5dafc9..45165d348 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -28,10 +28,11 @@ #include "BlockChain.h" #include "EthereumHost.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace p2p; -#define clogS(X) eth::LogOutputStream(false) << "| " << std::setw(2) << session()->socketId() << "] " +#define clogS(X) dev::LogOutputStream(false) << "| " << std::setw(2) << session()->socketId() << "] " EthereumPeer::EthereumPeer(Session* _s, HostCapabilityFace* _h): Capability(_s, _h) @@ -73,7 +74,7 @@ void EthereumPeer::startInitialSync() } h256 c = host()->m_chain->currentHash(); - uint n = host()->m_chain->number(); + unsigned n = host()->m_chain->number(); u256 td = max(host()->m_chain->details().totalDifficulty, host()->m_totalDifficultyOfNeeded); clogS(NetAllDetail) << "Initial sync. Latest:" << c.abridged() << ", number:" << n << ", TD: max(" << host()->m_chain->details().totalDifficulty << "," << host()->m_totalDifficultyOfNeeded << ") versus " << m_totalDifficulty; @@ -123,7 +124,7 @@ bool EthereumPeer::interpret(RLP const& _r) { case StatusPacket: { - m_protocolVersion = _r[1].toInt(); + m_protocolVersion = _r[1].toInt(); m_networkId = _r[2].toInt(); m_totalDifficulty = _r[3].toInt(); m_latestHash = _r[4].toHash(); diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index b799de314..c0c75f646 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -31,6 +31,8 @@ #include #include "CommonNet.h" +namespace dev +{ namespace eth { @@ -65,7 +67,7 @@ private: void giveUpOnFetch(); - uint m_protocolVersion; + unsigned m_protocolVersion; u256 m_networkId; h256 m_latestHash; ///< Peer's latest block's hash. @@ -83,3 +85,4 @@ private: }; } +} diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 7fbd36102..e8c1fd1cb 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -25,7 +25,8 @@ #include "State.h" #include "ExtVM.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; #define ETH_VMTRACE 1 @@ -157,8 +158,8 @@ OnOpFunc Executive::simpleTrace() o << " STORAGE" << endl; for (auto const& i: ext.state().storage(ext.myAddress)) o << showbase << hex << i.first << ": " << i.second << endl; - eth::LogOutputStream(true) << o.str(); - eth::LogOutputStream(false) << " | " << dec << ext.level << " | " << ext.myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << dec << vm.gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32" << " ]"; + dev::LogOutputStream(true) << o.str(); + dev::LogOutputStream(false) << " | " << dec << ext.level << " | " << ext.myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << dec << vm.gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32" << " ]"; }; } diff --git a/libethereum/Executive.h b/libethereum/Executive.h index e7ba44223..80e1035c9 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -29,6 +29,8 @@ #include "Transaction.h" #include "Manifest.h" +namespace dev +{ namespace eth { @@ -78,3 +80,4 @@ private: }; } +} diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index f3d8bee50..b4db1975e 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -27,6 +27,8 @@ #include #include "State.h" +namespace dev +{ namespace eth { @@ -122,5 +124,5 @@ private: }; } - +} diff --git a/libethereum/Manifest.cpp b/libethereum/Manifest.cpp index d5d7e2df9..2d1e4aa6e 100644 --- a/libethereum/Manifest.cpp +++ b/libethereum/Manifest.cpp @@ -21,7 +21,8 @@ #include "Manifest.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; Manifest::Manifest(bytesConstRef _r) { diff --git a/libethereum/Manifest.h b/libethereum/Manifest.h index 0a873afc6..2f83d0cab 100644 --- a/libethereum/Manifest.h +++ b/libethereum/Manifest.h @@ -26,6 +26,8 @@ #include #include +namespace dev +{ namespace eth { @@ -68,3 +70,4 @@ struct Manifest }; } +} diff --git a/libethereum/MessageFilter.cpp b/libethereum/MessageFilter.cpp index 786440775..537bc4a9b 100644 --- a/libethereum/MessageFilter.cpp +++ b/libethereum/MessageFilter.cpp @@ -24,7 +24,8 @@ #include #include "State.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; void MessageFilter::fillStream(RLPStream& _s) const { @@ -35,7 +36,7 @@ h256 MessageFilter::sha3() const { RLPStream s; fillStream(s); - return eth::sha3(s.out()); + return dev::eth::sha3(s.out()); } bool MessageFilter::matches(h256 _bloom) const diff --git a/libethereum/MessageFilter.h b/libethereum/MessageFilter.h index cefc424c0..8c44ce449 100644 --- a/libethereum/MessageFilter.h +++ b/libethereum/MessageFilter.h @@ -26,6 +26,8 @@ #include #include "PastMessage.h" +namespace dev +{ namespace eth { @@ -71,3 +73,4 @@ private: }; } +} diff --git a/libethereum/Miner.cpp b/libethereum/Miner.cpp index 3c0a8b003..95789889f 100644 --- a/libethereum/Miner.cpp +++ b/libethereum/Miner.cpp @@ -23,7 +23,8 @@ #include "Miner.h" #include "State.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; Miner::Miner(MinerHost* _host, unsigned _id): m_host(_host), diff --git a/libethereum/Miner.h b/libethereum/Miner.h index c0aa09d56..46f59d0f5 100644 --- a/libethereum/Miner.h +++ b/libethereum/Miner.h @@ -29,6 +29,8 @@ #include #include "State.h" +namespace dev +{ namespace eth { @@ -41,8 +43,8 @@ struct MineProgress double requirement = 0; ///< The PoW requirement - as the second logarithm of the minimum acceptable hash. double best = 1e99; ///< The PoW achievement - as the second logarithm of the minimum found hash. double current = 0; ///< The most recent PoW achievement - as the second logarithm of the presently found hash. - uint hashes = 0; ///< Total number of hashes computed. - uint ms = 0; ///< Total number of milliseconds of mining thus far. + unsigned hashes = 0; ///< Total number of hashes computed. + unsigned ms = 0; ///< Total number of milliseconds of mining thus far. }; /** @@ -139,3 +141,4 @@ private: }; } +} diff --git a/libethereum/PastMessage.cpp b/libethereum/PastMessage.cpp index 852d4a4bd..377b7e4d2 100644 --- a/libethereum/PastMessage.cpp +++ b/libethereum/PastMessage.cpp @@ -21,4 +21,5 @@ #include "PastMessage.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; diff --git a/libethereum/PastMessage.h b/libethereum/PastMessage.h index 789ce350a..1b7f79527 100644 --- a/libethereum/PastMessage.h +++ b/libethereum/PastMessage.h @@ -25,6 +25,8 @@ #include #include "Manifest.h" +namespace dev +{ namespace eth { @@ -51,3 +53,4 @@ struct PastMessage typedef std::vector PastMessages; } +} diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 5ef528c58..9ff089566 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -33,7 +33,8 @@ #include "Defaults.h" #include "ExtVM.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; #define ctrace clog(StateTrace) @@ -72,7 +73,7 @@ State::State(Address _coinbaseAddress, OverlayDB const& _db): paranoia("beginning of normal construction.", true); - eth::commit(genesisState(), m_db, m_state); + dev::eth::commit(genesisState(), m_db, m_state); m_db.commit(); paranoia("after DB commit of normal construction.", true); @@ -300,7 +301,7 @@ void State::ensureCached(std::map& _cache, Address _a, bo void State::commit() { - eth::commit(m_cache, m_db, m_state); + dev::eth::commit(m_cache, m_db, m_state); m_cache.clear(); } @@ -761,7 +762,7 @@ void State::commitToMine(BlockChain const& _bc) m_currentBlock.parentHash = m_previousBlock.hash; } -MineInfo State::mine(uint _msTimeout, bool _turbo) +MineInfo State::mine(unsigned _msTimeout, bool _turbo) { // Update difficulty according to timestamp. m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock); @@ -1200,7 +1201,7 @@ void State::applyRewards(Addresses const& _uncleAddresses) addBalance(m_currentBlock.coinbaseAddress, r); } -std::ostream& eth::operator<<(std::ostream& _out, State const& _s) +std::ostream& dev::eth::operator<<(std::ostream& _out, State const& _s) { _out << "--- " << _s.rootHash() << std::endl; std::set
d; diff --git a/libethereum/State.h b/libethereum/State.h index d2aa97632..1a45b89ba 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -38,6 +38,8 @@ #include "Executive.h" #include "AccountDiff.h" +namespace dev +{ namespace eth { @@ -120,7 +122,7 @@ public: /// This function is thread-safe. You can safely have other interactions with this object while it is happening. /// @param _msTimeout Timeout before return in milliseconds. /// @returns Information on the mining. - MineInfo mine(uint _msTimeout = 1000, bool _turbo = false); + MineInfo mine(unsigned _msTimeout = 1000, bool _turbo = false); /** Commit to DB and build the final block if the previous call to mine()'s result is completion. * Typically looks like: @@ -363,5 +365,5 @@ void commit(std::map const& _cache, DB& _db, TrieDB #include "Transaction.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; #define ETH_ADDRESS_DEBUG 0 @@ -78,7 +79,7 @@ Address Transaction::sender() const throw InvalidSignature(); // TODO: check right160 is correct and shouldn't be left160. - m_sender = right160(eth::sha3(bytesConstRef(&(pubkey[1]), 64))); + m_sender = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); #if ETH_ADDRESS_DEBUG cout << "---- RECOVER -------------------------------" << endl; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 9e0ab3009..7aba44dcd 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -25,6 +25,8 @@ #include #include +namespace dev +{ namespace eth { @@ -65,8 +67,8 @@ struct Transaction void fillStream(RLPStream& _s, bool _sig = true) const; bytes rlp(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return s.out(); } std::string rlpString(bool _sig = true) const { return asString(rlp(_sig)); } - h256 sha3(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return eth::sha3(s.out()); } - bytes sha3Bytes(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return eth::sha3Bytes(s.out()); } + h256 sha3(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::eth::sha3(s.out()); } + bytes sha3Bytes(bool _sig = true) const { RLPStream s; fillStream(s, _sig); return dev::eth::sha3Bytes(s.out()); } private: mutable Address m_sender; @@ -94,5 +96,4 @@ inline std::ostream& operator<<(std::ostream& _out, Transaction const& _t) } } - - +} diff --git a/libethereum/TransactionQueue.cpp b/libethereum/TransactionQueue.cpp index c2f03ddf1..4fb6c2299 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -25,7 +25,8 @@ #include #include "Transaction.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; bool TransactionQueue::import(bytesConstRef _transactionRLP) { diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index 41cefc56f..6cf3bc250 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -26,6 +26,8 @@ #include "libethcore/CommonEth.h" #include +namespace dev +{ namespace eth { @@ -58,5 +60,5 @@ private: }; } - +} diff --git a/libethereum/Utility.cpp b/libethereum/Utility.cpp index 894041c59..b6653fe39 100644 --- a/libethereum/Utility.cpp +++ b/libethereum/Utility.cpp @@ -24,9 +24,10 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -bytes eth::parseData(string const& _args) +bytes dev::eth::parseData(string const& _args) { bytes m_data; @@ -41,12 +42,12 @@ bytes eth::parseData(string const& _args) { u256 v((string)what[2]); if (what[6] == "szabo") - v *= eth::szabo; + v *= dev::eth::szabo; else if (what[5] == "finney") - v *= eth::finney; + v *= dev::eth::finney; else if (what[4] == "ether") - v *= eth::ether; - bytes bs = eth::toCompactBigEndian(v); + v *= dev::eth::ether; + bytes bs = dev::toCompactBigEndian(v); if (what[1] != "$") for (auto i = bs.size(); i < 32; ++i) m_data.push_back(0); diff --git a/libethereum/Utility.h b/libethereum/Utility.h index 8a0f5217d..0f9d178ff 100644 --- a/libethereum/Utility.h +++ b/libethereum/Utility.h @@ -24,9 +24,12 @@ #include #include +namespace dev +{ namespace eth { bytes parseData(std::string const& _args); } +} diff --git a/libethereumx/Ethereum.cpp b/libethereumx/Ethereum.cpp index f2793a366..d1968b7fa 100644 --- a/libethereumx/Ethereum.cpp +++ b/libethereumx/Ethereum.cpp @@ -24,7 +24,8 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace p2p; Ethereum::Ethereum() diff --git a/libethereumx/Ethereum.h b/libethereumx/Ethereum.h index 9f08234fe..517010b93 100644 --- a/libethereumx/Ethereum.h +++ b/libethereumx/Ethereum.h @@ -36,6 +36,8 @@ #include #include +namespace dev +{ namespace eth { @@ -143,3 +145,4 @@ private: }; } +} diff --git a/libevm/ExtVMFace.cpp b/libevm/ExtVMFace.cpp index bdaa8f8a6..7c938417a 100644 --- a/libevm/ExtVMFace.cpp +++ b/libevm/ExtVMFace.cpp @@ -22,7 +22,8 @@ #include "ExtVMFace.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytesConstRef _code, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock): myAddress(_myAddress), diff --git a/libevm/ExtVMFace.h b/libevm/ExtVMFace.h index 2c32c74f4..e768519de 100644 --- a/libevm/ExtVMFace.h +++ b/libevm/ExtVMFace.h @@ -26,6 +26,8 @@ #include #include +namespace dev +{ namespace eth { @@ -107,3 +109,4 @@ public: }; } +} diff --git a/libevm/FeeStructure.cpp b/libevm/FeeStructure.cpp index f7dbbfbf8..d29b9fef9 100644 --- a/libevm/FeeStructure.cpp +++ b/libevm/FeeStructure.cpp @@ -22,15 +22,16 @@ #include "FeeStructure.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -u256 const eth::c_stepGas = 1; -u256 const eth::c_balanceGas = 20; -u256 const eth::c_sha3Gas = 20; -u256 const eth::c_sloadGas = 20; -u256 const eth::c_sstoreGas = 100; -u256 const eth::c_createGas = 100; -u256 const eth::c_callGas = 20; -u256 const eth::c_memoryGas = 1; -u256 const eth::c_txDataGas = 5; -u256 const eth::c_txGas = 500; +u256 const dev::eth::c_stepGas = 1; +u256 const dev::eth::c_balanceGas = 20; +u256 const dev::eth::c_sha3Gas = 20; +u256 const dev::eth::c_sloadGas = 20; +u256 const dev::eth::c_sstoreGas = 100; +u256 const dev::eth::c_createGas = 100; +u256 const dev::eth::c_callGas = 20; +u256 const dev::eth::c_memoryGas = 1; +u256 const dev::eth::c_txDataGas = 5; +u256 const dev::eth::c_txGas = 500; diff --git a/libevm/FeeStructure.h b/libevm/FeeStructure.h index 341c81f8c..364a6de0d 100644 --- a/libevm/FeeStructure.h +++ b/libevm/FeeStructure.h @@ -23,6 +23,8 @@ #include +namespace dev +{ namespace eth { @@ -38,3 +40,4 @@ extern u256 const c_txDataGas; ///< Per byte of data attached to a transaction extern u256 const c_txGas; ///< Per transaction. NOTE: Not payable on data of calls between transactions. } +} diff --git a/libevm/VM.cpp b/libevm/VM.cpp index 5383f4906..e47237d5a 100644 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -22,7 +22,8 @@ #include "VM.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; void VM::reset(u256 _gas) { diff --git a/libevm/VM.h b/libevm/VM.h index 76b68a11c..e774a1787 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -30,6 +30,8 @@ #include "FeeStructure.h" #include "ExtVMFace.h" +namespace dev +{ namespace eth { @@ -87,9 +89,9 @@ private: } // INLINE: -template eth::bytesConstRef eth::VM::go(Ext& _ext, OnOpFunc const& _onOp, uint64_t _steps) +template dev::bytesConstRef dev::eth::VM::go(Ext& _ext, OnOpFunc const& _onOp, uint64_t _steps) { - auto memNeed = [](eth::u256 _offset, eth::u256 _size) { return _size ? _offset + _size : 0; }; + auto memNeed = [](dev::u256 _offset, dev::u256 _size) { return _size ? _offset + _size : 0; }; u256 nextPC = m_curPC + 1; auto osteps = _steps; @@ -310,7 +312,7 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, OnOpFunc const& _ break; case Instruction::BYTE: require(2); - m_stack[m_stack.size() - 2] = m_stack.back() < 32 ? (m_stack[m_stack.size() - 2] >> (uint)(8 * (31 - m_stack.back()))) & 0xff : 0; + m_stack[m_stack.size() - 2] = m_stack.back() < 32 ? (m_stack[m_stack.size() - 2] >> (unsigned)(8 * (31 - m_stack.back()))) & 0xff : 0; m_stack.pop_back(); break; case Instruction::ADDMOD: @@ -688,4 +690,4 @@ template eth::bytesConstRef eth::VM::go(Ext& _ext, OnOpFunc const& _ throw StepsDone(); return bytesConstRef(); } - +} diff --git a/libevmface/Instruction.cpp b/libevmface/Instruction.cpp index 7d6fdd366..83dc22c42 100644 --- a/libevmface/Instruction.cpp +++ b/libevmface/Instruction.cpp @@ -23,9 +23,10 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -const std::map eth::c_instructions = +const std::map dev::eth::c_instructions = { { "STOP", Instruction::STOP }, { "ADD", Instruction::ADD }, @@ -279,10 +280,10 @@ static const std::map c_instructionInfo = { Instruction::SUICIDE, { "SUICIDE", 0, 1, 0} } }; -string eth::disassemble(bytes const& _mem) +string dev::eth::disassemble(bytes const& _mem) { stringstream ret; - uint numerics = 0; + unsigned numerics = 0; for (auto it = _mem.begin(); it != _mem.end(); ++it) { byte n = *it; @@ -303,7 +304,7 @@ string eth::disassemble(bytes const& _mem) return ret.str(); } -InstructionInfo eth::instructionInfo(Instruction _inst) +InstructionInfo dev::eth::instructionInfo(Instruction _inst) { try { diff --git a/libevmface/Instruction.h b/libevmface/Instruction.h index 1af42bada..01b4d6354 100644 --- a/libevmface/Instruction.h +++ b/libevmface/Instruction.h @@ -27,6 +27,8 @@ namespace boost { namespace spirit { class utree; } } namespace sp = boost::spirit; +namespace dev +{ namespace eth { @@ -188,3 +190,4 @@ extern const std::map c_instructions; std::string disassemble(bytes const& _mem); } +} diff --git a/liblll/Assembly.cpp b/liblll/Assembly.cpp index f397ec37d..475eaeabf 100644 --- a/liblll/Assembly.cpp +++ b/liblll/Assembly.cpp @@ -24,7 +24,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; int AssemblyItem::deposit() const { @@ -59,7 +60,7 @@ unsigned Assembly::bytesRequired() const ret += 33; break; case Push: - ret += 1 + max(1, eth::bytesRequired(i.m_data)); + ret += 1 + max(1, dev::bytesRequired(i.m_data)); break; case PushSubSize: ret += 4; // worst case: a 16MB program @@ -71,7 +72,7 @@ unsigned Assembly::bytesRequired() const case Tag:; default:; } - if (eth::bytesRequired(ret) <= br) + if (dev::bytesRequired(ret) <= br) return ret; } } @@ -110,7 +111,7 @@ void Assembly::append(Assembly const& _a, int _deposit) } } -ostream& eth::operator<<(ostream& _out, AssemblyItemsConstRef _i) +ostream& dev::eth::operator<<(ostream& _out, AssemblyItemsConstRef _i) { for (AssemblyItem const& i: _i) switch (i.type()) @@ -217,7 +218,7 @@ inline bool matches(AssemblyItemsConstRef _a, AssemblyItemsConstRef _b) } struct OptimiserChannel: public LogChannel { static const char* name() { return "OPT"; } static const int verbosity = 12; }; -#define copt eth::LogOutputStream() +#define copt dev::LogOutputStream() Assembly& Assembly::optimise(bool _enable) { @@ -353,7 +354,7 @@ bytes Assembly::assemble() const vector tagPos(m_usedTags); map tagRef; multimap dataRef; - unsigned bytesPerTag = eth::bytesRequired(totalBytes); + unsigned bytesPerTag = dev::bytesRequired(totalBytes); byte tagPush = (byte)Instruction::PUSH1 - 1 + bytesPerTag; for (auto const& i: m_subs) @@ -380,7 +381,7 @@ bytes Assembly::assemble() const } case Push: { - byte b = max(1, eth::bytesRequired(i.m_data)); + byte b = max(1, dev::bytesRequired(i.m_data)); ret.push_back((byte)Instruction::PUSH1 - 1 + b); ret.resize(ret.size() + b); bytesRef byr(&ret.back() + 1 - b, b); @@ -404,7 +405,7 @@ bytes Assembly::assemble() const case PushSubSize: { auto s = m_data[i.m_data].size(); - byte b = max(1, eth::bytesRequired(s)); + byte b = max(1, dev::bytesRequired(s)); ret.push_back((byte)Instruction::PUSH1 - 1 + b); ret.resize(ret.size() + b); bytesRef byr(&ret.back() + 1 - b, b); diff --git a/liblll/Assembly.h b/liblll/Assembly.h index f0f93297f..cfeb6d1fb 100644 --- a/liblll/Assembly.h +++ b/liblll/Assembly.h @@ -27,6 +27,8 @@ #include #include "Exceptions.h" +namespace dev +{ namespace eth { @@ -130,3 +132,4 @@ inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a) } } +} diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index 07d17fbef..ecad3d364 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -28,7 +28,8 @@ #include "CompilerState.h" #include "Parser.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; namespace qi = boost::spirit::qi; namespace px = boost::phoenix; namespace sp = boost::spirit; diff --git a/liblll/CodeFragment.h b/liblll/CodeFragment.h index 98a6f15c7..a81d8ea22 100644 --- a/liblll/CodeFragment.h +++ b/liblll/CodeFragment.h @@ -29,6 +29,8 @@ namespace boost { namespace spirit { class utree; } } namespace sp = boost::spirit; +namespace dev +{ namespace eth { @@ -58,3 +60,4 @@ private: static const CodeFragment NullCodeFragment; } +} diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp index ebe2638be..389c10be2 100644 --- a/liblll/Compiler.cpp +++ b/liblll/Compiler.cpp @@ -25,9 +25,10 @@ #include "CodeFragment.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -bytes eth::compileLLL(string const& _src, bool _opt, vector* _errors) +bytes dev::eth::compileLLL(string const& _src, bool _opt, vector* _errors) { try { @@ -52,7 +53,7 @@ bytes eth::compileLLL(string const& _src, bool _opt, vector* _errors) return bytes(); } -std::string eth::compileLLLToAsm(std::string const& _src, bool _opt, std::vector* _errors) +std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::vector* _errors) { try { @@ -76,7 +77,7 @@ std::string eth::compileLLLToAsm(std::string const& _src, bool _opt, std::vector return string(); } -string eth::parseLLL(string const& _src) +string dev::eth::parseLLL(string const& _src) { sp::utree o; try diff --git a/liblll/Compiler.h b/liblll/Compiler.h index da84a2fea..5daec0a54 100644 --- a/liblll/Compiler.h +++ b/liblll/Compiler.h @@ -25,6 +25,8 @@ #include #include +namespace dev +{ namespace eth { @@ -33,4 +35,4 @@ std::string compileLLLToAsm(std::string const& _src, bool _opt = true, std::vect bytes compileLLL(std::string const& _src, bool _opt = true, std::vector* _errors = nullptr); } - +} diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 222775017..c3dc2dda3 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -23,7 +23,8 @@ #include "CodeFragment.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; CompilerState::CompilerState() { diff --git a/liblll/CompilerState.h b/liblll/CompilerState.h index a0b3bf46e..bfe56f927 100644 --- a/liblll/CompilerState.h +++ b/liblll/CompilerState.h @@ -24,6 +24,8 @@ #include #include "CodeFragment.h" +namespace dev +{ namespace eth { @@ -52,3 +54,4 @@ struct CompilerState }; } +} diff --git a/liblll/Exceptions.h b/liblll/Exceptions.h index a1aee1738..1dcbbcc66 100644 --- a/liblll/Exceptions.h +++ b/liblll/Exceptions.h @@ -21,11 +21,15 @@ #pragma once +#include + +namespace dev +{ namespace eth { /// Compile a Low-level Lisp-like Language program into EVM-code. -class CompilerException: public Exception {}; +class CompilerException: public dev::Exception {}; class InvalidOperation: public CompilerException {}; class IntegerOutOfRange: public CompilerException {}; class StringTooLong: public CompilerException {}; @@ -40,3 +44,4 @@ class BareSymbol: public CompilerException {}; class ExpectedLiteral: public CompilerException {}; } +} diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index edcd38f32..52a05174b 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -28,12 +28,13 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; namespace qi = boost::spirit::qi; namespace px = boost::phoenix; namespace sp = boost::spirit; -void eth::killBigints(sp::utree const& _this) +void dev::eth::killBigints(sp::utree const& _this) { switch (_this.which()) { @@ -43,7 +44,7 @@ void eth::killBigints(sp::utree const& _this) } } -void eth::debugOutAST(ostream& _out, sp::utree const& _this) +void dev::eth::debugOutAST(ostream& _out, sp::utree const& _this) { switch (_this.which()) { @@ -69,7 +70,7 @@ void eth::debugOutAST(ostream& _out, sp::utree const& _this) } } -namespace eth { +namespace dev { namespace eth { namespace parseTreeLLL_ { template @@ -81,13 +82,13 @@ struct tagNode } }; -}} +}}} -void eth::parseTreeLLL(string const& _s, sp::utree& o_out) +void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) { using qi::standard::space; using qi::standard::space_type; - using eth::parseTreeLLL_::tagNode; + using dev::eth::parseTreeLLL_::tagNode; typedef sp::basic_string symbol_type; typedef string::const_iterator it; diff --git a/liblll/Parser.h b/liblll/Parser.h index 5286c3e8a..f90c6b5df 100644 --- a/liblll/Parser.h +++ b/liblll/Parser.h @@ -28,6 +28,8 @@ namespace boost { namespace spirit { class utree; } } namespace sp = boost::spirit; +namespace dev +{ namespace eth { @@ -36,4 +38,4 @@ void parseTreeLLL(std::string const& _s, sp::utree& o_out); void debugOutAST(std::ostream& _out, sp::utree const& _this); } - +} diff --git a/libp2p/CMakeLists.txt b/libp2p/CMakeLists.txt index 98d9b06bb..118aecbe8 100644 --- a/libp2p/CMakeLists.txt +++ b/libp2p/CMakeLists.txt @@ -17,6 +17,7 @@ file(GLOB HEADERS "*.h") include_directories(..) +target_link_libraries(${EXECUTABLE} ethential) target_link_libraries(${EXECUTABLE} secp256k1) if(MINIUPNPC_LS) target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) diff --git a/libp2p/Capability.cpp b/libp2p/Capability.cpp index 85ccf9aa9..5ca674120 100644 --- a/libp2p/Capability.cpp +++ b/libp2p/Capability.cpp @@ -23,8 +23,8 @@ #include "Session.h" using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; void Capability::disable(std::string const& _problem) { diff --git a/libp2p/Capability.h b/libp2p/Capability.h index 275470c65..bffd38c79 100644 --- a/libp2p/Capability.h +++ b/libp2p/Capability.h @@ -24,6 +24,8 @@ #include "Common.h" #include "HostCapability.h" +namespace dev +{ namespace p2p { @@ -60,3 +62,4 @@ private: }; } +} diff --git a/libp2p/Common.cpp b/libp2p/Common.cpp index 297bd4715..21f23696a 100644 --- a/libp2p/Common.cpp +++ b/libp2p/Common.cpp @@ -21,8 +21,8 @@ #include "Common.h" using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; // Helper function to determine if an address falls within one of the reserved ranges // For V4: diff --git a/libp2p/Common.h b/libp2p/Common.h index 7061b8090..94be0b04b 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -33,23 +33,15 @@ namespace ba = boost::asio; namespace bi = boost::asio::ip; -namespace eth +namespace dev { + class RLP; class RLPStream; -} namespace p2p { -using eth::LogChannel; -using eth::bytes; -using eth::h256; -using eth::h512; -using eth::bytesConstRef; -using eth::RLP; -using eth::RLPStream; - bool isPrivateAddress(bi::address _addressToCheck); class UPnP; @@ -105,3 +97,4 @@ struct PeerInfo }; } +} diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 580a5ea1a..1a375608d 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -40,8 +40,8 @@ #include "Capability.h" #include "UPnP.h" using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; // Addresses we will skip during network interface discovery // Use a vector as the list is small diff --git a/libp2p/Host.h b/libp2p/Host.h index 08a39a8c2..c362bbe11 100644 --- a/libp2p/Host.h +++ b/libp2p/Host.h @@ -33,14 +33,13 @@ namespace ba = boost::asio; namespace bi = boost::asio::ip; -namespace p2p +namespace dev { class RLPStream; -class TransactionQueue; -class BlockQueue; -using eth::Guard; +namespace p2p +{ /** * @brief The Host class @@ -157,3 +156,4 @@ protected: }; } +} diff --git a/libp2p/HostCapability.cpp b/libp2p/HostCapability.cpp index 5d81e1213..a3a47cd5c 100644 --- a/libp2p/HostCapability.cpp +++ b/libp2p/HostCapability.cpp @@ -24,8 +24,8 @@ #include "Session.h" #include "Host.h" using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; void HostCapabilityFace::seal(bytes& _b) { diff --git a/libp2p/HostCapability.h b/libp2p/HostCapability.h index e4b3d403b..4b6d38f64 100644 --- a/libp2p/HostCapability.h +++ b/libp2p/HostCapability.h @@ -25,6 +25,9 @@ #include "Common.h" +namespace dev +{ + namespace p2p { @@ -68,3 +71,5 @@ protected: }; } + +} diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index f2b5a1d01..cdd168db4 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -27,10 +27,10 @@ #include "Host.h" #include "Capability.h" using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; -#define clogS(X) eth::LogOutputStream(false) << "| " << std::setw(2) << m_socket.native_handle() << "] " +#define clogS(X) dev::LogOutputStream(false) << "| " << std::setw(2) << m_socket.native_handle() << "] " Session::Session(Host* _s, bi::tcp::socket _socket, bi::address _peerAddress, unsigned short _peerPort): m_server(_s), diff --git a/libp2p/Session.h b/libp2p/Session.h index 52628210c..a005e35ed 100644 --- a/libp2p/Session.h +++ b/libp2p/Session.h @@ -29,6 +29,9 @@ #include #include "Common.h" +namespace dev +{ + namespace p2p { @@ -98,7 +101,7 @@ private: std::chrono::steady_clock::time_point m_connect; std::chrono::steady_clock::time_point m_disconnect; - uint m_rating; + unsigned m_rating; std::map> m_capabilities; @@ -106,3 +109,4 @@ private: }; } +} diff --git a/libp2p/UPnP.cpp b/libp2p/UPnP.cpp index ce0286681..6b3ef4cc5 100644 --- a/libp2p/UPnP.cpp +++ b/libp2p/UPnP.cpp @@ -33,8 +33,8 @@ #include #include using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; UPnP::UPnP() { diff --git a/libp2p/UPnP.h b/libp2p/UPnP.h index 8f118bae4..0031298a6 100644 --- a/libp2p/UPnP.h +++ b/libp2p/UPnP.h @@ -29,6 +29,8 @@ struct UPNPUrls; struct IGDdatas; +namespace dev +{ namespace p2p { @@ -51,3 +53,4 @@ public: }; } +} diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index 96963f6ff..2fd94b228 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -10,48 +10,48 @@ using namespace std; // types -using eth::bytes; -using eth::bytesConstRef; -using eth::h160; -using eth::h256; -using eth::u160; -using eth::u256; -using eth::u256s; -using eth::Address; -using eth::BlockInfo; -using eth::Client; -using eth::Instruction; -using eth::KeyPair; -using eth::NodeMode; -using p2p::PeerInfo; -using eth::RLP; -using eth::Secret; -using eth::Transaction; +using dev::bytes; +using dev::bytesConstRef; +using dev::h160; +using dev::h256; +using dev::u160; +using dev::u256; +using dev::u256s; +using dev::RLP; +using dev::eth::Address; +using dev::eth::BlockInfo; +using dev::eth::Client; +using dev::eth::Instruction; +using dev::eth::KeyPair; +using dev::eth::NodeMode; +using dev::p2p::PeerInfo; +using dev::eth::Secret; +using dev::eth::Transaction; // functions -using eth::toHex; -using eth::disassemble; -using eth::formatBalance; -using eth::fromHex; -using eth::right160; -using eth::simpleDebugOut; -using eth::toLog2; -using eth::toString; -using eth::units; -using eth::operator +; +using dev::toHex; +using dev::fromHex; +using dev::right160; +using dev::simpleDebugOut; +using dev::toLog2; +using dev::toString; +using dev::operator+; +using dev::eth::disassemble; +using dev::eth::units; +using dev::eth::formatBalance; // vars -using eth::g_logPost; -using eth::g_logVerbosity; +using dev::g_logPost; +using dev::g_logVerbosity; -eth::bytes toBytes(QString const& _s) +dev::bytes toBytes(QString const& _s) { if (_s.startsWith("0x")) // Hex - return eth::fromHex(_s.mid(2).toStdString()); + return dev::fromHex(_s.mid(2).toStdString()); else if (!_s.contains(QRegExp("[^0-9]"))) // Decimal - return eth::toCompactBigEndian(eth::bigint(_s.toStdString())); + return dev::toCompactBigEndian(dev::bigint(_s.toStdString())); else { // Binary @@ -62,12 +62,12 @@ eth::bytes toBytes(QString const& _s) QString padded(QString const& _s, unsigned _l, unsigned _r) { - eth::bytes b = toBytes(_s); + dev::bytes b = toBytes(_s); while (b.size() < _l) b.insert(b.begin(), 0); while (b.size() < _r) b.push_back(0); - return asQString(eth::asBytes(eth::asString(b).substr(b.size() - max(_l, _r)))); + return asQString(dev::asBytes(dev::asString(b).substr(b.size() - max(_l, _r)))); } //"0xff".bin().unbin() @@ -89,7 +89,8 @@ QString unpadded(QString _s) return _s; } -QEthereum::QEthereum(QObject* _p, Client* _c, QList _accounts): QObject(_p), m_client(_c), m_accounts(_accounts) +QEthereum::QEthereum(QObject* _p, Client* _c, QList _accounts): + QObject(_p), m_client(_c), m_accounts(_accounts) { // required to prevent crash on osx when performing addto/evaluatejavascript calls moveToThread(_p->thread()); @@ -126,27 +127,27 @@ Client* QEthereum::client() const QString QEthereum::lll(QString _s) const { - return toQJS(eth::compileLLL(_s.toStdString())); + return toQJS(dev::eth::compileLLL(_s.toStdString())); } QString QEthereum::sha3(QString _s) const { - return toQJS(eth::sha3(toBytes(_s))); + return toQJS(dev::eth::sha3(toBytes(_s))); } QString QEthereum::sha3(QString _s1, QString _s2) const { - return toQJS(eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)))); + return toQJS(dev::eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)))); } QString QEthereum::sha3(QString _s1, QString _s2, QString _s3) const { - return toQJS(eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)) + asBytes(padded(_s3, 32)))); + return toQJS(dev::eth::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)) + asBytes(padded(_s3, 32)))); } QString QEthereum::sha3old(QString _s) const { - return toQJS(eth::sha3(asBytes(_s))); + return toQJS(dev::eth::sha3(asBytes(_s))); } QString QEthereum::offset(QString _s, int _i) const @@ -254,9 +255,9 @@ double QEthereum::countAt(QString _a, int _block) const return m_client ? (double)(uint64_t)client()->countAt(toAddress(_a), _block) : 0; } -static eth::MessageFilter toMessageFilter(QString _json) +static dev::eth::MessageFilter toMessageFilter(QString _json) { - eth::MessageFilter filter; + dev::eth::MessageFilter filter; QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); if (f.contains("earliest")) @@ -333,21 +334,21 @@ static TransactionSkeleton toTransaction(QString _json) ret.data = toBytes(f["code"].toString()); else if (f["data"].isArray()) for (auto i: f["data"].toArray()) - eth::operator +=(ret.data, asBytes(padded(i.toString(), 32))); + dev::operator +=(ret.data, asBytes(padded(i.toString(), 32))); else if (f["code"].isArray()) for (auto i: f["code"].toArray()) - eth::operator +=(ret.data, asBytes(padded(i.toString(), 32))); + dev::operator +=(ret.data, asBytes(padded(i.toString(), 32))); else if (f["dataclose"].isArray()) for (auto i: f["dataclose"].toArray()) - eth::operator +=(ret.data, toBytes(i.toString())); + dev::operator +=(ret.data, toBytes(i.toString())); } return ret; } -static QString toJson(eth::PastMessages const& _pms) +static QString toJson(dev::eth::PastMessages const& _pms) { QJsonArray jsonArray; - for (eth::PastMessage const& t: _pms) + for (dev::eth::PastMessage const& t: _pms) { QJsonObject v; v["input"] = ::fromBinary(t.input); @@ -441,7 +442,7 @@ QString QEthereum::doTransact(QString _json) t.from = b.secret(); } if (!t.gasPrice) - t.gasPrice = 10 * eth::szabo; + t.gasPrice = 10 * dev::eth::szabo; if (!t.gas) t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice); if (t.to) @@ -462,7 +463,7 @@ QString QEthereum::doCall(QString _json) if (!t.from && m_accounts.size()) t.from = m_accounts[0].secret(); if (!t.gasPrice) - t.gasPrice = 10 * eth::szabo; + t.gasPrice = 10 * dev::eth::szabo; if (!t.gas) t.gas = client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice; bytes out = client()->call(t.from, t.value, t.to, t.data, t.gas, t.gasPrice); @@ -475,9 +476,9 @@ unsigned QEthereum::newWatch(QString _json) return (unsigned)-1; unsigned ret; if (_json == "chain") - ret = m_client->installWatch(eth::ChainChangedFilter); + ret = m_client->installWatch(dev::eth::ChainChangedFilter); else if (_json == "pending") - ret = m_client->installWatch(eth::PendingChangedFilter); + ret = m_client->installWatch(dev::eth::PendingChangedFilter); else ret = m_client->installWatch(toMessageFilter(_json)); m_watches.push_back(ret); diff --git a/libqethereum/QEthereum.h b/libqethereum/QEthereum.h index 645c91740..41451118e 100644 --- a/libqethereum/QEthereum.h +++ b/libqethereum/QEthereum.h @@ -6,26 +6,26 @@ #include #include -namespace eth { +namespace dev { namespace eth { class Client; class State; -} +}} class QJSEngine; class QWebFrame; class QEthereum; -inline eth::bytes asBytes(QString const& _s) +inline dev::bytes asBytes(QString const& _s) { - eth::bytes ret; + dev::bytes ret; ret.reserve(_s.size()); for (QChar c: _s) ret.push_back(c.cell()); return ret; } -inline QString asQString(eth::bytes const& _s) +inline QString asQString(dev::bytes const& _s) { QString ret; ret.reserve(_s.size()); @@ -34,34 +34,34 @@ inline QString asQString(eth::bytes const& _s) return ret; } -eth::bytes toBytes(QString const& _s); +dev::bytes toBytes(QString const& _s); QString padded(QString const& _s, unsigned _l, unsigned _r); QString padded(QString const& _s, unsigned _l); QString unpadded(QString _s); -template eth::FixedHash toFixed(QString const& _s) +template dev::FixedHash toFixed(QString const& _s) { if (_s.startsWith("0x")) // Hex - return eth::FixedHash(_s.mid(2).toStdString()); + return dev::FixedHash(_s.mid(2).toStdString()); else if (!_s.contains(QRegExp("[^0-9]"))) // Decimal - return (typename eth::FixedHash::Arith)(_s.toStdString()); + return (typename dev::FixedHash::Arith)(_s.toStdString()); else // Binary - return eth::FixedHash(asBytes(padded(_s, N))); + return dev::FixedHash(asBytes(padded(_s, N))); } template inline boost::multiprecision::number> toInt(QString const& _s); -inline eth::Address toAddress(QString const& _s) { return toFixed<20>(_s); } -inline eth::Secret toSecret(QString const& _s) { return toFixed<32>(_s); } -inline eth::u256 toU256(QString const& _s) { return toInt<32>(_s); } +inline dev::eth::Address toAddress(QString const& _s) { return toFixed<20>(_s); } +inline dev::eth::Secret toSecret(QString const& _s) { return toFixed<32>(_s); } +inline dev::u256 toU256(QString const& _s) { return toInt<32>(_s); } -template QString toQJS(eth::FixedHash const& _h) { return QString::fromStdString("0x" + toHex(_h.ref())); } -template QString toQJS(boost::multiprecision::number> const& _n) { return QString::fromStdString("0x" + eth::toHex(eth::toCompactBigEndian(_n))); } -inline QString toQJS(eth::bytes const& _n) { return "0x" + QString::fromStdString(eth::toHex(_n)); } +template QString toQJS(dev::FixedHash const& _h) { return QString::fromStdString("0x" + toHex(_h.ref())); } +template QString toQJS(boost::multiprecision::number> const& _n) { return QString::fromStdString("0x" + dev::toHex(dev::toCompactBigEndian(_n))); } +inline QString toQJS(dev::bytes const& _n) { return "0x" + QString::fromStdString(dev::toHex(_n)); } inline QString toBinary(QString const& _s) { @@ -70,23 +70,23 @@ inline QString toBinary(QString const& _s) inline QString toDecimal(QString const& _s) { - return QString::fromStdString(eth::toString(toU256(_s))); + return QString::fromStdString(dev::toString(toU256(_s))); } inline double fromFixed(QString const& _s) { - return (double)toU256(_s) / (double)(eth::u256(1) << 128); + return (double)toU256(_s) / (double)(dev::u256(1) << 128); } inline QString toFixed(double _s) { - return toQJS(eth::u256(_s * (double)(eth::u256(1) << 128))); + return toQJS(dev::u256(_s * (double)(dev::u256(1) << 128))); } -inline QString fromBinary(eth::bytes _s, unsigned _padding = 32) +inline QString fromBinary(dev::bytes _s, unsigned _padding = 32) { _s.resize(std::max(_s.size(), _padding)); - return QString::fromStdString("0x" + eth::toHex(_s)); + return QString::fromStdString("0x" + dev::toHex(_s)); } inline QString fromBinary(QString const& _s, unsigned _padding = 32) @@ -99,16 +99,16 @@ class QEthereum: public QObject Q_OBJECT public: - QEthereum(QObject* _p, eth::Client* _c, QList _accounts); + QEthereum(QObject* _p, dev::eth::Client* _c, QList _accounts); virtual ~QEthereum(); - eth::Client* client() const; - void setClient(eth::Client* _c) { m_client = _c; } + dev::eth::Client* client() const; + void setClient(dev::eth::Client* _c) { m_client = _c; } /// Call when the client() is going to be deleted to make this object useless but safe. void clientDieing(); - void setAccounts(QList _l) { m_accounts = _l; keysChanged(); } + void setAccounts(QList _l) { m_accounts = _l; keysChanged(); } Q_INVOKABLE QString ethTest() const { return "Hello world!"; } Q_INVOKABLE QEthereum* self() { return this; } @@ -134,15 +134,15 @@ public: Q_INVOKABLE QString toFixed(double _d) const { return ::toFixed(_d); } // [NEW API] - Use this instead. - Q_INVOKABLE QString/*eth::u256*/ balanceAt(QString/*eth::Address*/ _a, int _block) const; - Q_INVOKABLE double countAt(QString/*eth::Address*/ _a, int _block) const; - Q_INVOKABLE QString/*eth::u256*/ stateAt(QString/*eth::Address*/ _a, QString/*eth::u256*/ _p, int _block) const; - Q_INVOKABLE QString/*eth::u256*/ codeAt(QString/*eth::Address*/ _a, int _block) const; + Q_INVOKABLE QString/*dev::u256*/ balanceAt(QString/*dev::Address*/ _a, int _block) const; + Q_INVOKABLE double countAt(QString/*dev::Address*/ _a, int _block) const; + Q_INVOKABLE QString/*dev::u256*/ stateAt(QString/*dev::Address*/ _a, QString/*dev::u256*/ _p, int _block) const; + Q_INVOKABLE QString/*dev::u256*/ codeAt(QString/*dev::Address*/ _a, int _block) const; - Q_INVOKABLE QString/*eth::u256*/ balanceAt(QString/*eth::Address*/ _a) const; - Q_INVOKABLE double countAt(QString/*eth::Address*/ _a) const; - Q_INVOKABLE QString/*eth::u256*/ stateAt(QString/*eth::Address*/ _a, QString/*eth::u256*/ _p) const; - Q_INVOKABLE QString/*eth::u256*/ codeAt(QString/*eth::Address*/ _a) const; + Q_INVOKABLE QString/*dev::u256*/ balanceAt(QString/*dev::Address*/ _a) const; + Q_INVOKABLE double countAt(QString/*dev::Address*/ _a) const; + Q_INVOKABLE QString/*dev::u256*/ stateAt(QString/*dev::Address*/ _a, QString/*dev::u256*/ _p) const; + Q_INVOKABLE QString/*dev::u256*/ codeAt(QString/*dev::Address*/ _a) const; Q_INVOKABLE QString/*json*/ getMessages(QString _attribs/*json*/) const; @@ -159,20 +159,20 @@ public: bool isListening() const; bool isMining() const; - QString/*eth::Address*/ coinbase() const; - QString/*eth::u256*/ gasPrice() const { return toQJS(10 * eth::szabo); } - QString/*eth::u256*/ number() const; + QString/*dev::Address*/ coinbase() const; + QString/*dev::u256*/ gasPrice() const { return toQJS(10 * dev::eth::szabo); } + QString/*dev::u256*/ number() const; int getDefault() const; - QString/*eth::KeyPair*/ key() const; - QStringList/*list of eth::KeyPair*/ keys() const; - QString/*eth::Address*/ account() const; - QStringList/*list of eth::Address*/ accounts() const; + QString/*dev::KeyPair*/ key() const; + QStringList/*list of dev::eth::KeyPair*/ keys() const; + QString/*dev::Address*/ account() const; + QStringList/*list of dev::eth::Address*/ accounts() const; unsigned peerCount() const; public slots: - void setCoinbase(QString/*eth::Address*/); + void setCoinbase(QString/*dev::Address*/); void setMining(bool _l); void setListening(bool _l); void setDefault(int _block); @@ -199,9 +199,9 @@ private: Q_PROPERTY(unsigned peerCount READ peerCount NOTIFY miningChanged) Q_PROPERTY(int defaultBlock READ getDefault WRITE setDefault) - eth::Client* m_client; + dev::eth::Client* m_client; std::vector m_watches; - QList m_accounts; + QList m_accounts; }; #define QETH_INSTALL_JS_NAMESPACE(frame, eth, env) [frame, eth, env]() \ @@ -232,12 +232,12 @@ private: template inline boost::multiprecision::number> toInt(QString const& _s) { if (_s.startsWith("0x")) - return eth::fromBigEndian>>(eth::fromHex(_s.toStdString().substr(2))); + return dev::fromBigEndian>>(dev::fromHex(_s.toStdString().substr(2))); else if (!_s.contains(QRegExp("[^0-9]"))) // Hex or Decimal return boost::multiprecision::number>(_s.toStdString()); else // Binary - return eth::fromBigEndian>>(asBytes(padded(_s, N))); + return dev::fromBigEndian>>(asBytes(padded(_s, N))); } diff --git a/libqethereum/QmlEthereum.cpp b/libqethereum/QmlEthereum.cpp index 3896382fd..b718bfb7b 100644 --- a/libqethereum/QmlEthereum.cpp +++ b/libqethereum/QmlEthereum.cpp @@ -13,42 +13,42 @@ using namespace std; // types -using eth::bytes; -using eth::bytesConstRef; -using eth::h160; -using eth::h256; -using eth::u160; -using eth::u256; -using eth::u256s; -using eth::Address; -using eth::BlockInfo; -using eth::Client; -using eth::Instruction; -using eth::KeyPair; -using eth::NodeMode; -using p2p::PeerInfo; -using eth::RLP; -using eth::Secret; -using eth::Transaction; +using dev::bytes; +using dev::bytesConstRef; +using dev::h160; +using dev::h256; +using dev::u160; +using dev::u256; +using dev::u256s; +using dev::RLP; +using dev::eth::Address; +using dev::eth::BlockInfo; +using dev::eth::Client; +using dev::eth::Instruction; +using dev::eth::KeyPair; +using dev::eth::NodeMode; +using dev::eth::Secret; +using dev::eth::Transaction; +using dev::p2p::PeerInfo; // functions -using eth::toHex; -using eth::disassemble; -using eth::formatBalance; -using eth::fromHex; -using eth::right160; -using eth::simpleDebugOut; -using eth::toLog2; -using eth::toString; -using eth::units; +using dev::toHex; +using dev::fromHex; +using dev::right160; +using dev::simpleDebugOut; +using dev::toLog2; +using dev::toString; +using dev::eth::disassemble; +using dev::eth::formatBalance; +using dev::eth::units; // vars -using eth::g_logPost; -using eth::g_logVerbosity; +using dev::g_logPost; +using dev::g_logVerbosity; // Horrible global for the mainwindow. Needed for the QmlEthereums to find the Main window which acts as multiplexer for now. // Can get rid of this once we've sorted out ITC for signalling & multiplexed querying. -eth::Client* g_qmlClient; +dev::eth::Client* g_qmlClient; QObject* g_qmlMain; QmlAccount::QmlAccount(QObject*) @@ -72,7 +72,7 @@ void QmlAccount::setEthereum(QmlEthereum* _eth) // changed(); } -eth::u256 QmlAccount::balance() const +dev::u256 QmlAccount::balance() const { if (m_eth) return m_eth->balanceAt(m_address); diff --git a/libqethereum/QmlEthereum.h b/libqethereum/QmlEthereum.h index 2554dd02f..59dff6f5e 100644 --- a/libqethereum/QmlEthereum.h +++ b/libqethereum/QmlEthereum.h @@ -7,22 +7,22 @@ #include #include -namespace eth { +namespace dev { namespace eth { class Client; class State; -} +}} class QQmlEngine; class QmlAccount; class QmlEthereum; -extern eth::Client* g_qmlClient; +extern dev::eth::Client* g_qmlClient; extern QObject* g_qmlMain; -Q_DECLARE_METATYPE(eth::u256) -Q_DECLARE_METATYPE(eth::Address) -Q_DECLARE_METATYPE(eth::Secret) -Q_DECLARE_METATYPE(eth::KeyPair) +Q_DECLARE_METATYPE(dev::u256) +Q_DECLARE_METATYPE(dev::eth::Address) +Q_DECLARE_METATYPE(dev::eth::Secret) +Q_DECLARE_METATYPE(dev::eth::KeyPair) Q_DECLARE_METATYPE(QmlAccount*) Q_DECLARE_METATYPE(QmlEthereum*) @@ -33,28 +33,28 @@ class QmlU256Helper: public QObject public: QmlU256Helper(QObject* _p = nullptr): QObject(_p) {} - Q_INVOKABLE eth::u256 add(eth::u256 _a, eth::u256 _b) const { return _a + _b; } - Q_INVOKABLE eth::u256 sub(eth::u256 _a, eth::u256 _b) const { return _a - _b; } - Q_INVOKABLE eth::u256 mul(eth::u256 _a, int _b) const { return _a * _b; } - Q_INVOKABLE eth::u256 mul(int _a, eth::u256 _b) const { return _a * _b; } - Q_INVOKABLE eth::u256 div(eth::u256 _a, int _b) const { return _a / _b; } - - Q_INVOKABLE eth::u256 wei(double _s) const { return (eth::u256)_s; } - Q_INVOKABLE eth::u256 szabo(double _s) const { return (eth::u256)(_s * (double)eth::szabo); } - Q_INVOKABLE eth::u256 finney(double _s) const { return (eth::u256)(_s * (double)eth::finney); } - Q_INVOKABLE eth::u256 ether(double _s) const { return (eth::u256)(_s * (double)eth::ether); } - Q_INVOKABLE eth::u256 wei(unsigned _s) const { return (eth::u256)_s; } - Q_INVOKABLE eth::u256 szabo(unsigned _s) const { return (eth::u256)(_s * eth::szabo); } - Q_INVOKABLE eth::u256 finney(unsigned _s) const { return (eth::u256)(_s * eth::finney); } - Q_INVOKABLE eth::u256 ether(unsigned _s) const { return (eth::u256)(_s * eth::ether); } - Q_INVOKABLE double toWei(eth::u256 _t) const { return (double)_t; } - Q_INVOKABLE double toSzabo(eth::u256 _t) const { return toWei(_t) / (double)eth::szabo; } - Q_INVOKABLE double toFinney(eth::u256 _t) const { return toWei(_t) / (double)eth::finney; } - Q_INVOKABLE double toEther(eth::u256 _t) const { return toWei(_t) / (double)eth::ether; } - - Q_INVOKABLE double value(eth::u256 _t) const { return (double)_t; } - - Q_INVOKABLE QString stringOf(eth::u256 _t) const { return QString::fromStdString(eth::formatBalance(_t)); } + Q_INVOKABLE dev::u256 add(dev::u256 _a, dev::u256 _b) const { return _a + _b; } + Q_INVOKABLE dev::u256 sub(dev::u256 _a, dev::u256 _b) const { return _a - _b; } + Q_INVOKABLE dev::u256 mul(dev::u256 _a, int _b) const { return _a * _b; } + Q_INVOKABLE dev::u256 mul(int _a, dev::u256 _b) const { return _a * _b; } + Q_INVOKABLE dev::u256 div(dev::u256 _a, int _b) const { return _a / _b; } + + Q_INVOKABLE dev::u256 wei(double _s) const { return (dev::u256)_s; } + Q_INVOKABLE dev::u256 szabo(double _s) const { return (dev::u256)(_s * (double)dev::eth::szabo); } + Q_INVOKABLE dev::u256 finney(double _s) const { return (dev::u256)(_s * (double)dev::eth::finney); } + Q_INVOKABLE dev::u256 ether(double _s) const { return (dev::u256)(_s * (double)dev::eth::ether); } + Q_INVOKABLE dev::u256 wei(unsigned _s) const { return (dev::u256)_s; } + Q_INVOKABLE dev::u256 szabo(unsigned _s) const { return (dev::u256)(_s * dev::eth::szabo); } + Q_INVOKABLE dev::u256 finney(unsigned _s) const { return (dev::u256)(_s * dev::eth::finney); } + Q_INVOKABLE dev::u256 ether(unsigned _s) const { return (dev::u256)(_s * dev::eth::ether); } + Q_INVOKABLE double toWei(dev::u256 _t) const { return (double)_t; } + Q_INVOKABLE double toSzabo(dev::u256 _t) const { return toWei(_t) / (double)dev::eth::szabo; } + Q_INVOKABLE double toFinney(dev::u256 _t) const { return toWei(_t) / (double)dev::eth::finney; } + Q_INVOKABLE double toEther(dev::u256 _t) const { return toWei(_t) / (double)dev::eth::ether; } + + Q_INVOKABLE double value(dev::u256 _t) const { return (double)_t; } + + Q_INVOKABLE QString stringOf(dev::u256 _t) const { return QString::fromStdString(dev::eth::formatBalance(_t)); } }; class QmlKeyHelper: public QObject @@ -64,16 +64,16 @@ class QmlKeyHelper: public QObject public: QmlKeyHelper(QObject* _p = nullptr): QObject(_p) {} - Q_INVOKABLE eth::KeyPair create() const { return eth::KeyPair::create(); } - Q_INVOKABLE eth::Address address(eth::KeyPair _p) const { return _p.address(); } - Q_INVOKABLE eth::Secret secret(eth::KeyPair _p) const { return _p.secret(); } - Q_INVOKABLE eth::KeyPair keypair(eth::Secret _k) const { return eth::KeyPair(_k); } + Q_INVOKABLE dev::eth::KeyPair create() const { return dev::eth::KeyPair::create(); } + Q_INVOKABLE dev::eth::Address address(dev::eth::KeyPair _p) const { return _p.address(); } + Q_INVOKABLE dev::eth::Secret secret(dev::eth::KeyPair _p) const { return _p.secret(); } + Q_INVOKABLE dev::eth::KeyPair keypair(dev::eth::Secret _k) const { return dev::eth::KeyPair(_k); } - Q_INVOKABLE bool isNull(eth::Address _a) const { return !_a; } + Q_INVOKABLE bool isNull(dev::eth::Address _a) const { return !_a; } - Q_INVOKABLE eth::Address addressOf(QString _s) const { return eth::Address(_s.toStdString()); } - Q_INVOKABLE QString stringOf(eth::Address _a) const { return QString::fromStdString(eth::toHex(_a.asArray())); } - Q_INVOKABLE QString toAbridged(eth::Address _a) const { return QString::fromStdString(_a.abridged()); } + Q_INVOKABLE dev::eth::Address addressOf(QString _s) const { return dev::eth::Address(_s.toStdString()); } + Q_INVOKABLE QString stringOf(dev::eth::Address _a) const { return QString::fromStdString(dev::toHex(_a.asArray())); } + Q_INVOKABLE QString toAbridged(dev::eth::Address _a) const { return QString::fromStdString(_a.abridged()); } }; class QmlAccount: public QObject @@ -85,16 +85,16 @@ public: virtual ~QmlAccount(); Q_INVOKABLE QmlEthereum* ethereum() const { return m_eth; } - Q_INVOKABLE eth::u256 balance() const; + Q_INVOKABLE dev::u256 balance() const; Q_INVOKABLE double txCount() const; Q_INVOKABLE bool isContract() const; - Q_INVOKABLE eth::Address address() const { return m_address; } + Q_INVOKABLE dev::eth::Address address() const { return m_address; } // TODO: past transactions models. public slots: void setEthereum(QmlEthereum* _eth); - void setAddress(eth::Address _a) { m_address = _a; } + void setAddress(dev::eth::Address _a) { m_address = _a; } signals: void changed(); @@ -102,12 +102,12 @@ signals: private: QmlEthereum* m_eth = nullptr; - eth::Address m_address; + dev::eth::Address m_address; - Q_PROPERTY(eth::u256 balance READ balance NOTIFY changed STORED false) + Q_PROPERTY(dev::u256 balance READ balance NOTIFY changed STORED false) Q_PROPERTY(double txCount READ txCount NOTIFY changed STORED false) Q_PROPERTY(bool isContract READ isContract NOTIFY changed STORED false) - Q_PROPERTY(eth::Address address READ address WRITE setAddress NOTIFY changed) + Q_PROPERTY(dev::eth::Address address READ address WRITE setAddress NOTIFY changed) Q_PROPERTY(QmlEthereum* ethereum READ ethereum WRITE setEthereum NOTIFY ethChanged) }; @@ -119,28 +119,28 @@ public: QmlEthereum(QObject* _p = nullptr); virtual ~QmlEthereum(); - eth::Client* client() const; + dev::eth::Client* client() const; static QObject* constructU256Helper(QQmlEngine*, QJSEngine*) { return new QmlU256Helper; } static QObject* constructKeyHelper(QQmlEngine*, QJSEngine*) { return new QmlKeyHelper; } - Q_INVOKABLE eth::Address coinbase() const; + Q_INVOKABLE dev::eth::Address coinbase() const; Q_INVOKABLE bool isListening() const; Q_INVOKABLE bool isMining() const; - Q_INVOKABLE eth::u256 balanceAt(eth::Address _a) const; - Q_INVOKABLE double txCountAt(eth::Address _a) const; - Q_INVOKABLE bool isContractAt(eth::Address _a) const; + Q_INVOKABLE dev::u256 balanceAt(dev::eth::Address _a) const; + Q_INVOKABLE double txCountAt(dev::eth::Address _a) const; + Q_INVOKABLE bool isContractAt(dev::eth::Address _a) const; Q_INVOKABLE unsigned peerCount() const; Q_INVOKABLE QmlEthereum* self() { return this; } public slots: - void transact(eth::Secret _secret, eth::Address _dest, eth::u256 _amount, eth::u256 _gasPrice, eth::u256 _gas, QByteArray _data); - void transact(eth::Secret _secret, eth::u256 _amount, eth::u256 _gasPrice, eth::u256 _gas, QByteArray _init); - void setCoinbase(eth::Address); + void transact(dev::eth::Secret _secret, dev::eth::Address _dest, dev::u256 _amount, dev::u256 _gasPrice, dev::u256 _gas, QByteArray _data); + void transact(dev::eth::Secret _secret, dev::u256 _amount, dev::u256 _gasPrice, dev::u256 _gas, QByteArray _init); + void setCoinbase(dev::eth::Address); void setMining(bool _l); void setListening(bool _l); @@ -151,7 +151,7 @@ signals: // void miningChanged(); private: - Q_PROPERTY(eth::Address coinbase READ coinbase WRITE setCoinbase NOTIFY coinbaseChanged) + Q_PROPERTY(dev::eth::Address coinbase READ coinbase WRITE setCoinbase NOTIFY coinbaseChanged) Q_PROPERTY(bool listening READ isListening WRITE setListening) Q_PROPERTY(bool mining READ isMining WRITE setMining) }; @@ -167,8 +167,8 @@ class U256Helper: public QObject public: U256Helper(QObject* _p = nullptr): QObject(_p) {} - static eth::u256 in(QVariant const& _s) { return to(_s); } - static QVariant out(eth::u256 const& _s) { return toQJS(_s); } + static dev::u256 in(QVariant const& _s) { return to(_s); } + static QVariant out(dev::u256 const& _s) { return toQJS(_s); } Q_INVOKABLE QVariant add(QVariant _a, QVariant _b) const { return out(in(_a) + in(_b)); } Q_INVOKABLE QVariant sub(QVariant _a, QVariant _b) const { return out(in(_a) - in(_b)); } @@ -176,32 +176,32 @@ public: Q_INVOKABLE QVariant mul(int _a, QVariant _b) const { return out(in(_a) * in(_b)); } Q_INVOKABLE QVariant div(QVariant _a, int _b) const { return out(in(_a) / in(_b)); } - Q_INVOKABLE QVariant wei(double _s) const { return out(eth::u256(_s)); } - Q_INVOKABLE QVariant szabo(double _s) const { return out(eth::u256(_s * (double)eth::szabo)); } - Q_INVOKABLE QVariant finney(double _s) const { return out(eth::u256(_s * (double)eth::finney)); } - Q_INVOKABLE QVariant ether(double _s) const { return out(eth::u256(_s * (double)eth::ether)); } + Q_INVOKABLE QVariant wei(double _s) const { return out(dev::u256(_s)); } + Q_INVOKABLE QVariant szabo(double _s) const { return out(dev::u256(_s * (double)dev::eth::szabo)); } + Q_INVOKABLE QVariant finney(double _s) const { return out(dev::u256(_s * (double)dev::eth::finney)); } + Q_INVOKABLE QVariant ether(double _s) const { return out(dev::u256(_s * (double)dev::eth::ether)); } Q_INVOKABLE QVariant wei(unsigned _s) const { return value(_s); } - Q_INVOKABLE QVariant szabo(unsigned _s) const { return out(eth::u256(_s) * eth::szabo); } - Q_INVOKABLE QVariant finney(unsigned _s) const { return out(eth::u256(_s) * eth::finney); } - Q_INVOKABLE QVariant ether(unsigned _s) const { return out(eth::u256(_s) * eth::ether); } + Q_INVOKABLE QVariant szabo(unsigned _s) const { return out(dev::u256(_s) * dev::eth::szabo); } + Q_INVOKABLE QVariant finney(unsigned _s) const { return out(dev::u256(_s) * dev::eth::finney); } + Q_INVOKABLE QVariant ether(unsigned _s) const { return out(dev::u256(_s) * dev::eth::ether); } Q_INVOKABLE double toWei(QVariant _t) const { return toValue(_t); } - Q_INVOKABLE double toSzabo(QVariant _t) const { return toWei(_t) / (double)eth::szabo; } - Q_INVOKABLE double toFinney(QVariant _t) const { return toWei(_t) / (double)eth::finney; } - Q_INVOKABLE double toEther(QVariant _t) const { return toWei(_t) / (double)eth::ether; } + Q_INVOKABLE double toSzabo(QVariant _t) const { return toWei(_t) / (double)dev::eth::szabo; } + Q_INVOKABLE double toFinney(QVariant _t) const { return toWei(_t) / (double)dev::eth::finney; } + Q_INVOKABLE double toEther(QVariant _t) const { return toWei(_t) / (double)dev::eth::ether; } - Q_INVOKABLE QVariant value(unsigned _s) const { return out(eth::u256(_s)); } + Q_INVOKABLE QVariant value(unsigned _s) const { return out(dev::u256(_s)); } Q_INVOKABLE double toValue(QVariant _t) const { return (double)in(_t); } - Q_INVOKABLE QString ethOf(QVariant _t) const { return QString::fromStdString(eth::formatBalance(in(_t))); } - Q_INVOKABLE QString stringOf(QVariant _t) const { return QString::fromStdString(eth::toString(in(_t))); } + Q_INVOKABLE QString ethOf(QVariant _t) const { return QString::fromStdString(dev::eth::formatBalance(in(_t))); } + Q_INVOKABLE QString stringOf(QVariant _t) const { return QString::fromStdString(dev::eth::toString(in(_t))); } - Q_INVOKABLE QByteArray bytesOf(QVariant _t) const { eth::h256 b = in(_t); return QByteArray((char const*)&b, sizeof(eth::h256)); } - Q_INVOKABLE QVariant fromHex(QString _s) const { return out((eth::u256)eth::h256(_s.toStdString())); } + Q_INVOKABLE QByteArray bytesOf(QVariant _t) const { dev::h256 b = in(_t); return QByteArray((char const*)&b, sizeof(dev::h256)); } + Q_INVOKABLE QVariant fromHex(QString _s) const { return out((dev::u256)dev::h256(_s.toStdString())); } - Q_INVOKABLE QVariant fromAddress(QVariant/*eth::Address*/ _a) const { return out((eth::u160)to(_a)); } - Q_INVOKABLE QVariant toAddress(QVariant/*eth::Address*/ _a) const { return toQJS((eth::u160)in(_a)); } + Q_INVOKABLE QVariant fromAddress(QVariant/*dev::eth::Address*/ _a) const { return out((dev::eth::u160)to(_a)); } + Q_INVOKABLE QVariant toAddress(QVariant/*dev::eth::Address*/ _a) const { return toQJS((dev::eth::u160)in(_a)); } - Q_INVOKABLE bool isNull(QVariant/*eth::Address*/ _a) const { return !in(_a); } + Q_INVOKABLE bool isNull(QVariant/*dev::eth::Address*/ _a) const { return !in(_a); } }; class KeyHelper: public QObject @@ -211,19 +211,19 @@ class KeyHelper: public QObject public: KeyHelper(QObject* _p = nullptr): QObject(_p) {} - static eth::Address in(QVariant const& _s) { return to(_s); } - static QVariant out(eth::Address const& _s) { return toQJS(_s); } + static dev::eth::Address in(QVariant const& _s) { return to(_s); } + static QVariant out(dev::eth::Address const& _s) { return toQJS(_s); } - Q_INVOKABLE QVariant/*eth::KeyPair*/ create() const { return toQJS(eth::KeyPair::create()); } - Q_INVOKABLE QVariant/*eth::Address*/ address(QVariant/*eth::KeyPair*/ _p) const { return out(to(_p).address()); } - Q_INVOKABLE QVariant/*eth::Secret*/ secret(QVariant/*eth::KeyPair*/ _p) const { return toQJS(to(_p).secret()); } - Q_INVOKABLE QVariant/*eth::KeyPair*/ keypair(QVariant/*eth::Secret*/ _k) const { return toQJS(eth::KeyPair(to(_k))); } + Q_INVOKABLE QVariant/*dev::eth::KeyPair*/ create() const { return toQJS(dev::eth::KeyPair::create()); } + Q_INVOKABLE QVariant/*dev::eth::Address*/ address(QVariant/*dev::eth::KeyPair*/ _p) const { return out(to(_p).address()); } + Q_INVOKABLE QVariant/*dev::eth::Secret*/ secret(QVariant/*dev::eth::KeyPair*/ _p) const { return toQJS(to(_p).secret()); } + Q_INVOKABLE QVariant/*dev::eth::KeyPair*/ keypair(QVariant/*dev::eth::Secret*/ _k) const { return toQJS(dev::eth::KeyPair(to(_k))); } - Q_INVOKABLE bool isNull(QVariant/*eth::Address*/ _a) const { return !in(_a); } + Q_INVOKABLE bool isNull(QVariant/*dev::eth::Address*/ _a) const { return !in(_a); } - Q_INVOKABLE QVariant/*eth::Address*/ addressOf(QString _s) const { return out(eth::Address(_s.toStdString())); } - Q_INVOKABLE QString stringOf(QVariant/*eth::Address*/ _a) const { return QString::fromStdString(eth::toHex(in(_a).asArray())); } - Q_INVOKABLE QString toAbridged(QVariant/*eth::Address*/ _a) const { return QString::fromStdString(in(_a).abridged()); } + Q_INVOKABLE QVariant/*dev::eth::Address*/ addressOf(QString _s) const { return out(dev::eth::Address(_s.toStdString())); } + Q_INVOKABLE QString stringOf(QVariant/*dev::eth::Address*/ _a) const { return QString::fromStdString(dev::eth::toHex(in(_a).asArray())); } + Q_INVOKABLE QString toAbridged(QVariant/*dev::eth::Address*/ _a) const { return QString::fromStdString(in(_a).abridged()); } }; @@ -276,8 +276,8 @@ public: { while (_s.size() < 32) _s.append((char)0); - eth::h256 ret((uint8_t const*)_s.data(), eth::h256::ConstructFromPointer); - return toQJS(ret); + dev::h256 ret((uint8_t const*)_s.data(), dev::h256::ConstructFromPointer); + return toQJS(ret); } }; #endif diff --git a/libwebthree/CMakeLists.txt b/libwebthree/CMakeLists.txt new file mode 100644 index 000000000..54bfd586d --- /dev/null +++ b/libwebthree/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_policy(SET CMP0015 NEW) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") + +aux_source_directory(. SRC_LIST) + +set(EXECUTABLE webthree) + +# set(CMAKE_INSTALL_PREFIX ../lib) +if(ETH_STATIC) + add_library(${EXECUTABLE} STATIC ${SRC_LIST}) +else() + add_library(${EXECUTABLE} SHARED ${SRC_LIST}) +endif() + +file(GLOB HEADERS "*.h") + +include_directories(..) + +target_link_libraries(${EXECUTABLE} ethereum) +target_link_libraries(${EXECUTABLE} evm) +target_link_libraries(${EXECUTABLE} lll) +target_link_libraries(${EXECUTABLE} whisper) +target_link_libraries(${EXECUTABLE} p2p) +target_link_libraries(${EXECUTABLE} ethcore) +target_link_libraries(${EXECUTABLE} secp256k1) +if(MINIUPNPC_LS) +target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) +endif() +target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) +target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) +target_link_libraries(${EXECUTABLE} gmp) + +if("${TARGET_PLATFORM}" STREQUAL "w64") + target_link_libraries(${EXECUTABLE} boost_system-mt-s) + target_link_libraries(${EXECUTABLE} boost_regex-mt-s) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s) + target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) + target_link_libraries(${EXECUTABLE} iphlpapi) + target_link_libraries(${EXECUTABLE} ws2_32) + target_link_libraries(${EXECUTABLE} mswsock) + target_link_libraries(${EXECUTABLE} shlwapi) +elseif (APPLE) + # Latest mavericks boost libraries only come with -mt + target_link_libraries(${EXECUTABLE} boost_system-mt) + target_link_libraries(${EXECUTABLE} boost_regex-mt) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt) + target_link_libraries(${EXECUTABLE} boost_thread-mt) + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +elseif (UNIX) + target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +else () + target_link_libraries(${EXECUTABLE} boost_system) + target_link_libraries(${EXECUTABLE} boost_regex) + target_link_libraries(${EXECUTABLE} boost_filesystem) + target_link_libraries(${EXECUTABLE} boost_thread) + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +endif () + +install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) + diff --git a/libwebthree/Client.cpp b/libwebthree/Client.cpp new file mode 100644 index 000000000..f8b3ad538 --- /dev/null +++ b/libwebthree/Client.cpp @@ -0,0 +1,172 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file RawWebThree.cpp + * @author Gav Wood + * @date 2014 + */ + +#include "Client.h" + +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +using namespace dev; +using namespace dev::p2p; +using namespace dev::eth; +using namespace dev::shh; + +RawWebThree::RawWebThree(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean): + m_clientVersion(_clientVersion) +{ + if (_dbPath.size()) + Defaults::setDBPath(_dbPath); +} + +RawWebThree::~RawWebThree() +{ + stopNetwork(); +} + +void RawWebThree::startNetwork(unsigned short _listenPort, std::string const& _seedHost, unsigned short _port, NodeMode _mode, unsigned _peers, string const& _publicIP, bool _upnp, u256 _networkId) +{ + static const char* c_threadName = "net"; + + { + UpgradableGuard l(x_net); + if (m_net.get()) + return; + { + UpgradeGuard ul(l); + + if (!m_workNet) + m_workNet.reset(new thread([&]() + { + setThreadName(c_threadName); + m_workNetState.store(Active, std::memory_order_release); + while (m_workNetState.load(std::memory_order_acquire) != Deleting) + workNet(); + m_workNetState.store(Deleted, std::memory_order_release); + })); + + try + { + m_net.reset(new Host(m_clientVersion, _listenPort, _publicIP, _upnp)); + } + catch (std::exception const&) + { + // Probably already have the port open. + cwarn << "Could not initialize with specified/default port. Trying system-assigned port"; + m_net.reset(new Host(m_clientVersion, 0, _publicIP, _upnp)); + } +/* if (_mode == NodeMode::Full) + m_net->registerCapability(new EthereumHost(m_bc, _networkId)); + if (_mode == NodeMode::Full) + m_net->registerCapability(new WhisperHost());*/ + } + m_net->setIdealPeerCount(_peers); + } + + if (_seedHost.size()) + connect(_seedHost, _port); +} + +void RawWebThree::stopNetwork() +{ + UpgradableGuard l(x_net); + + if (m_workNet) + { + if (m_workNetState.load(std::memory_order_acquire) == Active) + m_workNetState.store(Deleting, std::memory_order_release); + while (m_workNetState.load(std::memory_order_acquire) != Deleted) + this_thread::sleep_for(chrono::milliseconds(10)); + m_workNet->join(); + } + if (m_net) + { + UpgradeGuard ul(l); + m_net.reset(nullptr); + m_workNet.reset(nullptr); + } +} + +std::vector RawWebThree::peers() +{ + ReadGuard l(x_net); + return m_net ? m_net->peers() : std::vector(); +} + +size_t RawWebThree::peerCount() const +{ + ReadGuard l(x_net); + return m_net ? m_net->peerCount() : 0; +} + +void RawWebThree::setIdealPeerCount(size_t _n) const +{ + ReadGuard l(x_net); + if (m_net) + return m_net->setIdealPeerCount(_n); +} + +bytes RawWebThree::savePeers() +{ + ReadGuard l(x_net); + if (m_net) + return m_net->savePeers(); + return bytes(); +} + +void RawWebThree::restorePeers(bytesConstRef _saved) +{ + ReadGuard l(x_net); + if (m_net) + return m_net->restorePeers(_saved); +} + +void RawWebThree::connect(std::string const& _seedHost, unsigned short _port) +{ + ReadGuard l(x_net); + if (!m_net.get()) + return; + m_net->connect(_seedHost, _port); +} + +void RawWebThree::workNet() +{ + // Process network events. + // Synchronise block chain with network. + // Will broadcast any of our (new) transactions and blocks, and collect & add any of their (new) transactions and blocks. + { + ReadGuard l(x_net); + if (m_net) + { + m_net->process(); // must be in guard for now since it uses the blockchain. + + // returns h256Set as block hashes, once for each block that has come in/gone out. +// m_net->cap()->sync(m_tq, m_bq); + } + } + this_thread::sleep_for(chrono::milliseconds(1)); +} + diff --git a/libwebthree/Client.h b/libwebthree/Client.h new file mode 100644 index 000000000..5c418d931 --- /dev/null +++ b/libwebthree/Client.h @@ -0,0 +1,101 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file Client.h + * @author Gav Wood + * @date 2014 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dev +{ + +enum WorkState +{ + Active = 0, + Deleting, + Deleted +}; + +enum class NodeMode +{ + PeerServer, + Full +}; + +/** + * @brief Main API hub for interfacing with Web 3 components. This doesn't do any local multiplexing, so you can only have one + * running on any given machine for the provided DB path. + */ +class RawWebThree +{ +public: + /// Constructor. + RawWebThree(std::string const& _clientVersion, std::string const& _dbPath = std::string(), bool _forceClean = false); + + /// Destructor. + ~RawWebThree(); + + // Misc stuff: + + void setClientVersion(std::string const& _name) { m_clientVersion = _name; } + + // Network stuff: + + /// Get information on the current peer set. + std::vector peers(); + /// Same as peers().size(), but more efficient. + size_t peerCount() const; + /// Same as peers().size(), but more efficient. + void setIdealPeerCount(size_t _n) const; + + /// Start the network subsystem. + void startNetwork(unsigned short _listenPort = 30303, std::string const& _remoteHost = std::string(), unsigned short _remotePort = 30303, NodeMode _mode = NodeMode::Full, unsigned _peers = 5, std::string const& _publicIP = std::string(), bool _upnp = true, dev::u256 _networkId = 0); + /// Connect to a particular peer. + void connect(std::string const& _seedHost, unsigned short _port = 30303); + /// Stop the network subsystem. + void stopNetwork(); + /// Is the network subsystem up? + bool haveNetwork() { ReadGuard l(x_net); return !!m_net; } + /// Save peers + dev::bytes savePeers(); + /// Restore peers + void restorePeers(bytesConstRef _saved); + +private: + /// Do some work on the network. + void workNet(); + + std::string m_clientVersion; ///< Our end-application client's name/version. + + std::unique_ptr m_workNet; ///< The network thread. + std::atomic m_workNetState; + mutable boost::shared_mutex x_net; ///< Lock for the network existance. + std::unique_ptr m_net; ///< Should run in background and send us events when blocks found and allow us to send blocks as required. +}; + +} diff --git a/libwhisper/Common.cpp b/libwhisper/Common.cpp index 73420e32a..52bed0742 100644 --- a/libwhisper/Common.cpp +++ b/libwhisper/Common.cpp @@ -22,7 +22,7 @@ #include "Common.h" using namespace std; -using namespace eth; -using namespace p2p; -using namespace shh; +using namespace dev; +using namespace dev::p2p; +using namespace dev::shh; diff --git a/libwhisper/Common.h b/libwhisper/Common.h index 0addc4b75..9ca727c1e 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -28,18 +28,20 @@ #include #include +namespace dev +{ namespace shh { -using h256 = eth::h256; -using h512 = eth::h512; -using h256s = eth::h256s; -using bytes = eth::bytes; -using RLPStream = eth::RLPStream; -using RLP = eth::RLP; -using bytesRef = eth::bytesRef; -using bytesConstRef = eth::bytesConstRef; -using h256Set = eth::h256Set; +using h256 = dev::h256; +using h512 = dev::h512; +using h256s = dev::h256s; +using bytes = dev::bytes; +using RLPStream = dev::RLPStream; +using RLP = dev::RLP; +using bytesRef = dev::bytesRef; +using bytesConstRef = dev::bytesConstRef; +using h256Set = dev::h256Set; class WhisperHost; class WhisperPeer; @@ -54,3 +56,4 @@ enum WhisperPacket }; } +} diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index ee548949e..020170013 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -24,11 +24,11 @@ #include #include using namespace std; -using namespace eth; -using namespace p2p; -using namespace shh; +using namespace dev; +using namespace dev::p2p; +using namespace dev::shh; -#define clogS(X) eth::LogOutputStream(false) << "| " << std::setw(2) << session()->socketId() << "] " +#define clogS(X) dev::LogOutputStream(false) << "| " << std::setw(2) << session()->socketId() << "] " WhisperPeer::WhisperPeer(Session* _s, HostCapabilityFace* _h): Capability(_s, _h) { diff --git a/libwhisper/WhisperPeer.h b/libwhisper/WhisperPeer.h index 5db7ffa2b..dba3efed8 100644 --- a/libwhisper/WhisperPeer.h +++ b/libwhisper/WhisperPeer.h @@ -31,6 +31,8 @@ #include #include "Common.h" +namespace dev +{ namespace shh { @@ -59,7 +61,7 @@ struct Message operator bool () const { return !!expiry; } void streamOut(RLPStream& _s) const { _s.appendList(4) << expiry << ttl << topic << payload; } - h256 sha3() const { RLPStream s; streamOut(s); return eth::sha3(s.out()); } + h256 sha3() const { RLPStream s; streamOut(s); return dev::eth::sha3(s.out()); } }; /** @@ -84,7 +86,7 @@ private: unsigned rating(Message const&) const { return 0; } // TODO void noteNewMessage(h256 _h, Message const& _m); - mutable eth::Mutex x_unseen; + mutable dev::Mutex x_unseen; std::map m_unseen; ///< Rated according to what they want. }; @@ -96,7 +98,7 @@ public: MessageFilter(RLP const& _r): m_topicMasks((std::vector >)_r) {} void fillStream(RLPStream& _s) const { _s << m_topicMasks; } - h256 sha3() const { RLPStream s; fillStream(s); return eth::sha3(s.out()); } + h256 sha3() const { RLPStream s; fillStream(s); return dev::eth::sha3(s.out()); } bool matches(Message const& _m) const; @@ -136,10 +138,10 @@ public: unsigned installWatch(MessageFilter const& _filter); unsigned installWatch(h256 _filterId); void uninstallWatch(unsigned _watchId); - h256s peekWatch(unsigned _watchId) const { eth::Guard l(m_filterLock); try { return m_watches.at(_watchId).changes; } catch (...) { return h256s(); } } - h256s checkWatch(unsigned _watchId) { eth::Guard l(m_filterLock); h256s ret; try { ret = m_watches.at(_watchId).changes; m_watches.at(_watchId).changes.clear(); } catch (...) {} return ret; } + h256s peekWatch(unsigned _watchId) const { dev::Guard l(m_filterLock); try { return m_watches.at(_watchId).changes; } catch (...) { return h256s(); } } + h256s checkWatch(unsigned _watchId) { dev::Guard l(m_filterLock); h256s ret; try { ret = m_watches.at(_watchId).changes; m_watches.at(_watchId).changes.clear(); } catch (...) {} return ret; } - Message message(h256 _m) const { try { eth::ReadGuard l(x_messages); return m_messages.at(_m); } catch (...) { return Message(); } } + Message message(h256 _m) const { try { dev::ReadGuard l(x_messages); return m_messages.at(_m); } catch (...) { return Message(); } } void sendRaw(bytes const& _payload, bytes const& _topic, unsigned _ttl) { inject(Message(time(0) + _ttl, _ttl, _topic, _payload)); } @@ -148,19 +150,20 @@ private: void noteChanged(h256 _messageHash, h256 _filter); - mutable eth::SharedMutex x_messages; + mutable dev::SharedMutex x_messages; std::map m_messages; - mutable eth::Mutex m_filterLock; + mutable dev::Mutex m_filterLock; std::map m_filters; std::map m_watches; }; -struct WatchChannel: public eth::LogChannel { static const char* name() { return "shh"; } static const int verbosity = 1; }; -#define cwatch eth::LogOutputStream() +struct WatchChannel: public dev::LogChannel { static const char* name() { return "shh"; } static const int verbosity = 1; }; +#define cwatch dev::LogOutputStream() class Watch; +} } /* namespace std { void swap(shh::Watch& _a, shh::Watch& _b); } diff --git a/lllc/main.cpp b/lllc/main.cpp index 22d40d2da..ccdf5a11b 100644 --- a/lllc/main.cpp +++ b/lllc/main.cpp @@ -28,7 +28,8 @@ #include #include "BuildInfo.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; void help() { @@ -46,9 +47,9 @@ void help() void version() { - cout << "LLLC, the Lovely Little Language Compiler " << eth::EthVersion << endl; + cout << "LLLC, the Lovely Little Language Compiler " << dev::Version << endl; cout << " By Gav Wood, (c) 2014." << endl; - cout << "Build: " << ETH_QUOTED(ETH_BUILD_PLATFORM) << "/" << ETH_QUOTED(ETH_BUILD_TYPE) << endl; + cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; exit(0); } diff --git a/neth/main.cpp b/neth/main.cpp index dbb4ed4b6..67afc2664 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -48,10 +48,11 @@ #undef OK using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; using namespace p2p; using namespace boost::algorithm; -using eth::Instruction; +using dev::eth::Instruction; bool isTrue(std::string const& _m) { @@ -121,11 +122,11 @@ string credits() { std::ostringstream ccout; ccout - << "NEthereum (++) " << eth::EthVersion << endl + << "NEthereum (++) " << dev::Version << endl << " Code by Gav Wood & , (c) 2013, 2014." << endl << " Based on a design by Vitalik Buterin." << endl << endl; - string vs = toString(eth::EthVersion); + string vs = toString(dev::Version); vs = vs.substr(vs.find_first_of('.') + 1)[0]; int pocnumber = stoi(vs); string m_servers; @@ -142,14 +143,14 @@ string credits() void version() { - cout << "neth version " << eth::EthVersion << endl; - cout << "Build: " << ETH_QUOTED(ETH_BUILD_PLATFORM) << "/" << ETH_QUOTED(ETH_BUILD_TYPE) << endl; + cout << "neth version " << dev::Version << endl; + cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; exit(0); } Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f"); -string pretty(h160 _a, eth::State _st) +string pretty(h160 _a, dev::eth::State _st) { string ns; h256 n; @@ -412,7 +413,7 @@ int main(int argc, char** argv) if (!clientName.empty()) clientName += "/"; - Client c("NEthereum(++)/" + clientName + "v" + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); + Client c("NEthereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath); c.setForceMining(true); @@ -525,14 +526,14 @@ int main(int argc, char** argv) if (cmd == "netstart") { - eth::uint port; + unsigned port; iss >> port; c.startNetwork((short)port); } else if (cmd == "connect") { string addr; - eth::uint port; + unsigned port; iss >> addr >> port; c.connect(addr, (short)port); } @@ -582,7 +583,7 @@ int main(int argc, char** argv) } else if (cmd == "block") { - eth::uint n = c.blockChain().details().number; + unsigned n = c.blockChain().details().number; ccout << "Current block # "; ccout << toString(n) << endl; } @@ -645,7 +646,7 @@ int main(int argc, char** argv) string sdata = fields[5]; cnote << "Data:"; cnote << sdata; - bytes data = eth::parseData(sdata); + bytes data = dev::eth::parseData(sdata); cnote << "Bytes:"; string sbd = asString(data); bytes bbd = asBytes(sbd); @@ -810,7 +811,7 @@ int main(int argc, char** argv) cnote << "Saved" << rechex << "to" << outFile; } - catch (eth::InvalidTrie) + catch (dev::eth::InvalidTrie) { cwarn << "Corrupted trie."; } @@ -955,7 +956,7 @@ int main(int argc, char** argv) // Block mvwprintw(blockswin, 0, x, "Block # "); - eth::uint n = c.blockChain().details().number; + unsigned n = c.blockChain().details().number; mvwprintw(blockswin, 0, 10, toString(n).c_str()); // Pending @@ -976,7 +977,7 @@ int main(int argc, char** argv) if (c.isMining()) { mvwprintw(consolewin, qheight - 1, width / 4 - 11, "Mining ON"); - eth::MineProgress p = c.miningProgress(); + dev::eth::MineProgress p = c.miningProgress(); auto speed = boost::format("%2% kH/s @ %1%s") % (p.ms / 1000) % (p.ms ? p.hashes / p.ms : 0); mvwprintw(consolewin, qheight - 2, width / 4 - speed.str().length() - 2, speed.str().c_str()); } diff --git a/test/MemTrie.cpp b/test/MemTrie.cpp index 5c819ffbd..b5d875acb 100644 --- a/test/MemTrie.cpp +++ b/test/MemTrie.cpp @@ -25,9 +25,10 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -namespace eth +namespace dev { #define ENABLE_DEBUG_PRINT 0 @@ -54,7 +55,7 @@ public: #endif /// 256-bit hash of the node - this is a SHA-3/256 hash of the RLP of the node. - h256 hash256() const { RLPStream s; makeRLP(s); return eth::sha3(s.out()); } + h256 hash256() const { RLPStream s; makeRLP(s); return dev::eth::sha3(s.out()); } bytes rlp() const { RLPStream s; makeRLP(s); return s.out(); } void mark() { m_hash256 = h256(); } @@ -199,7 +200,7 @@ void MemTrieNode::putRLP(RLPStream& _parentStream) const if (s.out().size() < 32) _parentStream.APPEND_CHILD(s.out()); else - _parentStream << eth::sha3(s.out()); + _parentStream << dev::eth::sha3(s.out()); } void TrieBranchNode::makeRLP(RLPStream& _intoStream) const @@ -228,7 +229,7 @@ void TrieInfixNode::makeRLP(RLPStream& _intoStream) const MemTrieNode* MemTrieNode::newBranch(bytesConstRef _k1, std::string const& _v1, bytesConstRef _k2, std::string const& _v2) { - uint prefix = commonPrefix(_k1, _k2); + unsigned prefix = commonPrefix(_k1, _k2); MemTrieNode* ret; if (_k1.size() == prefix) @@ -347,7 +348,7 @@ MemTrieNode* TrieInfixNode::insert(bytesConstRef _key, std::string const& _value } else { - uint prefix = commonPrefix(_key, m_ext); + unsigned prefix = commonPrefix(_key, m_ext); if (prefix) { // one infix becomes two infixes, then insert into the second @@ -478,3 +479,4 @@ void MemTrie::remove(std::string const& _key) } } + diff --git a/test/MemTrie.h b/test/MemTrie.h index 8c90f2f3f..66669653c 100644 --- a/test/MemTrie.h +++ b/test/MemTrie.h @@ -24,7 +24,7 @@ #include #include -namespace eth +namespace dev { class MemTrieNode; diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 06f188a89..02a883dbc 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -19,11 +19,14 @@ * @date 2014 */ +#include "TestHelper.h" + #include #include #include -#include "TestHelper.h" +namespace dev +{ namespace eth { @@ -47,3 +50,4 @@ void connectClients(Client& c1, Client& c2) } } +} diff --git a/test/TestHelper.h b/test/TestHelper.h index 748373baa..d6924a17c 100644 --- a/test/TestHelper.h +++ b/test/TestHelper.h @@ -21,10 +21,15 @@ #pragma once +namespace dev +{ namespace eth { +class Client; + void mine(Client& c, int numBlocks); void connectClients(Client& c1, Client& c2); } +} diff --git a/test/TrieHash.cpp b/test/TrieHash.cpp index 8f4161a17..b2ebce731 100644 --- a/test/TrieHash.cpp +++ b/test/TrieHash.cpp @@ -25,9 +25,10 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; -namespace eth +namespace dev { /*/ @@ -67,12 +68,12 @@ void hash256rlp(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_i { // find the number of common prefix nibbles shared // i.e. the minimum number of nibbles shared at the beginning between the first hex string and each successive. - uint sharedPre = (uint)-1; - uint c = 0; + unsigned sharedPre = (unsigned)-1; + unsigned c = 0; for (auto i = std::next(_begin); i != _end && sharedPre; ++i, ++c) { - uint x = std::min(sharedPre, std::min((uint)_begin->first.size(), (uint)i->first.size())); - uint shared = _preLen; + unsigned x = std::min(sharedPre, std::min((unsigned)_begin->first.size(), (unsigned)i->first.size())); + unsigned shared = _preLen; for (; shared < x && _begin->first[shared] == i->first[shared]; ++shared) {} sharedPre = std::min(shared, sharedPre); } diff --git a/test/TrieHash.h b/test/TrieHash.h index 391c42633..4d86c4dbf 100644 --- a/test/TrieHash.h +++ b/test/TrieHash.h @@ -24,7 +24,7 @@ #include #include -namespace eth +namespace dev { bytes rlp256(StringMap const& _s); diff --git a/test/crypto.cpp b/test/crypto.cpp index c39de78d7..2e4ffa055 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -29,7 +29,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; BOOST_AUTO_TEST_CASE(crypto_tests) @@ -145,7 +146,7 @@ int cryptoTest() int ret = secp256k1_ecdsa_recover_compact((byte const*)hmsg.data(), (int)hmsg.size(), (byte const*)sig64.data(), pubkey.data(), &pubkeylen, 0, (int)t.vrs.v - 27); pubkey.resize(pubkeylen); cout << "RECPUB: " << dec << ret << " " << pubkeylen << " " << toHex(pubkey) << endl; - cout << "SENDER: " << hex << toAddress(eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; + cout << "SENDER: " << hex << toAddress(dev::eth::sha3(bytesConstRef(&pubkey).cropped(1))) << dec << endl; } #endif return 0; diff --git a/test/dagger.cpp b/test/dagger.cpp index 4f65b47aa..fd60a8efa 100644 --- a/test/dagger.cpp +++ b/test/dagger.cpp @@ -25,7 +25,8 @@ #include using namespace std; using namespace std::chrono; -using namespace eth; +using namespace dev; +using namespace dev::eth; int daggerTest() { diff --git a/test/fork.cpp b/test/fork.cpp index f0edb702f..1cdb8822c 100644 --- a/test/fork.cpp +++ b/test/fork.cpp @@ -27,7 +27,8 @@ #include #include "TestHelper.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; // Disabled since tests shouldn't block. Need a short cut to avoid real mining. /* diff --git a/test/genesis.cpp b/test/genesis.cpp index 441826e78..be6655aba 100644 --- a/test/genesis.cpp +++ b/test/genesis.cpp @@ -28,7 +28,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; namespace js = json_spirit; diff --git a/test/hexPrefix.cpp b/test/hexPrefix.cpp index 5ea670923..7dbe80a57 100644 --- a/test/hexPrefix.cpp +++ b/test/hexPrefix.cpp @@ -27,7 +27,8 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; namespace js = json_spirit; BOOST_AUTO_TEST_CASE(hexPrefix_test) diff --git a/test/main.cpp b/test/main.cpp index 1497f2981..08142095c 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -38,7 +38,8 @@ int peerTest(int argc, char** argv); #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; BOOST_AUTO_TEST_CASE(basic_tests) { diff --git a/test/network.cpp b/test/network.cpp index 978d68934..acdd649d9 100644 --- a/test/network.cpp +++ b/test/network.cpp @@ -27,7 +27,8 @@ #include #include "TestHelper.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; // Disabled since tests shouldn't block (not the worst offender, but timeout should be reduced anyway). /* diff --git a/test/peer.cpp b/test/peer.cpp index f903d0429..821aab514 100644 --- a/test/peer.cpp +++ b/test/peer.cpp @@ -24,8 +24,8 @@ #include #include using namespace std; -using namespace eth; -using namespace p2p; +using namespace dev; +using namespace dev::p2p; int peerTest(int argc, char** argv) { diff --git a/test/rlp.cpp b/test/rlp.cpp index 548be8d9b..963d61091 100644 --- a/test/rlp.cpp +++ b/test/rlp.cpp @@ -30,10 +30,10 @@ #include using namespace std; -using namespace eth; +using namespace dev; namespace js = json_spirit; -namespace eth +namespace dev { namespace test { @@ -116,7 +116,7 @@ namespace eth BOOST_CHECK( !u.isData() ); js::mArray& arr = v.get_array(); BOOST_CHECK( u.itemCount() == arr.size() ); - uint i; + unsigned i; for( i = 0; i < arr.size(); i++ ) { RLP item = u[i]; @@ -137,16 +137,16 @@ BOOST_AUTO_TEST_CASE(rlp_encoding_test) { cnote << "Testing RLP Encoding..."; js::mValue v; - eth::test::getRLPTestCases(v); + dev::test::getRLPTestCases(v); for (auto& i: v.get_obj()) { js::mObject& o = i.second.get_obj(); cnote << i.first; - eth::test::checkRLPTestCase(o); + dev::test::checkRLPTestCase(o); RLPStream s; - eth::test::buildRLP(o["in"], s); + dev::test::buildRLP(o["in"], s); std::string expectedText(o["out"].get_str()); std::transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower ); @@ -173,19 +173,19 @@ BOOST_AUTO_TEST_CASE(rlp_decoding_test) // and then compare the output structure to the json of the // input object. js::mValue v; - eth::test::getRLPTestCases(v); + dev::test::getRLPTestCases(v); for (auto& i: v.get_obj()) { js::mObject& o = i.second.get_obj(); cnote << i.first; - eth::test::checkRLPTestCase(o); + dev::test::checkRLPTestCase(o); js::mValue& inputData = o["in"]; bytes payloadToDecode = fromHex(o["out"].get_str()); RLP payload(payloadToDecode); - eth::test::checkRLPAgainstJson(inputData, payload); + dev::test::checkRLPAgainstJson(inputData, payload); } } diff --git a/test/state.cpp b/test/state.cpp index 8d82b0c2b..99ce30957 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -26,7 +26,8 @@ #include #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; int stateTest() { diff --git a/test/trie.cpp b/test/trie.cpp index b28be8b18..4ddf30a61 100644 --- a/test/trie.cpp +++ b/test/trie.cpp @@ -29,22 +29,23 @@ #include using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; namespace js = json_spirit; -namespace eth -{ - namespace test - { - static unsigned fac(unsigned _i) - { - return _i > 2 ? _i * fac(_i - 1) : _i; - } +namespace dev +{ +namespace test +{ - } +static unsigned fac(unsigned _i) +{ + return _i > 2 ? _i * fac(_i - 1) : _i; } +} +} BOOST_AUTO_TEST_CASE(trie_tests) { @@ -66,7 +67,7 @@ BOOST_AUTO_TEST_CASE(trie_tests) if (!ss.back().second.find("0x")) ss.back().second = asString(fromHex(ss.back().second.substr(2))); } - for (unsigned j = 0; j < min(1000u, eth::test::fac((unsigned)ss.size())); ++j) + for (unsigned j = 0; j < min(1000u, dev::test::fac((unsigned)ss.size())); ++j) { next_permutation(ss.begin(), ss.end()); MemoryDB m; diff --git a/test/txTest.cpp b/test/txTest.cpp index 314cf9644..cc78c26a2 100644 --- a/test/txTest.cpp +++ b/test/txTest.cpp @@ -27,7 +27,8 @@ #include #include "TestHelper.h" using namespace std; -using namespace eth; +using namespace dev; +using namespace dev::eth; // Disabled since tests shouldn't block. Need a short cut to avoid real mining. /* @@ -46,7 +47,7 @@ BOOST_AUTO_TEST_CASE(mine_local_simple_tx) //send c2 some eth from c1 auto txAmount = c1bal / 2u; auto gasPrice = 10 * szabo; - auto gas = eth::c_callGas; + auto gas = dev::eth::c_callGas; c1.transact(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice); //mine some more to include the transaction on chain @@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE(mine_and_send_to_peer) //send c2 some eth from c1 auto txAmount = c1bal / 2u; auto gasPrice = 10 * szabo; - auto gas = eth::c_callGas; + auto gas = dev::eth::c_callGas; c1.transact(kp1.secret(), txAmount, kp2.address(), bytes(), gas, gasPrice); //mine some more to include the transaction on chain @@ -105,7 +106,7 @@ BOOST_AUTO_TEST_CASE(mine_and_send_to_peer_fee_check) //send c2 some eth from c1 auto txAmount = c1StartBalance / 2u; auto gasPrice = 10 * szabo; - auto gas = eth::c_callGas; + auto gas = dev::eth::c_callGas; 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) diff --git a/test/vm.cpp b/test/vm.cpp index 0647849a0..2b75f0b3d 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -33,9 +33,10 @@ using namespace std; using namespace json_spirit; -using namespace eth; +using namespace dev; +using namespace dev::eth; -namespace eth { namespace test { +namespace dev { namespace test { class FakeExtVM: public ExtVMFace { @@ -387,7 +388,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) BOOST_REQUIRE(o.count("exec") > 0); VM vm; - eth::test::FakeExtVM fev; + dev::test::FakeExtVM fev; fev.importEnv(o["env"].get_obj()); fev.importState(o["pre"].get_obj()); @@ -419,7 +420,7 @@ void doTests(json_spirit::mValue& v, bool _fillin) BOOST_REQUIRE(o.count("out") > 0); BOOST_REQUIRE(o.count("gas") > 0); - eth::test::FakeExtVM test; + dev::test::FakeExtVM test; test.importState(o["post"].get_obj()); test.importCallCreates(o["callcreates"].get_array()); int i = 0; @@ -481,7 +482,7 @@ BOOST_AUTO_TEST_CASE(vm_tests) string s = asString(contents("../../../cpp-ethereum/test/vmtests.json")); BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'vmtests.json' is empty."); json_spirit::read_string(s, v); - eth::test::doTests(v, true); + dev::test::doTests(v, true); writeFile("../../../tests/vmtests.json", asBytes(json_spirit::write_string(v, true))); } /* catch (std::exception const& e) @@ -496,7 +497,7 @@ BOOST_AUTO_TEST_CASE(vm_tests) string s = asString(contents("../../../tests/vmtests.json")); BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'vmtests.json' is empty. Have you cloned the 'tests' repo branch develop?"); json_spirit::read_string(s, v); - eth::test::doTests(v, false); + dev::test::doTests(v, false); } catch (std::exception const& e) { diff --git a/third/MainWin.cpp b/third/MainWin.cpp index 22ce25b66..b8722f2d7 100644 --- a/third/MainWin.cpp +++ b/third/MainWin.cpp @@ -44,45 +44,45 @@ using namespace std; // types -using eth::bytes; -using eth::bytesConstRef; -using eth::h160; -using eth::h256; -using eth::u160; -using eth::u256; -using eth::Address; -using eth::BlockInfo; -using eth::Client; -using eth::Instruction; -using eth::KeyPair; -using eth::NodeMode; -using eth::BlockChain; -using p2p::PeerInfo; -using eth::RLP; -using eth::Secret; -using eth::Transaction; -using eth::Executive; +using dev::bytes; +using dev::bytesConstRef; +using dev::h160; +using dev::h256; +using dev::u160; +using dev::u256; +using dev::eth::Address; +using dev::eth::BlockInfo; +using dev::eth::Client; +using dev::eth::Instruction; +using dev::eth::KeyPair; +using dev::eth::NodeMode; +using dev::eth::BlockChain; +using dev::p2p::PeerInfo; +using dev::RLP; +using dev::eth::Secret; +using dev::eth::Transaction; +using dev::eth::Executive; // functions -using eth::toHex; -using eth::compileLLL; -using eth::disassemble; -using eth::formatBalance; -using eth::fromHex; -using eth::sha3; -using eth::left160; -using eth::right160; -using eth::simpleDebugOut; -using eth::toLog2; -using eth::toString; -using eth::units; -using eth::operator<<; +using dev::toHex; +using dev::fromHex; +using dev::left160; +using dev::right160; +using dev::simpleDebugOut; +using dev::toLog2; +using dev::toString; +using dev::operator<<; +using dev::eth::units; +using dev::eth::compileLLL; +using dev::eth::disassemble; +using dev::eth::formatBalance; +using dev::eth::sha3; // vars -using eth::g_logPost; -using eth::g_logVerbosity; +using dev::g_logPost; +using dev::g_logVerbosity; -static QString fromRaw(eth::h256 _n, unsigned* _inc = nullptr) +static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr) { if (_n) { @@ -121,8 +121,8 @@ Main::Main(QWidget *parent) : cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl; cerr << "Block RLP: " << RLP(BlockChain::createGenesisBlock()) << endl; cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl; - cerr << "Network protocol version: " << eth::c_protocolVersion << endl; - cerr << "Client database version: " << eth::c_databaseVersion << endl; + cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl; + cerr << "Client database version: " << dev::eth::c_databaseVersion << endl; ui->ownedAccountsDock->hide(); @@ -186,14 +186,14 @@ void Main::onKeysChanged() installBalancesWatch(); } -unsigned Main::installWatch(eth::MessageFilter const& _tf, std::function const& _f) +unsigned Main::installWatch(dev::eth::MessageFilter const& _tf, std::function const& _f) { auto ret = m_client->installWatch(_tf); m_handlers[ret] = _f; return ret; } -unsigned Main::installWatch(eth::h256 _tf, std::function const& _f) +unsigned Main::installWatch(dev::h256 _tf, std::function const& _f) { auto ret = m_client->installWatch(_tf); m_handlers[ret] = _f; @@ -202,26 +202,26 @@ unsigned Main::installWatch(eth::h256 _tf, std::function const& _f) void Main::installWatches() { - installWatch(eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); }); - installWatch(eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); }); - installWatch(eth::ChainChangedFilter, [=](){ onNewBlock(); }); + installWatch(dev::eth::MessageFilter().altered(c_config, 0), [=](){ installNameRegWatch(); }); + installWatch(dev::eth::MessageFilter().altered(c_config, 1), [=](){ installCurrenciesWatch(); }); + installWatch(dev::eth::ChainChangedFilter, [=](){ onNewBlock(); }); } void Main::installNameRegWatch() { m_client->uninstallWatch(m_nameRegFilter); - m_nameRegFilter = installWatch(eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 0)), [=](){ onNameRegChange(); }); + m_nameRegFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 0)), [=](){ onNameRegChange(); }); } void Main::installCurrenciesWatch() { m_client->uninstallWatch(m_currenciesFilter); - m_currenciesFilter = installWatch(eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); }); + m_currenciesFilter = installWatch(dev::eth::MessageFilter().altered((u160)m_client->stateAt(c_config, 1)), [=](){ onCurrenciesChange(); }); } void Main::installBalancesWatch() { - eth::MessageFilter tf; + dev::eth::MessageFilter tf; vector
altCoins; Address coinsAddr = right160(m_client->stateAt(c_config, 1)); @@ -291,7 +291,7 @@ void Main::eval(QString const& _js) ui->webView->page()->currentFrame()->evaluateJavaScript("___RET=(" + _js + ")"); } -QString Main::pretty(eth::Address _a) const +QString Main::pretty(dev::eth::Address _a) const { h256 n; @@ -301,7 +301,7 @@ QString Main::pretty(eth::Address _a) const return fromRaw(n); } -QString Main::render(eth::Address _a) const +QString Main::render(dev::eth::Address _a) const { QString p = pretty(_a); if (!p.isNull()) @@ -368,7 +368,7 @@ QString Main::lookup(QString const& _a) const void Main::on_about_triggered() { - QMessageBox::about(this, "About Third PoC-" + QString(eth::EthVersion).section('.', 1, 1), QString("Third/v") + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM) "\n" ETH_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); + QMessageBox::about(this, "About Third PoC-" + QString(dev::Version).section('.', 1, 1), QString("Third/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); } void Main::writeSettings() @@ -466,7 +466,7 @@ void Main::on_urlEdit_returnPressed() void Main::refreshMining() { - eth::MineProgress p = m_client->miningProgress(); + dev::eth::MineProgress p = m_client->miningProgress(); ui->mineStatus->setText(m_client->isMining() ? QString("%1s @ %2kH/s").arg(p.ms / 1000).arg(p.ms ? p.hashes / p.ms : 0) : "Not mining"); } @@ -516,7 +516,7 @@ void Main::refreshBlockCount() cwatch << "refreshBlockCount()"; auto d = m_client->blockChain().details(); auto diff = BlockInfo(m_client->blockChain().block()).difficulty; - ui->blockCount->setText(QString("#%1 @%3 T%2 N%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(eth::c_protocolVersion).arg(eth::c_databaseVersion)); + ui->blockCount->setText(QString("#%1 @%3 T%2 N%4 D%5").arg(d.number).arg(toLog2(d.totalDifficulty)).arg(toLog2(diff)).arg(dev::eth::c_protocolVersion).arg(dev::eth::c_databaseVersion)); } void Main::timerEvent(QTimerEvent*) @@ -572,11 +572,11 @@ void Main::on_ourAccounts_doubleClicked() void Main::ensureNetwork() { - string n = string("Third/v") + eth::EthVersion; - n += "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM); + string n = string("Third/v") + dev::Version; + n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM); m_client->setClientVersion(n); - int pocnumber = QString(eth::EthVersion).section('.', 1, 1).toInt(); + int pocnumber = QString(dev::Version).section('.', 1, 1).toInt(); string defPeer; if (pocnumber == 5) defPeer = "54.72.69.180"; diff --git a/third/MainWin.h b/third/MainWin.h index 4706b5158..6fc7a6a5d 100644 --- a/third/MainWin.h +++ b/third/MainWin.h @@ -36,11 +36,11 @@ namespace Ui { class Main; } -namespace eth { +namespace dev { namespace eth { class Client; class State; class MessageFilter; -} +}} class QQuickView; @@ -52,9 +52,9 @@ public: explicit Main(QWidget *parent = 0); ~Main(); - eth::Client* client() { return m_client.get(); } + dev::eth::Client* client() { return m_client.get(); } - QList const& owned() const { return m_myKeys; } + QList const& owned() const { return m_myKeys; } public slots: void note(QString _entry); @@ -79,16 +79,16 @@ signals: void poll(); private: - QString pretty(eth::Address _a) const; - QString render(eth::Address _a) const; - eth::Address fromString(QString const& _a) const; + QString pretty(dev::eth::Address _a) const; + QString render(dev::eth::Address _a) const; + dev::eth::Address fromString(QString const& _a) const; QString lookup(QString const& _n) const; void readSettings(bool _skipGeometry = false); void writeSettings(); - unsigned installWatch(eth::MessageFilter const& _tf, std::function const& _f); - unsigned installWatch(eth::h256 _tf, std::function const& _f); + unsigned installWatch(dev::eth::MessageFilter const& _tf, std::function const& _f); + unsigned installWatch(dev::h256 _tf, std::function const& _f); void onNewBlock(); void onNameRegChange(); @@ -111,9 +111,9 @@ private: std::unique_ptr ui; - std::unique_ptr m_client; + std::unique_ptr m_client; - QList m_myKeys; + QList m_myKeys; std::map> m_handlers; unsigned m_nameRegFilter = (unsigned)-1; diff --git a/walleth/MainWin.cpp b/walleth/MainWin.cpp index 8abd9ba60..a07230885 100644 --- a/walleth/MainWin.cpp +++ b/walleth/MainWin.cpp @@ -18,38 +18,38 @@ using namespace std; // types -using eth::bytes; -using eth::bytesConstRef; -using eth::h160; -using eth::h256; -using eth::u160; -using eth::u256; -using eth::u256s; -using eth::Address; -using eth::BlockInfo; -using eth::Client; -using eth::Instruction; -using eth::KeyPair; -using eth::NodeMode; -using p2p::PeerInfo; -using eth::RLP; -using eth::Secret; -using eth::Transaction; +using dev::bytes; +using dev::bytesConstRef; +using dev::h160; +using dev::h256; +using dev::u160; +using dev::u256; +using dev::u256s; +using dev::eth::Address; +using dev::eth::BlockInfo; +using dev::eth::Client; +using dev::eth::Instruction; +using dev::eth::KeyPair; +using dev::eth::NodeMode; +using dev::p2p::PeerInfo; +using dev::RLP; +using dev::eth::Secret; +using dev::eth::Transaction; // functions -using eth::toHex; -using eth::disassemble; -using eth::formatBalance; -using eth::fromHex; -using eth::right160; -using eth::simpleDebugOut; -using eth::toLog2; -using eth::toString; -using eth::units; +using dev::toHex; +using dev::fromHex; +using dev::right160; +using dev::simpleDebugOut; +using dev::toLog2; +using dev::toString; +using dev::eth::units; +using dev::eth::disassemble; +using dev::eth::formatBalance; // vars -using eth::g_logPost; -using eth::g_logVerbosity; +using dev::g_logPost; +using dev::g_logVerbosity; Main::Main(QWidget *parent) : QMainWindow(parent), @@ -61,14 +61,14 @@ Main::Main(QWidget *parent) : g_qmlMain = this; - m_client.reset(new Client("Walleth", Address(), eth::getDataDir() + "/Walleth")); + m_client.reset(new Client("Walleth", Address(), dev::eth::getDataDir() + "/Walleth")); g_qmlClient = m_client.get(); - qRegisterMetaType("eth::u256"); - qRegisterMetaType("eth::KeyPair"); - qRegisterMetaType("eth::Secret"); - qRegisterMetaType("eth::Address"); + qRegisterMetaType("dev::u256"); + qRegisterMetaType("dev::eth::KeyPair"); + qRegisterMetaType("dev::eth::Secret"); + qRegisterMetaType("dev::eth::Address"); qRegisterMetaType("QmlAccount*"); qRegisterMetaType("QmlEthereum*"); @@ -112,7 +112,7 @@ Main::Main(QWidget *parent) : on_net_triggered(true); } }); - QNetworkRequest r(QUrl("http://www.ethereum.org/servers.poc" + QString(eth::EthVersion).section('.', 1, 1) + ".txt")); + QNetworkRequest r(QUrl("http://www.ethereum.org/servers.poc" + QString(dev::Version).section('.', 1, 1) + ".txt")); r.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.0 Safari/537.36"); m_webCtrl.get(r); srand(time(0)); @@ -136,7 +136,7 @@ void Main::timerEvent(QTimerEvent *) void Main::on_about_triggered() { - QMessageBox::about(this, "About Walleth PoC-" + QString(eth::EthVersion).section('.', 1, 1), QString("Walleth/v") + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM) "\n" ETH_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); + QMessageBox::about(this, "About Walleth PoC-" + QString(dev::Version).section('.', 1, 1), QString("Walleth/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); } void Main::writeSettings() @@ -217,10 +217,10 @@ void Main::refresh() void Main::on_net_triggered(bool _auto) { - string n = string("Walleth/v") + eth::EthVersion; + string n = string("Walleth/v") + dev::Version; if (m_clientName.size()) n += "/" + m_clientName.toStdString(); - n += "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM); + n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM); client()->setClientVersion(n); if (ui->net->isChecked()) { diff --git a/walleth/MainWin.h b/walleth/MainWin.h index b4c192d01..0edbff226 100644 --- a/walleth/MainWin.h +++ b/walleth/MainWin.h @@ -12,10 +12,10 @@ namespace Ui { class Main; } -namespace eth { +namespace dev { namespace eth { class Client; class State; -} +}} class QQuickView; class QQmlEngine; @@ -29,7 +29,7 @@ public: explicit Main(QWidget *parent = 0); ~Main(); - eth::Client* client() const { return m_client.get(); } + dev::eth::Client* client() const { return m_client.get(); } private slots: void on_connect_triggered(); @@ -47,19 +47,19 @@ protected: virtual void timerEvent(QTimerEvent *); private: -/* QString pretty(eth::Address _a) const; - QString render(eth::Address _a) const; - eth::Address fromString(QString const& _a) const; +/* QString pretty(dev::eth::Address _a) const; + QString render(dev::eth::Address _a) const; + dev::eth::Address fromString(QString const& _a) const; */ - eth::State const& state() const; + dev::eth::State const& state() const; void updateFee(); void readSettings(); void writeSettings(); - eth::u256 fee() const; - eth::u256 total() const; - eth::u256 value() const; + dev::u256 fee() const; + dev::u256 total() const; + dev::u256 value() const; std::unique_ptr ui; @@ -67,7 +67,7 @@ private: QMutex m_guiLock; QTimer* m_refresh; QTimer* m_refreshNetwork; - QVector m_myKeys; + QVector m_myKeys; bool m_keysChanged = false; int m_port; int m_idealPeers; @@ -78,7 +78,7 @@ private: QNetworkAccessManager m_webCtrl; - std::unique_ptr m_client; + std::unique_ptr m_client; }; #endif // MAIN_H