(new Executive(m_executiveState));
- Transaction t = st.pending()[txi];
+ Transaction t = m_executiveState.pending()[txi];
+ m_executiveState = m_executiveState.fromPending(txi);
auto r = t.rlp();
populateDebugger(&r);
m_currentExecution.reset();
@@ -962,7 +1146,6 @@ void Main::on_debugCurrent_triggered()
void Main::on_debugDumpState_triggered(int _add)
{
- eth::ClientGuard g(m_client.get());
if (auto item = ui->blocks->currentItem())
{
auto hba = item->data(Qt::UserRole).toByteArray();
@@ -975,9 +1158,8 @@ void Main::on_debugDumpState_triggered(int _add)
ofstream f(fn.toStdString());
if (f.is_open())
{
- eth::State st(m_client->state().db(), m_client->blockChain(), h);
unsigned txi = item->data(Qt::UserRole + 1).toInt();
- f << st.fromPending(txi + _add) << endl;
+ f << ethereum()->state(txi + _add, h) << endl;
}
}
}
@@ -988,7 +1170,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)
@@ -1000,10 +1182,10 @@ void Main::populateDebugger(eth::bytesConstRef _r)
bytesConstRef lastData;
h256 lastHash;
h256 lastDataHash;
- auto onOp = [&](uint64_t steps, Instruction inst, unsigned 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;
@@ -1025,6 +1207,7 @@ void Main::populateDebugger(eth::bytesConstRef _r)
m_history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, vm.gas(), lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels}));
};
m_currentExecution->go(onOp);
+ m_currentExecution->finalize(onOp);
initDebugger();
updateDebugger();
}
@@ -1033,33 +1216,32 @@ void Main::populateDebugger(eth::bytesConstRef _r)
void Main::on_contracts_currentItemChanged()
{
ui->contractInfo->clear();
- eth::ClientGuard l(&*m_client);
if (auto item = ui->contracts->currentItem())
{
auto hba = item->data(Qt::UserRole).toByteArray();
assert(hba.size() == 20);
- auto h = h160((byte const*)hba.data(), h160::ConstructFromPointer);
+ auto address = h160((byte const*)hba.data(), h160::ConstructFromPointer);
stringstream s;
try
{
- auto storage = state().storage(h);
+ auto storage = ethereum()->storageAt(address);
for (auto const& i: storage)
s << "@" << showbase << hex << prettyU256(i.first).toStdString() << " " << showbase << hex << prettyU256(i.second).toStdString() << "
";
- s << "Body Code
" << disassemble(state().code(h));
+ s << "Body Code
" << disassemble(ethereum()->codeAt(address));
ui->contractInfo->appendHtml(QString::fromStdString(s.str()));
}
- catch (eth::InvalidTrie)
+ catch (dev::eth::InvalidTrie)
{
ui->contractInfo->appendHtml("Corrupted trie.");
}
+ ui->contractInfo->moveCursor(QTextCursor::Start);
}
}
void Main::on_idealPeers_valueChanged()
{
- if (m_client->peerServer())
- m_client->peerServer()->setIdealPeerCount(ui->idealPeers->value());
+ m_webThree->setIdealPeerCount(ui->idealPeers->value());
}
void Main::on_ourAccounts_doubleClicked()
@@ -1071,7 +1253,8 @@ void Main::on_ourAccounts_doubleClicked()
void Main::on_log_doubleClicked()
{
- qApp->clipboard()->setText(ui->log->currentItem()->text());
+ ui->log->setPlainText("");
+ m_logHistory.clear();
}
void Main::on_accounts_doubleClicked()
@@ -1115,14 +1298,12 @@ void Main::on_data_textChanged()
}
else
{
- auto asmcode = eth::compileLLLToAsm(src, false);
- auto asmcodeopt = eth::compileLLLToAsm(ui->data->toPlainText().toStdString(), true);
- m_data = eth::compileLLL(ui->data->toPlainText().toStdString(), true, &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 + ")";
}
@@ -1132,7 +1313,15 @@ void Main::on_data_textChanged()
}
}
else
- lll = "Opt
" + QString::fromStdString(asmcodeopt).toHtmlEscaped() + "
Pre
" + QString::fromStdString(asmcode).toHtmlEscaped() + "
";
+ {
+ auto asmcode = dev::eth::compileLLLToAsm(src, false);
+ lll = "Pre
" + QString::fromStdString(asmcode).toHtmlEscaped() + "
";
+ if (m_enableOptimizer)
+ {
+ asmcode = dev::eth::compileLLLToAsm(src, true);
+ lll = "Opt
" + QString::fromStdString(asmcode).toHtmlEscaped() + "
" + lll;
+ }
+ }
}
QString errs;
if (errors.size())
@@ -1142,7 +1331,7 @@ void Main::on_data_textChanged()
errs.append("" + QString::fromStdString(i).toHtmlEscaped() + "
");
}
ui->code->setHtml(errs + lll + "Code
" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped());
- ui->gas->setMinimum((qint64)state().createGas(m_data.size(), 0));
+ ui->gas->setMinimum((qint64)Client::txGas(m_data.size(), 0));
if (!ui->gas->isEnabled())
ui->gas->setValue(m_backupGas);
ui->gas->setEnabled(true);
@@ -1153,8 +1342,9 @@ void Main::on_data_textChanged()
QString s = ui->data->toPlainText();
while (s.size())
{
- QRegExp r("(@|\\$)?\"([^\"]*)\"(.*)");
- QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(.*)");
+ QRegExp r("(@|\\$)?\"([^\"]*)\"(\\s.*)?");
+ QRegExp d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?");
+ QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?");
if (r.exactMatch(s))
{
for (auto i: r.cap(2))
@@ -1166,6 +1356,23 @@ void Main::on_data_textChanged()
m_data.push_back(0);
s = r.cap(3);
}
+ else if (d.exactMatch(s))
+ {
+ u256 v(d.cap(2).toStdString());
+ if (d.cap(6) == "szabo")
+ v *= dev::eth::szabo;
+ else if (d.cap(5) == "finney")
+ v *= dev::eth::finney;
+ else if (d.cap(4) == "ether")
+ 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);
+ for (auto b: bs)
+ m_data.push_back(b);
+ s = d.cap(7);
+ }
else if (h.exactMatch(s))
{
bytes bs = fromHex((((h.cap(3).size() & 1) ? "0" : "") + h.cap(3)).toStdString());
@@ -1179,10 +1386,10 @@ void Main::on_data_textChanged()
else
s = s.mid(1);
}
- ui->code->setHtml(QString::fromStdString(eth::memDump(m_data, 8, true)));
- if (m_client->postState().addressHasCode(fromString(ui->destination->currentText())))
+ ui->code->setHtml(QString::fromStdString(dev::memDump(m_data, 8, true)));
+ if (ethereum()->codeAt(fromString(ui->destination->currentText()), 0).size())
{
- ui->gas->setMinimum((qint64)state().callGas(m_data.size(), 1));
+ ui->gas->setMinimum((qint64)Client::txGas(m_data.size(), 1));
if (!ui->gas->isEnabled())
ui->gas->setValue(m_backupGas);
ui->gas->setEnabled(true);
@@ -1191,7 +1398,7 @@ void Main::on_data_textChanged()
{
if (ui->gas->isEnabled())
m_backupGas = ui->gas->value();
- ui->gas->setValue((qint64)state().callGas(m_data.size()));
+ ui->gas->setValue((qint64)Client::txGas(m_data.size()));
ui->gas->setEnabled(false);
}
}
@@ -1203,10 +1410,12 @@ void Main::on_killBlockchain_triggered()
writeSettings();
ui->mine->setChecked(false);
ui->net->setChecked(false);
- m_client.reset();
- m_client.reset(new Client("AlethZero", Address(), string(), true));
- m_client->start();
- readSettings();
+ web3()->stopNetwork();
+ ethereum()->killChain();
+ m_ethereum->setClient(ethereum());
+ readSettings(true);
+ installWatches();
+ refreshAll();
}
bool Main::isCreation() const
@@ -1246,7 +1455,7 @@ void Main::updateFee()
bool ok = false;
for (auto i: m_myKeys)
- if (state().balance(i.address()) >= totalReq)
+ if (ethereum()->balanceAt(i.address()) >= totalReq)
{
ok = true;
break;
@@ -1261,19 +1470,28 @@ 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);
- m_client->setClientVersion(n);
+ n += "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM);
+ web3()->setClientVersion(n);
if (ui->net->isChecked())
{
- m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked());
+ // TODO: alter network stuff?
+ //ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked(), m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0
+ web3()->setIdealPeerCount(ui->idealPeers->value());
+ web3()->setNetworkPreferences(netPrefs());
+ ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0);
+ web3()->startNetwork();
+ ui->downloadView->setDownloadMan(ethereum()->downloadMan());
if (m_peers.size() && ui->usePast->isChecked())
- m_client->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
+ web3()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
}
else
- m_client->stopNetwork();
+ {
+ ui->downloadView->setDownloadMan(nullptr);
+ web3()->stopNetwork();
+ }
}
void Main::on_connect_triggered()
@@ -1289,7 +1507,7 @@ void Main::on_connect_triggered()
{
string host = s.section(":", 0, 0).toStdString();
unsigned short port = s.section(":", 1).toInt();
- m_client->connect(host, port);
+ web3()->connect(host, port);
}
}
@@ -1303,27 +1521,25 @@ void Main::on_mine_triggered()
{
if (ui->mine->isChecked())
{
- m_client->setAddress(m_myKeys.last().address());
- m_client->startMining();
+ ethereum()->setAddress(m_myKeys.last().address());
+ ethereum()->startMining();
}
else
- m_client->stopMining();
+ ethereum()->stopMining();
}
void Main::on_send_clicked()
{
u256 totalReq = value() + fee();
- eth::ClientGuard l(&*m_client);
for (auto i: m_myKeys)
- if (m_client->postState().balance(i.address()) >= totalReq)
+ if (ethereum()->balanceAt(i.address(), 0) >= totalReq)
{
debugFinished();
Secret s = i.secret();
if (isCreation())
- m_client->transact(s, value(), m_data, ui->gas->value(), gasPrice());
+ ethereum()->transact(s, value(), m_data, ui->gas->value(), gasPrice());
else
- m_client->transact(s, value(), fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice());
- refresh();
+ ethereum()->transact(s, value(), fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice());
return;
}
statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount.");
@@ -1335,15 +1551,14 @@ void Main::on_debug_clicked()
try
{
u256 totalReq = value() + fee();
- eth::ClientGuard l(&*m_client);
for (auto i: m_myKeys)
- if (m_client->state().balance(i.address()) >= totalReq)
+ if (ethereum()->balanceAt(i.address()) >= totalReq)
{
Secret s = i.secret();
- m_executiveState = state();
+ m_executiveState = ethereum()->postState();
m_currentExecution = unique_ptr(new Executive(m_executiveState));
Transaction t;
- t.nonce = m_executiveState.transactionsFrom(toAddress(s));
+ t.nonce = m_executiveState.transactionsFrom(dev::toAddress(s));
t.value = value();
t.gasPrice = gasPrice();
t.gas = ui->gas->value();
@@ -1357,7 +1572,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()));
}
@@ -1371,15 +1586,17 @@ void Main::on_create_triggered()
void Main::on_debugStep_triggered()
{
- auto l = m_history[ui->debugTimeline->value()].levels.size();
- if (ui->debugTimeline->value() < m_history.size() && m_history[ui->debugTimeline->value() + 1].levels.size() > l)
- {
- on_debugStepInto_triggered();
- if (m_history[ui->debugTimeline->value()].levels.size() > l)
- on_debugStepOut_triggered();
+ if (ui->debugTimeline->value() < m_history.size()) {
+ auto l = m_history[ui->debugTimeline->value()].levels.size();
+ if ((ui->debugTimeline->value() + 1) < m_history.size() && m_history[ui->debugTimeline->value() + 1].levels.size() > l)
+ {
+ on_debugStepInto_triggered();
+ if (m_history[ui->debugTimeline->value()].levels.size() > l)
+ on_debugStepOut_triggered();
+ }
+ else
+ on_debugStepInto_triggered();
}
- else
- on_debugStepInto_triggered();
}
void Main::on_debugStepInto_triggered()
@@ -1437,7 +1654,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()
@@ -1450,11 +1667,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 << " : " << c_instructionInfo.at(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";
}
}
@@ -1467,8 +1684,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;
}
}
@@ -1526,16 +1743,16 @@ 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;
ostringstream s;
if (!(_n >> 64))
- s << "0x" << (uint64_t)_n << "";
+ s << "" << (uint64_t)_n << " (0x" << hex << (uint64_t)_n << ")";
else if (!~(_n >> 64))
- s << "0x" << (int64_t)_n << "";
- else if (_n >> 200 == 0)
+ s << "" << (int64_t)_n << " (0x" << hex << (int64_t)_n << ")";
+ else if ((_n >> 200) == 0)
{
Address a = right160(_n);
QString n = pretty(a);
@@ -1570,7 +1787,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
");
@@ -1580,7 +1797,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("");
@@ -1603,7 +1820,7 @@ void Main::updateDebugger()
ostringstream out;
out << s.cur.abridged();
if (i)
- out << " " << c_instructionInfo.at(s.inst).name << " @0x" << hex << s.curPC;
+ out << " " << instructionInfo(s.inst).name << " @0x" << hex << s.curPC;
ui->callStack->addItem(QString::fromStdString(out.str()));
}
}
@@ -1619,7 +1836,7 @@ void Main::updateDebugger()
byte b = i < code.size() ? code[i] : 0;
try
{
- QString s = c_instructionInfo.at((Instruction)b).name;
+ QString s = QString::fromStdString(instructionInfo((Instruction)b).name);
ostringstream out;
out << hex << setw(4) << setfill('0') << i;
m_pcWarp[i] = dc->count();
@@ -1645,7 +1862,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("");
@@ -1655,7 +1872,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)
@@ -1669,7 +1886,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 << " : " << c_instructionInfo.at(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)
@@ -1689,4 +1906,7 @@ void Main::updateDebugger()
#include\
"moc_MiningView.cpp"
+#include\
+"moc_DownloadView.cpp"
+
#endif
diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h
index 99b337a20..ce1a9b670 100644
--- a/alethzero/MainWin.h
+++ b/alethzero/MainWin.h
@@ -27,36 +27,38 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
+#include
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;
- unsigned newMemSize;
- eth::u256 gas;
- eth::h256 code;
- eth::h256 callData;
- eth::u256s stack;
- eth::bytes memory;
- eth::bigint gasCost;
- std::map storage;
+ dev::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;
};
@@ -68,9 +70,11 @@ public:
explicit Main(QWidget *parent = 0);
~Main();
- eth::Client* client() { return m_client.get(); }
+ dev::WebThreeDirect* web3() const { return m_webThree.get(); }
+ dev::eth::Client* ethereum() const { return m_webThree->ethereum(); }
+ dev::shh::WhisperHost* whisper() const { return m_webThree->whisper(); }
- QList const& owned() const { return m_myKeys; }
+ QList const& owned() const { return m_myKeys; }
public slots:
void load(QString _file);
@@ -78,6 +82,8 @@ public slots:
void debug(QString _entry);
void warn(QString _entry);
+ void onKeysChanged();
+
private slots:
void eval(QString const& _js);
@@ -106,7 +112,7 @@ private slots:
void on_about_triggered();
void on_paranoia_triggered();
void on_nameReg_textChanged();
- void on_preview_triggered() { refresh(true); }
+ void on_preview_triggered();
void on_quit_triggered() { close(); }
void on_urlEdit_returnPressed();
void on_debugStep_triggered();
@@ -118,11 +124,11 @@ private slots:
void on_importKey_triggered();
void on_exportKey_triggered();
void on_inject_triggered();
- void on_showAll_triggered() { refresh(true); }
- void on_showAllAccounts_triggered() { refresh(true); }
+ void on_showAll_triggered() { refreshBlockChain(); }
+ void on_showAllAccounts_triggered() { refreshAccounts(); }
void on_loadJS_triggered();
void on_blockChainFilter_textChanged();
- void on_clearPending_triggered();
+ void on_forceMining_triggered();
void on_dumpTrace_triggered();
void on_dumpTraceStorage_triggered();
void on_dumpTracePretty_triggered();
@@ -134,73 +140,105 @@ private slots:
void on_debugCurrent_triggered();
void on_debugDumpState_triggered(int _add = 1);
void on_debugDumpStatePre_triggered();
-
- void refresh(bool _override = false);
- void refreshNetwork();
- void refreshMining();
- void refreshBlockChain();
+ void on_refresh_triggered();
+ void on_usePrivate_triggered();
+ void on_enableOptimizer_triggered();
+ void on_turboMining_triggered();
signals:
- void changed(); // TODO: manifest
+ void poll();
private:
- void updateBlockCount();
+ dev::p2p::NetworkPreferences netPrefs() const;
+
+ QString pretty(dev::Address _a) const;
+ QString prettyU256(dev::u256 _n) const;
- QString pretty(eth::Address _a) const;
- QString prettyU256(eth::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::Address _a) const;
+ dev::Address fromString(QString const& _a) const;
+ std::string renderDiff(dev::eth::StateDiff const& _d) const;
void alterDebugStateGroup(bool _enable) const;
- eth::State const& state() const;
-
void updateFee();
- void readSettings();
+ void readSettings(bool _skipGeometry = false);
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(dev::eth::MessageFilter const& _tf, std::function const& _f);
+ unsigned installWatch(dev::h256 _tf, std::function const& _f);
+
+ void onNewPending();
+ void onNewBlock();
+ void onNameRegChange();
+ void onCurrenciesChange();
+ void onBalancesChange();
+
+ void installWatches();
+ void installCurrenciesWatch();
+ void installNameRegWatch();
+ void installBalancesWatch();
+
+ virtual void timerEvent(QTimerEvent*);
+
+ void refreshNetwork();
+ void refreshMining();
+
+ void refreshAll();
+ void refreshPending();
+ void refreshAccounts();
+ void refreshDestination();
+ void refreshBlockChain();
+ void refreshBlockCount();
+ void refreshBalances();
std::unique_ptr ui;
- std::unique_ptr m_client;
+ std::unique_ptr m_webThree;
+
+ std::map> m_handlers;
+ unsigned m_nameRegFilter = (unsigned)-1;
+ unsigned m_currenciesFilter = (unsigned)-1;
+ unsigned m_balancesFilter = (unsigned)-1;
QByteArray m_peers;
- QMutex m_guiLock;
- QTimer* m_refresh;
- QTimer* m_refreshNetwork;
- QTimer* m_refreshMining;
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::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;
QList> m_consoleHistory;
+ QMutex m_logLock;
+ QString m_logHistory;
+ bool m_logChanged = true;
- QEthereum* m_ethereum;
+ QEthereum* m_ethereum = nullptr;
};
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 1b4a91b9a..8f3135f75 100644
--- a/alethzero/MiningView.h
+++ b/alethzero/MiningView.h
@@ -27,12 +27,13 @@
#include
#include
+#ifndef Q_MOC_RUN
#include
+#endif
-namespace eth
-{
+namespace dev { namespace eth {
struct MineInfo;
-}
+}}
class MiningView: public QWidget
{
@@ -41,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/CMakeLists.txt b/eth/CMakeLists.txt
index 93946aa8f..eee1d258b 100644
--- a/eth/CMakeLists.txt
+++ b/eth/CMakeLists.txt
@@ -4,13 +4,13 @@ aux_source_directory(. SRC_LIST)
include_directories(..)
link_directories(../libethcore)
-link_directories(../libethereum)
+link_directories(../libwebthree)
set(EXECUTABLE eth)
add_executable(${EXECUTABLE} ${SRC_LIST})
-target_link_libraries(${EXECUTABLE} ethereum)
+target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} secp256k1)
target_link_libraries(${EXECUTABLE} gmp)
if(MINIUPNPC_LS)
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..caa7e6651 100644
--- a/eth/CommonJS.h
+++ b/eth/CommonJS.h
@@ -23,66 +23,69 @@
#pragma once
#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#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 0d5182eb8..ad6a87781 100644
--- a/eth/EthStubServer.cpp
+++ b/eth/EthStubServer.cpp
@@ -25,13 +25,15 @@
#include
#include
#include
+#include
#include "CommonJS.h"
using namespace std;
-using namespace eth;
+using namespace dev;
+using namespace dev::eth;
-EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, Client& _client):
+EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3):
AbstractEthStubServer(_conn),
- m_client(_client)
+ m_web3(_web3)
{
}
@@ -58,40 +60,43 @@ Json::Value EthStubServer::procedures()
return ret;
}
+dev::eth::Client& EthStubServer::ethereum() const
+{
+ return *m_web3.ethereum();
+}
+
std::string EthStubServer::coinbase()
{
- ClientGuard g(&m_client);
- return toJS(m_client.address());
+ return toJS(ethereum().address());
}
std::string EthStubServer::balanceAt(std::string const& _a)
{
- ClientGuard g(&m_client);
- return toJS(m_client.postState().balance(jsToAddress(_a)));
+ return toJS(ethereum().balanceAt(jsToAddress(_a), 0));
}
Json::Value EthStubServer::check(Json::Value const& _as)
{
- if (m_client.changed())
+ // TODO
+// if (ethereum().changed())
return _as;
- else
+/* else
{
Json::Value ret;
ret.resize(0);
return ret;
- }
+ }*/
}
std::string EthStubServer::create(const std::string& _bCode, const std::string& _sec, const std::string& _xEndowment, const std::string& _xGas, const std::string& _xGasPrice)
{
- ClientGuard g(&m_client);
- Address ret = m_client.transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
+ Address ret = ethereum().transact(jsToSecret(_sec), jsToU256(_xEndowment), jsToBytes(_bCode), jsToU256(_xGas), jsToU256(_xGasPrice));
return toJS(ret);
}
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()
@@ -101,18 +106,17 @@ std::string EthStubServer::gasPrice()
bool EthStubServer::isContractAt(const std::string& _a)
{
- ClientGuard g(&m_client);
- return m_client.postState().addressHasCode(jsToAddress(_a));
+ return ethereum().codeAt(jsToAddress(_a), 0).size();
}
bool EthStubServer::isListening()
{
- return m_client.haveNetwork();
+ return m_web3.haveNetwork();
}
bool EthStubServer::isMining()
{
- return m_client.isMining();
+ return ethereum().isMining();
}
std::string EthStubServer::key()
@@ -132,27 +136,28 @@ Json::Value EthStubServer::keys()
int EthStubServer::peerCount()
{
- ClientGuard g(&m_client);
- return m_client.peerCount();
+ return m_web3.peerCount();
}
std::string EthStubServer::storageAt(const std::string& _a, const std::string& x)
{
- ClientGuard g(&m_client);
- return toJS(m_client.postState().storage(jsToAddress(_a), jsToU256(x)));
+ return toJS(ethereum().stateAt(jsToAddress(_a), jsToU256(x), 0));
+}
+
+std::string EthStubServer::stateAt(const std::string& _a, const std::string& x, const std::string& s)
+{
+ return toJS(ethereum().stateAt(jsToAddress(_a), jsToU256(x), std::atol(s.c_str())));
}
Json::Value EthStubServer::transact(const std::string& _aDest, const std::string& _bData, const std::string& _sec, const std::string& _xGas, const std::string& _xGasPrice, const std::string& _xValue)
{
- ClientGuard g(&m_client);
- m_client.transact(jsToSecret(_sec), jsToU256(_xValue), jsToAddress(_aDest), jsToBytes(_bData), jsToU256(_xGas), jsToU256(_xGasPrice));
+ ethereum().transact(jsToSecret(_sec), jsToU256(_xValue), jsToAddress(_aDest), jsToBytes(_bData), jsToU256(_xGas), jsToU256(_xGasPrice));
return Json::Value();
}
std::string EthStubServer::txCountAt(const std::string& _a)
{
- ClientGuard g(&m_client);
- return toJS(m_client.postState().transactionsFrom(jsToAddress(_a)));
+ return toJS(ethereum().countAt(jsToAddress(_a), 0));
}
std::string EthStubServer::secretToAddress(const std::string& _a)
@@ -173,7 +178,7 @@ Json::Value EthStubServer::block(const std::string& _hash)
Json::Value EthStubServer::blockJson(const std::string& _hash)
{
Json::Value res;
- auto const& bc = m_client.blockChain();
+ auto const& bc = ethereum().blockChain();
auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block();
diff --git a/eth/EthStubServer.h b/eth/EthStubServer.h
index bd7041d3d..469abed07 100644
--- a/eth/EthStubServer.h
+++ b/eth/EthStubServer.h
@@ -23,18 +23,18 @@
#include
#include
+#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "abstractethstubserver.h"
#pragma GCC diagnostic pop
-namespace eth { class Client; }
-namespace eth { class KeyPair; }
+namespace dev { class WebThreeDirect; namespace eth { class Client; } class KeyPair; }
class EthStubServer: public AbstractEthStubServer
{
public:
- EthStubServer(jsonrpc::AbstractServerConnector* _conn, eth::Client& _client);
+ EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual Json::Value procedures();
virtual std::string balanceAt(std::string const& _a);
@@ -49,16 +49,18 @@ public:
virtual Json::Value keys();
virtual int peerCount();
virtual std::string storageAt(const std::string& a, const std::string& x);
+ virtual std::string stateAt(const std::string& a, const std::string& x, const std::string& s);
virtual Json::Value transact(const std::string& aDest, const std::string& bData, const std::string& sec, const std::string& xGas, const std::string& xGasPrice, const std::string& xValue);
virtual std::string txCountAt(const std::string& a);
virtual std::string secretToAddress(const std::string& a);
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& ethereum() const;
+ dev::WebThreeDirect& m_web3;
+ std::vector m_keys;
Json::Value jsontypeToValue(int);
Json::Value blockJson(const std::string&);
};
diff --git a/eth/abstractethstubserver.h b/eth/abstractethstubserver.h
index 940e4c809..7f110513d 100644
--- a/eth/abstractethstubserver.h
+++ b/eth/abstractethstubserver.h
@@ -30,6 +30,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerbindAndAddMethod(new jsonrpc::Procedure("procedures", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::proceduresI);
this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI);
this->bindAndAddMethod(new jsonrpc::Procedure("storageAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::storageAtI);
+ this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "aDest",jsonrpc::JSON_STRING,"bData",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING,"xValue",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::transactI);
this->bindAndAddMethod(new jsonrpc::Procedure("txCountAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::txCountAtI);
@@ -120,6 +121,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerstorageAt(request["a"].asString(), request["x"].asString());
}
+ inline virtual void stateAtI(const Json::Value& request, Json::Value& response)
+ {
+ response = this->stateAt(request["a"].asString(), request["x"].asString(), request["s"].asString());
+ }
+
inline virtual void transactI(const Json::Value& request, Json::Value& response)
{
response = this->transact(request["aDest"].asString(), request["bData"].asString(), request["sec"].asString(), request["xGas"].asString(), request["xGasPrice"].asString(), request["xValue"].asString());
@@ -148,6 +154,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer
#endif
-#include
+#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
#if ETH_READLINE
#include
#include
@@ -46,10 +43,13 @@
#endif
#include "BuildInfo.h"
using namespace std;
-using namespace eth;
+using namespace dev;
+using namespace dev::p2p;
+using namespace dev::eth;
using namespace boost::algorithm;
-using eth::Instruction;
-using eth::c_instructionInfo;
+using dev::eth::Instruction;
+
+#undef RETURN
bool isTrue(std::string const& _m)
{
@@ -73,6 +73,7 @@ void interactiveHelp()
<< " verbosity () Gets or sets verbosity level." << endl
<< " minestart Starts mining." << endl
<< " minestop Stops mining." << endl
+ << " mineforce Forces mining, even when there are no transactions." << endl
<< " address Gives the current address." << endl
<< " secret Gives the current secret" << endl
<< " block Gives the current block height." << endl
@@ -81,13 +82,14 @@ void interactiveHelp()
<< " send Execute a given transaction with current secret." << endl
<< " contract Create a new contract with current secret." << endl
<< " peers List the peers that are connected" << endl
- << " listAccounts List the accounts on the network." << endl
- << " listContracts List the contracts on the network." << endl
- << " setSecret Set the secret to the hex secret key." < Set the coinbase (mining payout) address." < Export the config (.RLP) to the path provided." < Import the config (.RLP) from the path provided." < Dumps a contract to /.evm." << endl
+ << " listAccounts List the accounts on the network." << endl
+ << " listContracts List the contracts on the network." << endl
+ << " setSecret Set the secret to the hex secret key." < Set the coinbase (mining payout) address." < Export the config (.RLP) to the path provided." < Import the config (.RLP) from the path provided." < Dumps a contract to /.evm." << endl
+ << " dumptrace Dumps a transaction trace" << endl << "to . should be one of pretty, standard, standard+." << endl
<< " exit Exits the application." << endl;
}
@@ -97,10 +99,12 @@ void help()
<< "Usage eth [OPTIONS] " << endl
<< "Options:" << endl
<< " -a,--address Set the coinbase (mining payout) address to addr (default: auto)." << endl
+ << " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
<< " -c,--client-name Add a name to your client's version string (default: blank)." << endl
<< " -d,--db-path Load database from path (default: ~/.ethereum " << endl
<< " /Etherum or Library/Application Support/Ethereum)." << endl
- << " -h,--help Show this help message and exit." << endl
+ << " -f,--force-mining Mine even when there are no transaction to mine (Default: off)" << endl
+ << " -h,--help Show this help message and exit." << endl
<< " -i,--interactive Enter interactive mode (default: non-interactive)." << endl
#if ETH_JSONRPC
<< " -j,--json-rpc Enable JSON-RPC server (default: off)." << endl
@@ -108,8 +112,9 @@ void help()
#endif
<< " -l,--listen Listen on the given port for incoming connected (default: 30303)." << endl
<< " -m,--mining Enable mining, optionally for a specified number of blocks (Default: off)" << endl
- << " -n,--upnp Use upnp for NAT (default: on)." << endl
- << " -o,--mode Start a full node or a peer node (Default: full)." << endl
+ << " -n,--upnp Use upnp for NAT (default: on)." << endl
+ << " -L,--local-networking Use peers whose addresses are local." << endl
+ << " -o,--mode Start a full node or a peer node (Default: full)." << endl
<< " -p,--port Connect to remote port (default: 30303)." << endl
<< " -r,--remote Connect to remote host (default: none)." << endl
<< " -s,--secret Set the secret key for use with send command (default: auto)." << endl
@@ -124,23 +129,14 @@ 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);
- vs = vs.substr(vs.find_first_of('.') + 1)[0];
- int pocnumber = stoi(vs);
- string m_servers;
- if (pocnumber == 4)
- m_servers = "54.72.31.55";
- else
- m_servers = "54.72.69.180";
-
cout << "Type 'netstart 30303' to start networking" << endl;
- cout << "Type 'connect " << m_servers << " 30303' to connect" << endl;
+ cout << "Type 'connect " << Host::pocHost() << " 30303' to connect" << endl;
cout << "Type 'exit' to quit" << endl << endl;
}
return cout.str();
@@ -148,13 +144,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;
@@ -169,22 +165,25 @@ string pretty(h160 _a, eth::State _st)
}
return ns;
}
-bytes parse_data(string _args);
+
int main(int argc, char** argv)
{
unsigned short listenPort = 30303;
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;
#if ETH_JSONRPC
- int jsonrpc = 8080;
+ int jsonrpc = -1;
#endif
string publicIP;
+ bool bootstrap = false;
bool upnp = true;
+ bool useLocal = false;
+ bool forceMining = false;
string clientName;
// Init defaults
@@ -229,10 +228,12 @@ int main(int argc, char** argv)
upnp = false;
else
{
- cerr << "Invalid UPnP option: " << m << endl;
+ cerr << "Invalid -n/--upnp option: " << m << endl;
return -1;
}
}
+ else if (arg == "-L" || arg == "--local-networking")
+ useLocal = true;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
@@ -245,22 +246,26 @@ 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))
mining = i;
else
{
- cerr << "Unknown mining option: " << m << endl;
+ cerr << "Unknown -m/--mining option: " << m << endl;
return -1;
}
}
+ else if (arg == "-b" || arg == "--bootstrap")
+ bootstrap = true;
+ else if (arg == "-f" || arg == "--force-mining")
+ forceMining = true;
else if (arg == "-i" || arg == "--interactive")
interactive = true;
#if ETH_JSONRPC
else if ((arg == "-j" || arg == "--json-rpc"))
- jsonrpc = jsonrpc ? jsonrpc : 8080;
+ jsonrpc = jsonrpc == -1 ? 8080 : jsonrpc;
else if (arg == "--json-rpc-port" && i + 1 < argc)
jsonrpc = atoi(argv[++i]);
#endif
@@ -291,18 +296,33 @@ 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);
- c.start();
+
cout << credits();
+ NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
+ dev::WebThreeDirect web3("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), dbPath, false, mode == NodeMode::Full ? set{"eth", "shh"} : set{}, netPrefs);
+ web3.setIdealPeerCount(peers);
+ eth::Client* c = mode == NodeMode::Full ? web3.ethereum() : nullptr;
+
+ if (c)
+ {
+ c->setForceMining(forceMining);
+ c->setAddress(coinbase);
+ }
+
cout << "Address: " << endl << toHex(us.address().asArray()) << endl;
- c.startNetwork(listenPort, remoteHost, remotePort, mode, peers, publicIP, upnp);
+ web3.startNetwork();
+
+ if (bootstrap)
+ web3.connect(Host::pocHost());
+ if (remoteHost.size())
+ web3.connect(remoteHost, remotePort);
#if ETH_JSONRPC
auto_ptr jsonrpcServer;
if (jsonrpc > -1)
{
- jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), c));
+ jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@@ -310,9 +330,16 @@ int main(int argc, char** argv)
if (interactive)
{
+ string logbuf;
string l;
while (true)
{
+ g_logPost = [](std::string const& a, char const*) { cout << "\r \r" << a << endl << "Press Enter" << flush; };
+ cout << logbuf << "Press Enter" << flush;
+ std::getline(cin, l);
+ logbuf.clear();
+ g_logPost = [&](std::string const& a, char const*) { logbuf += a + "\n"; };
+
#if ETH_READLINE
if (l.size())
add_history(l.c_str());
@@ -333,31 +360,34 @@ int main(int argc, char** argv)
iss >> cmd;
if (cmd == "netstart")
{
- eth::uint port;
- iss >> port;
- ClientGuard g(&c);
- c.startNetwork((short)port);
+ iss >> netPrefs.listenPort;
+ web3.setNetworkPreferences(netPrefs);
+ web3.startNetwork();
}
else if (cmd == "connect")
{
string addr;
- eth::uint port;
+ unsigned port;
iss >> addr >> port;
- ClientGuard g(&c);
- c.connect(addr, (short)port);
+ web3.connect(addr, (short)port);
}
else if (cmd == "netstop")
{
- ClientGuard g(&c);
- c.stopNetwork();
+ web3.stopNetwork();
+ }
+ else if (c && cmd == "minestart")
+ {
+ c->startMining();
}
- else if (cmd == "minestart")
+ else if (c && cmd == "minestop")
{
- c.startMining();
+ c->stopMining();
}
- else if (cmd == "minestop")
+ else if (c && cmd == "mineforce")
{
- c.stopMining();
+ string enable;
+ iss >> enable;
+ c->setForceMining(isTrue(enable));
}
else if (cmd == "verbosity")
{
@@ -376,7 +406,7 @@ int main(int argc, char** argv)
{
if (jsonrpc < 0)
jsonrpc = 8080;
- jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), c));
+ jsonrpcServer = auto_ptr(new EthStubServer(new jsonrpc::HttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@@ -397,28 +427,24 @@ int main(int argc, char** argv)
{
cout << "Secret Key: " << toHex(us.secret().asArray()) << endl;
}
- else if (cmd == "block")
+ else if (c && cmd == "block")
{
- ClientGuard g(&c);
- cout << "Current block: " << c.blockChain().details().number;
+ cout << "Current block: " <blockChain().details().number << endl;
}
else if (cmd == "peers")
{
- ClientGuard g(&c);
- for (auto it: c.peers())
+ for (auto it: web3.peers())
cout << it.host << ":" << it.port << ", " << it.clientVersion << ", "
<< std::chrono::duration_cast(it.lastPing).count() << "ms"
<< endl;
}
- else if (cmd == "balance")
+ else if (c && cmd == "balance")
{
- ClientGuard g(&c);
- cout << "Current balance: " << formatBalance(c.postState().balance(us.address())) << " = " << c.postState().balance(us.address()) << " wei" << endl;
+ cout << "Current balance: " << formatBalance( c->balanceAt(us.address())) << " = " <balanceAt(us.address()) << " wei" << endl;
}
- else if (cmd == "transact")
+ else if (c && cmd == "transact")
{
- ClientGuard g(&c);
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
@@ -435,7 +461,7 @@ int main(int argc, char** argv)
cnote << "Data:";
cnote << sdata;
- bytes data = parse_data(sdata);
+ bytes data = dev::eth::parseData(sdata);
cnote << "Bytes:";
string sbd = asString(data);
bytes bbd = asBytes(sbd);
@@ -444,16 +470,16 @@ int main(int argc, char** argv)
cnote << ssbd.str();
int ssize = sechex.length();
int size = hexAddr.length();
- u256 minGas = (u256)c.state().callGas(data.size(), 0);
+ u256 minGas = (u256)Client::txGas(data.size(), 0);
if (size < 40)
{
if (size > 0)
- cwarn << "Invalid address length: " << size;
+ cwarn << "Invalid address length:" << size;
}
else if (gasPrice < info.minGasPrice)
- cwarn << "Minimum gas price is " << info.minGasPrice;
+ cwarn << "Minimum gas price is" << info.minGasPrice;
else if (gas < minGas)
- cwarn << "Minimum gas amount is " << minGas;
+ cwarn << "Minimum gas amount is" << minGas;
else if (ssize < 40)
{
if (ssize > 0)
@@ -463,48 +489,36 @@ int main(int argc, char** argv)
{
Secret secret = h256(fromHex(sechex));
Address dest = h160(fromHex(hexAddr));
- c.transact(secret, amount, dest, data, gas, gasPrice);
+ c->transact(secret, amount, dest, data, gas, gasPrice);
}
}
else
cwarn << "Require parameters: transact ADDRESS AMOUNT GASPRICE GAS SECRET DATA";
}
- else if (cmd == "listContracts")
+ else if (c && cmd == "listContracts")
{
- ClientGuard g(&c);
- auto const& st = c.state();
- auto acs = st.addresses();
+ auto acs =c->addresses();
string ss;
for (auto const& i: acs)
- {
- auto r = i.first;
- if (st.addressHasCode(r))
+ if ( c->codeAt(i, 0).size())
{
- ss = toString(r) + " : " + toString(formatBalance(i.second)) + " [" + toString((unsigned)st.transactionsFrom(i.first)) + "]";
+ ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl;
}
- }
}
- else if (cmd == "listAccounts")
+ else if (c && cmd == "listAccounts")
{
- ClientGuard g(&c);
- auto const& st = c.state();
- auto acs = st.addresses();
+ auto acs =c->addresses();
string ss;
for (auto const& i: acs)
- {
- auto r = i.first;
- if (!st.addressHasCode(r))
+ if ( c->codeAt(i, 0).empty())
{
- ss = toString(r) + pretty(r, st) + " : " + toString(formatBalance(i.second)) + " [" + toString((unsigned)st.transactionsFrom(i.first)) + "]";
+ ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl;
}
-
- }
}
- else if (cmd == "send")
+ else if (c && cmd == "send")
{
- ClientGuard g(&c);
if (iss.peek() != -1)
{
string hexAddr;
@@ -515,31 +529,30 @@ int main(int argc, char** argv)
if (size < 40)
{
if (size > 0)
- cwarn << "Invalid address length: " << size;
+ cwarn << "Invalid address length:" << size;
}
else
{
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
- u256 minGas = (u256)c.state().callGas(0, 0);
+ u256 minGas = (u256)Client::txGas(0, 0);
Address dest = h160(fromHex(hexAddr));
- c.transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice);
+ c->transact(us.secret(), amount, dest, bytes(), minGas, info.minGasPrice);
}
-
}
else
cwarn << "Require parameters: send ADDRESS AMOUNT";
}
- else if (cmd == "contract")
+ else if (c && cmd == "contract")
{
- ClientGuard g(&c);
- auto const& bc = c.blockChain();
+ auto const& bc =c->blockChain();
auto h = bc.currentHash();
auto blockData = bc.block(h);
BlockInfo info(blockData);
- if(iss.peek() != -1) {
+ if (iss.peek() != -1)
+ {
u256 endowment;
u256 gas;
u256 gasPrice;
@@ -550,7 +563,7 @@ int main(int argc, char** argv)
bytes init;
cnote << "Init:";
cnote << sinit;
- cnote << "Code size: " << size;
+ cnote << "Code size:" << size;
if (size < 1)
cwarn << "No code submitted";
else
@@ -563,20 +576,75 @@ int main(int argc, char** argv)
cnote << "Init:";
cnote << ssc.str();
}
- u256 minGas = (u256)c.state().createGas(init.size(), 0);
+ u256 minGas = (u256)Client::txGas(init.size(), 0);
if (endowment < 0)
cwarn << "Invalid endowment";
else if (gasPrice < info.minGasPrice)
- cwarn << "Minimum gas price is " << info.minGasPrice;
+ cwarn << "Minimum gas price is" << info.minGasPrice;
else if (gas < minGas)
- cwarn << "Minimum gas amount is " << minGas;
+ cwarn << "Minimum gas amount is" << minGas;
else
- c.transact(us.secret(), endowment, init, gas, gasPrice);
+ c->transact(us.secret(), endowment, init, gas, gasPrice);
}
else
cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX";
}
- else if (cmd == "inspect")
+ else if (c && cmd == "dumptrace")
+ {
+ unsigned block;
+ unsigned index;
+ string filename;
+ string format;
+ iss >> block >> index >> filename >> format;
+ ofstream f;
+ f.open(filename);
+
+ dev::eth::State state =c->state(index + 1,c->blockChain().numberHash(block));
+ if (index < state.pending().size())
+ {
+ Executive e(state);
+ Transaction t = state.pending()[index];
+ state = state.fromPending(index);
+ bytes r = t.rlp();
+ e.setup(&r);
+
+ OnOpFunc oof;
+ if (format == "pretty")
+ oof = [&](uint64_t steps, Instruction instr, bigint newMemSize, bigint gasCost, void* vvm, void 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 << 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() << " : " << 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)
+ {
+ 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)
+ {
+ 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(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);
+ }
+ }
+ else if (c && cmd == "inspect")
{
string rechex;
iss >> rechex;
@@ -585,20 +653,28 @@ int main(int argc, char** argv)
cwarn << "Invalid address length";
else
{
- ClientGuard g(&c);
auto h = h160(fromHex(rechex));
stringstream s;
- auto mem = c.state().storage(h);
- for (auto const& i: mem)
- s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl;
- s << endl << disassemble(c.state().code(h));
+ try
+ {
+ auto storage =c->storageAt(h, 0);
+ for (auto const& i: storage)
+ s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl;
+ s << endl << disassemble( c->codeAt(h, 0)) << endl;
+
+ string outFile = getDataDir() + "/" + rechex + ".evm";
+ ofstream ofs;
+ ofs.open(outFile, ofstream::binary);
+ ofs.write(s.str().c_str(), s.str().length());
+ ofs.close();
- string outFile = getDataDir() + "/" + rechex + ".evm";
- ofstream ofs;
- ofs.open(outFile, ofstream::binary);
- ofs.write(s.str().c_str(), s.str().length());
- ofs.close();
+ cnote << "Saved" << rechex << "to" << outFile;
+ }
+ catch (dev::eth::InvalidTrie)
+ {
+ cwarn << "Corrupted trie.";
+ }
}
}
else if (cmd == "setSecret")
@@ -670,75 +746,22 @@ int main(int argc, char** argv)
jsonrpcServer->StopListening();
#endif
}
- else
+ else if (c)
{
- eth::uint n = c.blockChain().details().number;
+ unsigned n =c->blockChain().details().number;
if (mining)
- c.startMining();
+ c->startMining();
while (true)
{
- if (c.blockChain().details().number - n == mining)
- c.stopMining();
+ if ( c->isMining() &&c->blockChain().details().number - n == mining)
+ c->stopMining();
this_thread::sleep_for(chrono::milliseconds(100));
}
}
-
+ else
+ while (true)
+ this_thread::sleep_for(chrono::milliseconds(1000));
return 0;
}
-bytes parse_data(string _args)
-{
- bytes m_data;
- stringstream args(_args);
- string arg;
- int cc = 0;
- while (args >> arg)
- {
- int al = arg.length();
- if (boost::starts_with(arg, "0x"))
- {
- bytes bs = fromHex(arg);
- m_data += bs;
- }
- else if (arg[0] == '@')
- {
- arg = arg.substr(1, arg.length());
- if (boost::starts_with(arg, "0x"))
- {
- cnote << "hex: " << arg;
- bytes bs = fromHex(arg);
- int size = bs.size();
- if (size < 32)
- for (auto i = 0; i < 32 - size; ++i)
- m_data.push_back(0);
- m_data += bs;
- }
- else if (boost::starts_with(arg, "\"") && boost::ends_with(arg, "\""))
- {
- arg = arg.substr(1, arg.length() - 2);
- cnote << "string: " << arg;
- if (al < 32)
- for (int i = 0; i < 32 - al; ++i)
- m_data.push_back(0);
- for (int i = 0; i < al; ++i)
- m_data.push_back(arg[i]);
- }
- else
- {
- cnote << "value: " << arg;
- bytes bs = toBigEndian(u256(arg));
- int size = bs.size();
- if (size < 32)
- for (auto i = 0; i < 32 - size; ++i)
- m_data.push_back(0);
- m_data += bs;
- }
- }
- else
- for (int i = 0; i < al; ++i)
- m_data.push_back(arg[i]);
- cc++;
- }
- return m_data;
-}
diff --git a/exp/CMakeLists.txt b/exp/CMakeLists.txt
index 5b76b4c7a..da6775798 100644
--- a/exp/CMakeLists.txt
+++ b/exp/CMakeLists.txt
@@ -9,6 +9,7 @@ set(EXECUTABLE exp)
add_executable(${EXECUTABLE} ${SRC_LIST})
target_link_libraries(${EXECUTABLE} ethereum)
+target_link_libraries(${EXECUTABLE} p2p)
target_link_libraries(${EXECUTABLE} gmp)
target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS})
if(MINIUPNPC_LS)
diff --git a/exp/main.cpp b/exp/main.cpp
index 6a5e5557f..1f29ab207 100644
--- a/exp/main.cpp
+++ b/exp/main.cpp
@@ -19,26 +19,97 @@
* @date 2014
* Ethereum client.
*/
-
-#include
-#include
-#include
-#include "BuildInfo.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace std;
-using namespace eth;
+using namespace dev;
+using namespace dev::eth;
+using namespace dev::p2p;
+using namespace dev::shh;
+
+int main()
+{
+ DownloadMan man;
+ DownloadSub s0(man);
+ DownloadSub s1(man);
+ DownloadSub s2(man);
+ man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)}));
+ cnote << s0.nextFetch(2);
+ cnote << s1.nextFetch(2);
+ cnote << s2.nextFetch(2);
+ s0.noteBlock(u256(0));
+ s0.doneFetch();
+ cnote << s0.nextFetch(2);
+ s1.noteBlock(u256(2));
+ s1.noteBlock(u256(3));
+ s1.doneFetch();
+ cnote << s1.nextFetch(2);
+ s0.doneFetch();
+ cnote << s0.nextFetch(2);
+
+/* RangeMask m(0, 100);
+ cnote << m;
+ m += UnsignedRange(3, 10);
+ cnote << m;
+ m += UnsignedRange(11, 16);
+ cnote << m;
+ m += UnsignedRange(10, 11);
+ cnote << m;
+ cnote << ~m;
+ cnote << (~m).lowest(10);
+ for (auto i: (~m).lowest(10))
+ cnote << i;*/
+ return 0;
+}
-int main(int, char**)
+/*
+int main(int argc, char** argv)
{
- u256 z = 0;
- u256 s = 7;
- u256 ms = z - s;
- s256 ams = -7;
- s256 sms = u2s(ms);
- cnote << sms;
- cnote << ams;
- cnote << ms;
- u256 t = 3;
- s256 st = u2s(t);
- cnote << ms << t << (sms % t) << sms << st << (s2u(sms % st) + 70);
+ g_logVerbosity = 20;
+
+ short listenPort = 30303;
+ string remoteHost;
+ short remotePort = 30303;
+
+ for (int i = 1; i < argc; ++i)
+ {
+ string arg = argv[i];
+ if (arg == "-l" && i + 1 < argc)
+ listenPort = (short)atoi(argv[++i]);
+ else if (arg == "-r" && i + 1 < argc)
+ remoteHost = argv[++i];
+ else if (arg == "-p" && i + 1 < argc)
+ remotePort = (short)atoi(argv[++i]);
+ else
+ remoteHost = argv[i];
+ }
+
+ Host ph("Test", NetworkPreferences(listenPort, "", false, true));
+ ph.registerCapability(new WhisperHost());
+ auto wh = ph.cap();
+
+ ph.start();
+
+ if (!remoteHost.empty())
+ ph.connect(remoteHost, remotePort);
+
+ /// Only interested in the packet if the lowest bit is 1
+ auto w = wh->installWatch(MessageFilter(std::vector >({{fromHex("0000000000000000000000000000000000000000000000000000000000000001"), fromHex("0000000000000000000000000000000000000000000000000000000000000001")}})));
+
+
+ for (int i = 0; ; ++i)
+ {
+ wh->sendRaw(h256(u256(i * i)).asBytes(), h256(u256(i)).asBytes(), 1000);
+ for (auto i: wh->checkWatch(w))
+ cnote << "New message:" << (u256)h256(wh->message(i).payload);
+ }
return 0;
}
+*/
diff --git a/iethxi/CMakeLists.txt b/iethxi/CMakeLists.txt
new file mode 100644
index 000000000..fc8edf1dc
--- /dev/null
+++ b/iethxi/CMakeLists.txt
@@ -0,0 +1,117 @@
+cmake_policy(SET CMP0015 NEW)
+
+if ("${TARGET_PLATFORM}" STREQUAL "w64")
+ cmake_policy(SET CMP0020 NEW)
+endif ()
+
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+aux_source_directory(. SRC_LIST)
+
+include_directories(..)
+link_directories(../libethcore)
+link_directories(../libethereum)
+link_directories(../libqethereum)
+
+# Find Qt5 for Apple and update src_list for windows
+if (APPLE)
+ # homebrew defaults to qt4 and installs qt5 as 'keg-only'
+ # which places it into /usr/local/opt insteadof /usr/local.
+
+ set(CMAKE_PREFIX_PATH /usr/local/opt/qt5)
+ include_directories(/usr/local/opt/qt5/include /usr/local/include)
+elseif ("${TARGET_PLATFORM}" STREQUAL "w64")
+ set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp)
+elseif (UNIX)
+ set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";$ENV{QTDIR}/lib/cmake")
+endif ()
+
+
+find_package(Qt5Widgets REQUIRED)
+find_package(Qt5Gui REQUIRED)
+find_package(Qt5Quick REQUIRED)
+find_package(Qt5Qml REQUIRED)
+find_package(Qt5Network REQUIRED)
+qt5_wrap_ui(ui_Main.h Main.ui)
+qt5_add_resources(RESOURCE_ADDED Resources.qrc)
+
+# Set name of binary and add_executable()
+if (APPLE)
+ set(EXECUTEABLE IEthXi)
+ set(CMAKE_INSTALL_PREFIX ./)
+ set(BIN_INSTALL_DIR ".")
+ set(DOC_INSTALL_DIR ".")
+
+ set(PROJECT_VERSION "${ETH_VERSION}")
+ set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
+ set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}")
+ set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
+ set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
+ set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}")
+ set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}")
+ set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTEABLE})
+ include(BundleUtilities)
+
+ add_executable(${EXECUTEABLE} MACOSX_BUNDLE Main.ui ${RESOURCE_ADDED} ${SRC_LIST})
+else ()
+ set(EXECUTEABLE iethxi)
+ add_executable(${EXECUTEABLE} Main.ui ${RESOURCE_ADDED} ${SRC_LIST})
+endif ()
+
+qt5_use_modules(${EXECUTEABLE} Core Gui Widgets Network Quick Qml)
+target_link_libraries(${EXECUTEABLE} qethereum ethereum secp256k1 ${CRYPTOPP_LS})
+
+if (APPLE)
+ if (${ADDFRAMEWORKS})
+ set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in")
+ endif ()
+
+ SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS)
+
+ # This is a workaround for when the build-type defaults to Debug, and when a multi-config generator like xcode is used, where the type
+ # will not be set but defaults to release.
+ set(generator_lowercase "${CMAKE_GENERATOR}")
+ string(TOLOWER "${CMAKE_GENERATOR}" generator_lowercase)
+ if ("${generator_lowercase}" STREQUAL "xcode")
+ # TODO: Not sure how to resolve this. Possibly \${TARGET_BUILD_DIR}
+ set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}/Debug")
+ else ()
+ set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}")
+ endif ()
+
+ set(APPS ${binary_build_dir}/${EXECUTEABLE}.app)
+
+ # This tool and the next will automatically looked at the linked libraries in order to determine what dependencies are required. Thus, target_link_libaries only needs to add ethereum and secp256k1 (above)
+ install(CODE "
+ include(BundleUtilities)
+ set(BU_CHMOD_BUNDLE_ITEMS 1)
+ fixup_bundle(\"${APPS}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\")
+ " COMPONENT RUNTIME )
+
+ if (${ADDFRAMEWORKS})
+ add_custom_target(addframeworks ALL
+ COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTEABLE}.app
+ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ DEPENDS ${PROJECT_NAME}
+ )
+ endif ()
+
+elseif ("${TARGET_PLATFORM}" STREQUAL "w64")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-keep-inline-dllexport -static-libgcc -static-libstdc++ -static")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-subsystem,windows -mthreads -L/usr/x86_64-w64-mingw32/plugins/platforms")
+ target_link_libraries(${EXECUTEABLE} gcc)
+ target_link_libraries(${EXECUTEABLE} mingw32 qtmain mswsock iphlpapi qwindows shlwapi Qt5PlatformSupport gdi32 comdlg32 oleaut32 imm32 winmm ole32 uuid ws2_32)
+ target_link_libraries(${EXECUTEABLE} boost_system-mt-s)
+ target_link_libraries(${EXECUTEABLE} boost_filesystem-mt-s)
+ target_link_libraries(${EXECUTEABLE} boost_thread_win32-mt-s)
+ target_link_libraries(${EXECUTEABLE} Qt5PlatformSupport)
+ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
+elseif (UNIX)
+else ()
+ target_link_libraries(${EXECUTEABLE} boost_system)
+ target_link_libraries(${EXECUTEABLE} boost_filesystem)
+ find_package(Threads REQUIRED)
+ target_link_libraries(${EXECUTEABLE} ${CMAKE_THREAD_LIBS_INIT})
+ install( TARGETS ${EXECUTEABLE} RUNTIME DESTINATION bin )
+endif ()
+
diff --git a/iethxi/EthereumMacOSXBundleInfo.plist.in b/iethxi/EthereumMacOSXBundleInfo.plist.in
new file mode 100644
index 000000000..684ad7908
--- /dev/null
+++ b/iethxi/EthereumMacOSXBundleInfo.plist.in
@@ -0,0 +1,38 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ ${MACOSX_BUNDLE_EXECUTABLE_NAME}
+ CFBundleGetInfoString
+ ${MACOSX_BUNDLE_INFO_STRING}
+ CFBundleIconFile
+ ${MACOSX_BUNDLE_ICON_FILE}
+ CFBundleIdentifier
+ ${MACOSX_BUNDLE_GUI_IDENTIFIER}
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleLongVersionString
+ ${MACOSX_BUNDLE_LONG_VERSION_STRING}
+ CFBundleName
+ ${MACOSX_BUNDLE_BUNDLE_NAME}
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ ${MACOSX_BUNDLE_SHORT_VERSION_STRING}
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ ${MACOSX_BUNDLE_BUNDLE_VERSION}
+ CSResourcesFileMapped
+
+ LSRequiresCarbon
+
+ NSHumanReadableCopyright
+ ${MACOSX_BUNDLE_COPYRIGHT}
+ NSHighResolutionCapable
+
+
+
diff --git a/iethxi/Main.ui b/iethxi/Main.ui
new file mode 100644
index 000000000..fe289ba9f
--- /dev/null
+++ b/iethxi/Main.ui
@@ -0,0 +1,168 @@
+
+
+ Main
+
+
+
+ 0
+ 0
+ 562
+ 488
+
+
+
+ Walleth
+
+
+ true
+
+
+ QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::VerticalTabs
+
+
+ true
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
-
+
+
+ 0 wei
+
+
+
+ -
+
+
+ 0 peers
+
+
+
+ -
+
+
+ 1 block
+
+
+
+
+
+
+
+
+
+
+
+ &Quit
+
+
+
+
+ true
+
+
+ true
+
+
+ Use &UPnP
+
+
+
+
+ &Connect to Peer...
+
+
+
+
+ true
+
+
+ Enable &Network
+
+
+
+
+ true
+
+
+ &Mine
+
+
+
+
+ &New Address
+
+
+
+
+ &About...
+
+
+
+
+ true
+
+
+ &Preview
+
+
+
+
+
+
+
diff --git a/iethxi/MainWin.cpp b/iethxi/MainWin.cpp
new file mode 100644
index 000000000..276ff7630
--- /dev/null
+++ b/iethxi/MainWin.cpp
@@ -0,0 +1,59 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "BuildInfo.h"
+#include "MainWin.h"
+#include "ui_Main.h"
+using namespace std;
+using namespace eth;
+
+Main::Main(QWidget *parent) :
+ QObject(parent)
+{
+/* qRegisterMetaType("eth::u256");
+ qRegisterMetaType("eth::KeyPair");
+ qRegisterMetaType("eth::Secret");
+ qRegisterMetaType("eth::Address");
+ qRegisterMetaType("QmlAccount*");
+ qRegisterMetaType("QmlEthereum*");
+
+ qmlRegisterType("org.ethereum", 1, 0, "Ethereum");
+ qmlRegisterType("org.ethereum", 1, 0, "Account");
+ qmlRegisterSingletonType("org.ethereum", 1, 0, "Balance", QmlEthereum::constructU256Helper);
+ qmlRegisterSingletonType("org.ethereum", 1, 0, "Key", QmlEthereum::constructKeyHelper);
+*/
+ /*
+ ui->librariesView->setModel(m_libraryMan);
+ ui->graphsView->setModel(m_graphMan);
+ */
+
+
+
+
+// QQmlContext* context = m_view->rootContext();
+// context->setContextProperty("u256", new U256Helper(this));
+}
+
+Main::~Main()
+{
+}
+
+// extra bits needed to link on VS
+#ifdef _MSC_VER
+
+// include moc file, ofuscated to hide from automoc
+#include\
+"moc_MainWin.cpp"
+
+#endif
diff --git a/iethxi/MainWin.h b/iethxi/MainWin.h
new file mode 100644
index 000000000..acbea8ca8
--- /dev/null
+++ b/iethxi/MainWin.h
@@ -0,0 +1,18 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+#include
+
+class Main: public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit Main(QWidget *parent = 0);
+ ~Main();
+
+private:
+ QQmlApplicationEngine* m_view;
+};
+
+#endif // MAIN_H
diff --git a/iethxi/Resources.qrc b/iethxi/Resources.qrc
new file mode 100644
index 000000000..1789216ed
--- /dev/null
+++ b/iethxi/Resources.qrc
@@ -0,0 +1,5 @@
+
+
+ Simple.qml
+
+
diff --git a/iethxi/Simple.qml b/iethxi/Simple.qml
new file mode 100644
index 000000000..ac9dc5e37
--- /dev/null
+++ b/iethxi/Simple.qml
@@ -0,0 +1,9 @@
+import QtQuick.Controls 1.1
+
+ApplicationWindow {
+ title: "My App"
+ Button {
+ text: "Push Me"
+ anchors.centerIn: parent
+ }
+}
diff --git a/iethxi/main.cpp b/iethxi/main.cpp
new file mode 100644
index 000000000..569b6d17c
--- /dev/null
+++ b/iethxi/main.cpp
@@ -0,0 +1,9 @@
+#include
+#include
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QQmlApplicationEngine app(QUrl("qrc:/Simple.qml"));
+ return a.exec();
+}
diff --git a/libethential/All.h b/libdevcore/All.h
similarity index 100%
rename from libethential/All.h
rename to libdevcore/All.h
diff --git a/libethential/CMakeLists.txt b/libdevcore/CMakeLists.txt
similarity index 95%
rename from libethential/CMakeLists.txt
rename to libdevcore/CMakeLists.txt
index 139e80ce4..3f3ecb619 100644
--- a/libethential/CMakeLists.txt
+++ b/libdevcore/CMakeLists.txt
@@ -8,7 +8,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB")
aux_source_directory(. SRC_LIST)
-set(EXECUTABLE ethential)
+set(EXECUTABLE devcore)
# set(CMAKE_INSTALL_PREFIX ../lib)
if(ETH_STATIC)
@@ -20,7 +20,7 @@ file(GLOB HEADERS "*.h")
include_directories(..)
-target_link_libraries(${EXECUTABLE} ethential)
+target_link_libraries(${EXECUTABLE} devcore)
if("${TARGET_PLATFORM}" STREQUAL "w64")
include_directories(/usr/x86_64-w64-mingw32/include/cryptopp)
diff --git a/libethential/Common.cpp b/libdevcore/Common.cpp
similarity index 91%
rename from libethential/Common.cpp
rename to libdevcore/Common.cpp
index 7c3d39f93..8312960c1 100644
--- a/libethential/Common.cpp
+++ b/libdevcore/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.5.18";
+char const* Version = "0.6.9";
}
+
diff --git a/libethential/Common.h b/libdevcore/Common.h
similarity index 91%
rename from libethential/Common.h
rename to libdevcore/Common.h
index c06ede0c0..132429010 100644
--- a/libethential/Common.h
+++ b/libdevcore/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/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp
new file mode 100644
index 000000000..6e889a6b0
--- /dev/null
+++ b/libdevcore/CommonData.cpp
@@ -0,0 +1,282 @@
+/*
+ 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 Common.cpp
+ * @author Gav Wood
+ * @date 2014
+ */
+
+#include "CommonData.h"
+
+#include
+#include "Exceptions.h"
+using namespace std;
+using namespace dev;
+
+std::string dev::escaped(std::string const& _s, bool _all)
+{
+ std::string ret;
+ ret.reserve(_s.size());
+ ret.push_back('"');
+ for (auto i: _s)
+ if (i == '"' && !_all)
+ ret += "\\\"";
+ else if (i == '\\' && !_all)
+ ret += "\\\\";
+ else if (i < ' ' || _all)
+ {
+ ret += "\\x";
+ ret.push_back("0123456789abcdef"[(uint8_t)i / 16]);
+ ret.push_back("0123456789abcdef"[(uint8_t)i % 16]);
+ }
+ else
+ ret.push_back(i);
+ ret.push_back('"');
+ return ret;
+}
+
+std::string dev::randomWord()
+{
+ static std::mt19937_64 s_eng(0);
+ std::string ret(std::uniform_int_distribution(1, 5)(s_eng), ' ');
+ char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
+ std::uniform_int_distribution d(0, sizeof(n) - 2);
+ for (char& c: ret)
+ c = n[d(s_eng)];
+ return ret;
+}
+
+int dev::fromHex(char _i)
+{
+ if (_i >= '0' && _i <= '9')
+ return _i - '0';
+ if (_i >= 'a' && _i <= 'f')
+ return _i - 'a' + 10;
+ if (_i >= 'A' && _i <= 'F')
+ return _i - 'A' + 10;
+ throw BadHexCharacter();
+}
+
+bytes dev::fromHex(std::string const& _s)
+{
+ unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0;
+ std::vector ret;
+ ret.reserve((_s.size() - s + 1) / 2);
+
+ if (_s.size() % 2)
+ try
+ {
+ ret.push_back(fromHex(_s[s++]));
+ }
+ catch (...){ ret.push_back(0); }
+ for (unsigned i = s; i < _s.size(); i += 2)
+ try
+ {
+ ret.push_back((byte)(fromHex(_s[i]) * 16 + fromHex(_s[i + 1])));
+ }
+ catch (...){ ret.push_back(0); }
+ return ret;
+}
+
+bytes dev::asNibbles(std::string const& _s)
+{
+ std::vector ret;
+ ret.reserve(_s.size() * 2);
+ for (auto i: _s)
+ {
+ ret.push_back(i / 16);
+ ret.push_back(i % 16);
+ }
+ return ret;
+}
+
+#if 0
+
+/* Following code is copyright 2012-2014 Luke Dashjr
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the standard MIT license. See COPYING for more details.
+ */
+
+#include
+#include
+#include
+#include
+
+static const int8_t b58digits_map[] = {
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1,
+ -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1,
+ 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1,
+ -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46,
+ 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1,
+};
+
+bool b58tobin(void *bin, size_t *binszp, const char *b58, size_t b58sz)
+{
+ size_t binsz = *binszp;
+ const unsigned char *b58u = (void*)b58;
+ unsigned char *binu = bin;
+ size_t outisz = (binsz + 3) / 4;
+ uint32_t outi[outisz];
+ uint64_t t;
+ uint32_t c;
+ size_t i, j;
+ uint8_t bytesleft = binsz % 4;
+ uint32_t zeromask = bytesleft ? (0xffffffff << (bytesleft * 8)) : 0;
+ unsigned zerocount = 0;
+
+ if (!b58sz)
+ b58sz = strlen(b58);
+
+ memset(outi, 0, outisz * sizeof(*outi));
+
+ // Leading zeros, just count
+ for (i = 0; i < b58sz && !b58digits_map[b58u[i]]; ++i)
+ ++zerocount;
+
+ for ( ; i < b58sz; ++i)
+ {
+ if (b58u[i] & 0x80)
+ // High-bit set on invalid digit
+ return false;
+ if (b58digits_map[b58u[i]] == -1)
+ // Invalid base58 digit
+ return false;
+ c = (unsigned)b58digits_map[b58u[i]];
+ for (j = outisz; j--; )
+ {
+ t = ((uint64_t)outi[j]) * 58 + c;
+ c = (t & 0x3f00000000) >> 32;
+ outi[j] = t & 0xffffffff;
+ }
+ if (c)
+ // Output number too big (carry to the next int32)
+ return false;
+ if (outi[0] & zeromask)
+ // Output number too big (last int32 filled too far)
+ return false;
+ }
+
+ j = 0;
+ switch (bytesleft) {
+ case 3:
+ *(binu++) = (outi[0] & 0xff0000) >> 16;
+ case 2:
+ *(binu++) = (outi[0] & 0xff00) >> 8;
+ case 1:
+ *(binu++) = (outi[0] & 0xff);
+ ++j;
+ default:
+ break;
+ }
+
+ for (; j < outisz; ++j)
+ {
+ *(binu++) = (outi[j] >> 0x18) & 0xff;
+ *(binu++) = (outi[j] >> 0x10) & 0xff;
+ *(binu++) = (outi[j] >> 8) & 0xff;
+ *(binu++) = (outi[j] >> 0) & 0xff;
+ }
+
+ // Count canonical base58 byte count
+ binu = bin;
+ for (i = 0; i < binsz; ++i)
+ {
+ if (binu[i])
+ break;
+ --*binszp;
+ }
+ *binszp += zerocount;
+
+ return true;
+}
+
+static
+bool my_dblsha256(void *hash, const void *data, size_t datasz)
+{
+ uint8_t buf[0x20];
+ return b58_sha256_impl(buf, data, datasz) && b58_sha256_impl(hash, buf, sizeof(buf));
+}
+
+int b58check(const void *bin, size_t binsz, const char *base58str, size_t b58sz)
+{
+ unsigned char buf[32];
+ const uint8_t *binc = bin;
+ unsigned i;
+ if (binsz < 4)
+ return -4;
+ if (!my_dblsha256(buf, bin, binsz - 4))
+ return -2;
+ if (memcmp(&binc[binsz - 4], buf, 4))
+ return -1;
+
+ // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
+ for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
+ {} // Just finding the end of zeros, nothing to do in loop
+ if (binc[i] == '\0' || base58str[i] == '1')
+ return -3;
+
+ return binc[0];
+}
+
+static const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
+
+bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)
+{
+ const uint8_t *bin = data;
+ int carry;
+ size_t i, j, high, zcount = 0;
+ size_t size;
+
+ while (zcount < binsz && !bin[zcount])
+ ++zcount;
+
+ size = (binsz - zcount) * 138 / 100 + 1;
+ uint8_t buf[size];
+ memset(buf, 0, size);
+
+ for (i = zcount, high = size - 1; i < binsz; ++i, high = j)
+ {
+ for (carry = bin[i], j = size - 1; (j > high) || carry; --j)
+ {
+ carry += 256 * buf[j];
+ buf[j] = carry % 58;
+ carry /= 58;
+ }
+ }
+
+ for (j = 0; j < size && !buf[j]; ++j);
+
+ if (*b58sz <= zcount + size - j)
+ {
+ *b58sz = zcount + size - j + 1;
+ return false;
+ }
+
+ if (zcount)
+ memset(b58, '1', zcount);
+ for (i = zcount; j < size; ++i, ++j)
+ b58[i] = b58digits_ordered[buf[j]];
+ b58[i] = '\0';
+ *b58sz = i + 1;
+
+ return true;
+}
+
+#endif
diff --git a/libethential/CommonData.h b/libdevcore/CommonData.h
similarity index 93%
rename from libethential/CommonData.h
rename to libdevcore/CommonData.h
index 6840194fc..11850fa69 100644
--- a/libethential/CommonData.h
+++ b/libdevcore/CommonData.h
@@ -30,7 +30,7 @@
#include
#include "Common.h"
-namespace eth
+namespace dev
{
// String conversion functions, mainly to/from hex/nibble/byte representations.
@@ -55,6 +55,11 @@ int fromHex(char _i);
/// @example fromHex("41626261") == asBytes("Abba")
bytes fromHex(std::string const& _s);
+#if 0
+std::string toBase58(bytesConstRef _data);
+bytes fromBase58(std::string const& _s);
+#endif
+
/// Converts byte array to a string containing the same (binary) data. Unless
/// the byte array happens to contain ASCII data, this won't be printable.
inline std::string asString(bytes const& _b)
@@ -79,7 +84,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 +94,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 +145,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