Browse Source

Merge branch 'develop' into p2p

cl-refactor
subtly 10 years ago
parent
commit
f8a8e1f1ac
  1. 14
      alethzero/MainWin.cpp
  2. 173
      alethzero/Transact.cpp
  3. 13
      alethzero/Transact.h
  4. 21
      eth/main.cpp
  5. 9
      libdevcrypto/FileSystem.cpp
  6. 2
      libdevcrypto/FileSystem.h
  7. 11
      libethcore/Common.h
  8. 4
      libethcore/Ethasher.cpp
  9. 1
      libethcore/Exceptions.h
  10. 1
      libethcore/Params.cpp
  11. 1
      libethcore/Params.h
  12. 36
      libethereum/Client.cpp
  13. 21
      libethereum/Client.h
  14. 22
      libethereum/Interface.h
  15. 27
      libethereum/LogFilter.cpp
  16. 11
      libethereum/LogFilter.h
  17. 2
      libethereum/Transaction.cpp
  18. 1
      libethereum/Transaction.h
  19. 4
      libevm/ExtVMFace.h
  20. 6
      libevm/VM.cpp
  21. 2
      libevm/VM.h
  22. 1
      libevm/VMFace.h
  23. 31
      libjsqrc/ethereumjs/dist/ethereum.js
  24. 8
      libjsqrc/ethereumjs/dist/ethereum.js.map
  25. 2
      libjsqrc/ethereumjs/dist/ethereum.min.js
  26. 2
      libjsqrc/ethereumjs/lib/web3/contract.js
  27. 27
      libjsqrc/ethereumjs/lib/web3/filter.js
  28. 45
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  29. 18
      mix/MixClient.cpp
  30. 19
      mix/MixClient.h
  31. 12
      neth/main.cpp
  32. 20
      third/MainWin.cpp

14
alethzero/MainWin.cpp

@ -162,7 +162,7 @@ Main::Main(QWidget *parent) :
QSettings s("ethereum", "alethzero"); QSettings s("ethereum", "alethzero");
m_networkConfig = s.value("peers").toByteArray(); m_networkConfig = s.value("peers").toByteArray();
bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size()); bytesConstRef network((byte*)m_networkConfig.data(), m_networkConfig.size());
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/AlethZero", false, {"eth", "shh"}, p2p::NetworkPreferences(), network)); m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir(), false, {"eth", "shh"}, p2p::NetworkPreferences(), network));
m_httpConnector.reset(new jsonrpc::HttpServer(8080)); m_httpConnector.reset(new jsonrpc::HttpServer(8080));
m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys), this)); m_server.reset(new OurWebThreeStubServer(*m_httpConnector, *web3(), keysAsVector(m_myKeys), this));
@ -312,7 +312,7 @@ void Main::installBalancesWatch()
Address coinsAddr = getCurrencies(); Address coinsAddr = getCurrencies();
// TODO: Update for new currencies reg. // TODO: Update for new currencies reg.
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1))); altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys) for (auto i: m_myKeys)
for (auto c: altCoins) for (auto c: altCoins)
@ -616,10 +616,10 @@ QString Main::lookup(QString const& _a) const
h256 ret; h256 ret;
// TODO: fix with the new DNSreg contract // TODO: fix with the new DNSreg contract
// if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, 0)) // if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, PendingBlock))
// ret = ethereum()->stateAt(dnsReg, n); // ret = ethereum()->stateAt(dnsReg, n);
/* if (!ret) /* if (!ret)
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, PendingBlock))
ret = ethereum()->stateAt(nameReg, n2); ret = ethereum()->stateAt(nameReg, n2);
*/ */
if (ret && !((u256)ret >> 32)) if (ret && !((u256)ret >> 32))
@ -937,7 +937,7 @@ void Main::refreshBalances()
u256 totalBalance = 0; u256 totalBalance = 0;
/* map<Address, tuple<QString, u256, u256>> altCoins; /* map<Address, tuple<QString, u256, u256>> altCoins;
Address coinsAddr = getCurrencies(); Address coinsAddr = getCurrencies();
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
{ {
auto n = ethereum()->stateAt(coinsAddr, i + 1); auto n = ethereum()->stateAt(coinsAddr, i + 1);
auto addr = right160(ethereum()->stateAt(coinsAddr, n)); auto addr = right160(ethereum()->stateAt(coinsAddr, n));
@ -1357,7 +1357,7 @@ void Main::on_transactionQueue_currentItemChanged()
auto r = receipt.rlp(); auto r = receipt.rlp();
s << "<div>Receipt: " << toString(RLP(r)) << "</div>"; s << "<div>Receipt: " << toString(RLP(r)) << "</div>";
s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>"; s << "<div>Receipt-Hex: " Span(Mono) << toHex(receipt.rlp()) << "</span></div>";
s << renderDiff(ethereum()->diff(i, 0)); s << renderDiff(ethereum()->diff(i, PendingBlock));
// s << "Pre: " << fs.rootHash() << "<br/>"; // s << "Pre: " << fs.rootHash() << "<br/>";
// s << "Post: <b>" << ts.rootHash() << "</b>"; // s << "Post: <b>" << ts.rootHash() << "</b>";
} }
@ -1550,7 +1550,7 @@ void Main::on_debugCurrent_triggered()
unsigned txi = item->data(Qt::UserRole + 1).toInt(); unsigned txi = item->data(Qt::UserRole + 1).toInt();
bytes t = ethereum()->blockChain().transaction(h, txi); bytes t = ethereum()->blockChain().transaction(h, txi);
State s(ethereum()->state(txi, h)); State s(ethereum()->state(txi, h));
Executive e(s, ethereum()->blockChain(), 0); Executive e(s, ethereum()->blockChain(), PendingBlock);
Debugger dw(this, this); Debugger dw(this, this);
dw.populate(e, Transaction(t, CheckSignature::Sender)); dw.populate(e, Transaction(t, CheckSignature::Sender));
dw.exec(); dw.exec();

173
alethzero/Transact.cpp

@ -163,8 +163,29 @@ void Transact::on_destination_currentTextChanged(QString)
// updateFee(); // updateFee();
} }
static std::string toString(TransactionException _te)
{
switch (_te)
{
case TransactionException::Unknown: return "Unknown error";
case TransactionException::InvalidSignature: return "Permanent Abort: Invalid transaction signature";
case TransactionException::InvalidNonce: return "Transient Abort: Invalid transaction nonce";
case TransactionException::NotEnoughCash: return "Transient Abort: Not enough cash to pay for transaction";
case TransactionException::OutOfGasBase: return "Permanent Abort: Not enough gas to consider transaction";
case TransactionException::BlockGasLimitReached: return "Transient Abort: Gas limit of block reached";
case TransactionException::BadInstruction: return "VM Error: Attempt to execute invalid instruction";
case TransactionException::BadJumpDestination: return "VM Error: Attempt to jump to invalid destination";
case TransactionException::OutOfGas: return "VM Error: Out of gas";
case TransactionException::OutOfStack: return "VM Error: VM stack limit reached during execution";
case TransactionException::StackUnderflow: return "VM Error: Stack underflow";
default:; return std::string();
}
}
void Transact::rejigData() void Transact::rejigData()
{ {
if (!ethereum())
return;
if (isCreation()) if (isCreation())
{ {
string src = ui->data->toPlainText().toStdString(); string src = ui->data->toPlainText().toStdString();
@ -226,26 +247,61 @@ void Transact::rejigData()
} }
} }
QString errs; QString errs;
qint64 gasNeeded = 0;
if (errors.size()) if (errors.size())
{ {
errs = "<h4>Errors</h4>"; errs = "<h4>Errors</h4>";
for (auto const& i: errors) for (auto const& i: errors)
errs.append("<div style=\"border-left: 6px solid #c00; margin-top: 2px\">" + QString::fromStdString(i).toHtmlEscaped() + "</div>"); errs.append("<div style=\"border-left: 6px solid #c00; margin-top: 2px\">" + QString::fromStdString(i).toHtmlEscaped() + "</div>");
} }
else
{
if (true)
{
auto s = findSecret(value() + ethereum()->gasLimitRemaining() * gasPrice());
if (!s)
errs += "<div class=\"error\"><span class=\"icon\">ERROR</span> No single account contains enough gas.</div>";
// TODO: use account with most balance anyway.
else
{
ExecutionResult er = ethereum()->create(s, value(), m_data, ethereum()->gasLimitRemaining(), gasPrice());
gasNeeded = (qint64)er.gasUsed;
auto base = (qint64)Interface::txGas(m_data, 0);
errs += QString("<div class=\"info\"><span class=\"icon\">INFO</span> Gas required: %1 base, %2 init</div>").arg(base).arg((qint64)er.gasUsed - base);
if (er.excepted != TransactionException::None)
errs += "<div class=\"error\"><span class=\"icon\">ERROR</span> " + QString::fromStdString(toString(er.excepted)) + "</div>";
if (er.codeDeposit == CodeDeposit::Failed)
errs += "<div class=\"error\"><span class=\"icon\">ERROR</span> Code deposit failed due to insufficient gas</div>";
}
}
else
gasNeeded = (qint64)Interface::txGas(m_data, 0);
}
ui->code->setHtml(errs + lll + solidity + "<h4>Code</h4>" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped() + "<h4>Hex</h4>" Div(Mono) + QString::fromStdString(toHex(m_data)) + "</div>"); ui->code->setHtml(errs + lll + solidity + "<h4>Code</h4>" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped() + "<h4>Hex</h4>" Div(Mono) + QString::fromStdString(toHex(m_data)) + "</div>");
ui->gas->setMinimum((qint64)Interface::txGas(m_data, 0));
if (!ui->gas->isEnabled()) if (ui->gas->value() == ui->gas->minimum())
ui->gas->setValue(m_backupGas); {
ui->gas->setMinimum(gasNeeded);
ui->gas->setValue(gasNeeded);
}
else
ui->gas->setMinimum(gasNeeded);
// if (!ui->gas->isEnabled())
// ui->gas->setValue(m_backupGas);
ui->gas->setEnabled(true); ui->gas->setEnabled(true);
if (ui->gas->value() == ui->gas->minimum() && !src.empty()) // if (ui->gas->value() == ui->gas->minimum() && !src.empty())
ui->gas->setValue((int)(m_ethereum->postState().gasLimitRemaining() / 10)); // ui->gas->setValue((int)(m_ethereum->postState().gasLimitRemaining() / 10));
} }
else else
{ {
auto base = (qint64)Interface::txGas(m_data, 0);
m_data = parseData(ui->data->toPlainText().toStdString()); m_data = parseData(ui->data->toPlainText().toStdString());
auto to = m_context->fromString(ui->destination->currentText()); auto to = m_context->fromString(ui->destination->currentText());
QString natspec; QString natspec;
if (ethereum()->codeAt(to, 0).size()) QString errs;
if (ethereum()->codeAt(to, PendingBlock).size())
{ {
string userNotice = m_natSpecDB->getUserNotice(ethereum()->postState().codeHash(to), m_data); string userNotice = m_natSpecDB->getUserNotice(ethereum()->postState().codeHash(to), m_data);
if (userNotice.empty()) if (userNotice.empty())
@ -255,7 +311,35 @@ void Transact::rejigData()
NatspecExpressionEvaluator evaluator; NatspecExpressionEvaluator evaluator;
natspec = evaluator.evalExpression(QString::fromStdString(userNotice)); natspec = evaluator.evalExpression(QString::fromStdString(userNotice));
} }
ui->gas->setMinimum((qint64)Interface::txGas(m_data, 1));
qint64 gasNeeded = 0;
if (true)
{
auto s = findSecret(value() + ethereum()->gasLimitRemaining() * gasPrice());
if (!s)
errs += "<div class=\"error\"><span class=\"icon\">ERROR</span> No single account contains enough gas.</div>";
// TODO: use account with most balance anyway.
else
{
ExecutionResult er = ethereum()->call(s, value(), to, m_data, ethereum()->gasLimitRemaining(), gasPrice());
gasNeeded = (qint64)er.gasUsed;
errs += QString("<div class=\"info\"><span class=\"icon\">INFO</span> Gas required: %1 base, %2 exec</div>").arg(base).arg((qint64)er.gasUsed - base);
if (er.excepted != TransactionException::None)
errs += "<div class=\"error\"><span class=\"icon\">ERROR</span> " + QString::fromStdString(toString(er.excepted)) + "</div>";
}
}
else
gasNeeded = (qint64)Interface::txGas(m_data, 0);
if (ui->gas->value() == ui->gas->minimum())
{
ui->gas->setMinimum(gasNeeded);
ui->gas->setValue(gasNeeded);
}
else
ui->gas->setMinimum(gasNeeded);
if (!ui->gas->isEnabled()) if (!ui->gas->isEnabled())
ui->gas->setValue(m_backupGas); ui->gas->setValue(m_backupGas);
ui->gas->setEnabled(true); ui->gas->setEnabled(true);
@ -265,50 +349,57 @@ void Transact::rejigData()
natspec += "Destination not a contract."; natspec += "Destination not a contract.";
if (ui->gas->isEnabled()) if (ui->gas->isEnabled())
m_backupGas = ui->gas->value(); m_backupGas = ui->gas->value();
ui->gas->setValue((qint64)Interface::txGas(m_data)); ui->gas->setMinimum(base);
ui->gas->setValue(base);
ui->gas->setEnabled(false); ui->gas->setEnabled(false);
} }
ui->code->setHtml("<h3>NatSpec</h3>" + natspec + "<h3>Dump</h3>" + QString::fromStdString(dev::memDump(m_data, 8, true)) + "<h3>Hex</h3>" + Div(Mono) + QString::fromStdString(toHex(m_data)) + "</div>"); ui->code->setHtml(errs + "<h3>NatSpec</h3>" + natspec + "<h3>Dump</h3>" + QString::fromStdString(dev::memDump(m_data, 8, true)) + "<h3>Hex</h3>" + Div(Mono) + QString::fromStdString(toHex(m_data)) + "</div>");
} }
updateFee(); updateFee();
} }
Secret Transact::findSecret(u256 _totalReq) const
{
if (ethereum())
for (auto const& i: m_myKeys)
if (ethereum()->balanceAt(i.address(), PendingBlock) >= _totalReq)
return i.secret();
return Secret();
}
void Transact::on_send_clicked() void Transact::on_send_clicked()
{ {
u256 totalReq = value() + fee(); Secret s = findSecret(value() + fee());
for (auto const& i: m_myKeys) if (!s)
if (ethereum()->balanceAt(i.address(), 0) >= totalReq) {
{ QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction: no single account contains at least the required amount.");
Secret s = i.secret(); return;
if (isCreation()) }
if (isCreation())
{
// If execution is a contract creation, add Natspec to
// a local Natspec LEVELDB
ethereum()->submitTransaction(s, value(), m_data, ui->gas->value(), gasPrice());
string src = ui->data->toPlainText().toStdString();
if (sourceIsSolidity(src))
try
{ {
// If execution is a contract creation, add Natspec to dev::solidity::CompilerStack compiler(true);
// a local Natspec LEVELDB m_data = compiler.compile(src, ui->optimize->isChecked());
ExecutionResult er = ethereum()->create(s, value(), m_data, ui->gas->value(), gasPrice()); for (string const& s: compiler.getContractNames())
ethereum()->submitTransaction(s, value(), m_data, ui->gas->value(), gasPrice()); {
string src = ui->data->toPlainText().toStdString(); h256 contractHash = compiler.getContractCodeHash(s);
if (sourceIsSolidity(src)) m_natSpecDB->add(contractHash, compiler.getMetadata(s, dev::solidity::DocumentationType::NatspecUser));
try }
{
dev::solidity::CompilerStack compiler(true);
m_data = compiler.compile(src, ui->optimize->isChecked());
for (string const& s: compiler.getContractNames())
{
h256 contractHash = compiler.getContractCodeHash(s);
m_natSpecDB->add(contractHash, compiler.getMetadata(s, dev::solidity::DocumentationType::NatspecUser));
}
}
catch (...)
{
}
close();
return;
} }
else catch (...)
ethereum()->submitTransaction(s, value(), m_context->fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice()); {
return; }
} }
QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction: no single account contains at least the required amount."); else
ethereum()->submitTransaction(s, value(), m_context->fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice());
close();
} }
void Transact::on_debug_clicked() void Transact::on_debug_clicked()

13
alethzero/Transact.h

@ -57,7 +57,7 @@ private slots:
void on_cancel_clicked() { close(); } void on_cancel_clicked() { close(); }
private: private:
dev::eth::Client* ethereum() { return m_ethereum; } dev::eth::Client* ethereum() const { return m_ethereum; }
void rejigData(); void rejigData();
void updateDestination(); void updateDestination();
@ -69,14 +69,15 @@ private:
dev::u256 gasPrice() const; dev::u256 gasPrice() const;
std::string getFunctionHashes(dev::solidity::CompilerStack const& _compiler, std::string const& _contractName = std::string()); std::string getFunctionHashes(dev::solidity::CompilerStack const& _compiler, std::string const& _contractName = std::string());
dev::Secret findSecret(dev::u256 _totalReq) const;
Ui::Transact* ui; Ui::Transact* ui = nullptr;
unsigned m_backupGas; unsigned m_backupGas = 0;
dev::bytes m_data; dev::bytes m_data;
QList<dev::KeyPair> m_myKeys; QList<dev::KeyPair> m_myKeys;
dev::eth::Client* m_ethereum; dev::eth::Client* m_ethereum = nullptr;
Context* m_context; Context* m_context = nullptr;
NatSpecFace* m_natSpecDB; NatSpecFace* m_natSpecDB = nullptr;
}; };

21
eth/main.cpp

@ -103,7 +103,7 @@ void interactiveHelp()
void help() void help()
{ {
cout cout
<< "Usage eth [OPTIONS] <remote-host>" << endl << "Usage eth [OPTIONS]" << endl
<< "Options:" << endl << "Options:" << endl
<< " -a,--address <addr> Set the coinbase (mining payout) address to addr (default: auto)." << endl << " -a,--address <addr> Set the coinbase (mining payout) address to addr (default: auto)." << endl
<< " -b,--bootstrap Connect to the default Ethereum peerserver." << endl << " -b,--bootstrap Connect to the default Ethereum peerserver." << endl
@ -119,6 +119,7 @@ void help()
<< " -j,--json-rpc Enable JSON-RPC server (default: off)." << endl << " -j,--json-rpc Enable JSON-RPC server (default: off)." << endl
<< " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: 8080)." << endl << " --json-rpc-port Specify JSON-RPC server port (implies '-j', default: 8080)." << endl
#endif #endif
<< " -K,--kill-blockchain First kill the blockchain." << endl
<< " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl << " -l,--listen <port> Listen on the given port for incoming connected (default: 30303)." << endl
<< " -L,--local-networking Use peers whose addresses are local." << endl << " -L,--local-networking Use peers whose addresses are local." << endl
<< " -m,--mining <on/off/number> Enable mining, optionally for a specified number of blocks (Default: off)" << endl << " -m,--mining <on/off/number> Enable mining, optionally for a specified number of blocks (Default: off)" << endl
@ -214,6 +215,7 @@ int main(int argc, char** argv)
bool upnp = true; bool upnp = true;
bool useLocal = false; bool useLocal = false;
bool forceMining = false; bool forceMining = false;
bool killChain = false;
bool jit = false; bool jit = false;
bool structuredLogging = false; bool structuredLogging = false;
string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S"; string structuredLoggingFormat = "%Y-%m-%dT%H:%M:%S";
@ -270,6 +272,8 @@ int main(int argc, char** argv)
} }
else if (arg == "-L" || arg == "--local-networking") else if (arg == "-L" || arg == "--local-networking")
useLocal = true; useLocal = true;
else if (arg == "-K" || arg == "--kill-blockchain")
killChain = true;
else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc) else if ((arg == "-c" || arg == "--client-name") && i + 1 < argc)
clientName = argv[++i]; clientName = argv[++i];
else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc) else if ((arg == "-a" || arg == "--address" || arg == "--coinbase-address") && i + 1 < argc)
@ -403,7 +407,10 @@ int main(int argc, char** argv)
else if (arg == "-V" || arg == "--version") else if (arg == "-V" || arg == "--version")
version(); version();
else else
remoteHost = argv[i]; {
cerr << "Invalid argument: " << arg << endl;
exit(-1);
}
} }
if (!clientName.empty()) if (!clientName.empty())
@ -419,7 +426,7 @@ int main(int argc, char** argv)
dev::WebThreeDirect web3( dev::WebThreeDirect web3(
clientImplString, clientImplString,
dbPath, dbPath,
false, killChain,
mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(), mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(),
netPrefs, netPrefs,
&nodesState, &nodesState,
@ -683,7 +690,7 @@ int main(int argc, char** argv)
auto acs =c->addresses(); auto acs =c->addresses();
string ss; string ss;
for (auto const& i: acs) for (auto const& i: acs)
if ( c->codeAt(i, 0).size()) if ( c->codeAt(i, PendingBlock).size())
{ {
ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]"; ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl; cout << ss << endl;
@ -694,7 +701,7 @@ int main(int argc, char** argv)
auto acs =c->addresses(); auto acs =c->addresses();
string ss; string ss;
for (auto const& i: acs) for (auto const& i: acs)
if ( c->codeAt(i, 0).empty()) if ( c->codeAt(i, PendingBlock).empty())
{ {
ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]"; ss = toString(i) + " : " + toString( c->balanceAt(i)) + " [" + toString((unsigned) c->countAt(i)) + "]";
cout << ss << endl; cout << ss << endl;
@ -886,10 +893,10 @@ int main(int argc, char** argv)
try try
{ {
auto storage =c->storageAt(h, 0); auto storage =c->storageAt(h, PendingBlock);
for (auto const& i: storage) for (auto const& i: storage)
s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl; s << "@" << showbase << hex << i.first << " " << showbase << hex << i.second << endl;
s << endl << disassemble( c->codeAt(h, 0)) << endl; s << endl << disassemble( c->codeAt(h, PendingBlock)) << endl;
string outFile = getDataDir() + "/" + rechex + ".evm"; string outFile = getDataDir() + "/" + rechex + ".evm";
ofstream ofs; ofstream ofs;

9
libdevcrypto/FileSystem.cpp

@ -32,12 +32,15 @@
using namespace std; using namespace std;
using namespace dev; using namespace dev;
std::string dev::getDataDir() std::string dev::getDataDir(std::string _prefix)
{ {
if (_prefix.empty())
_prefix = "ethereum";
#ifdef _WIN32 #ifdef _WIN32
_prefix[0] = toupper(_prefix[0]);
char path[1024] = ""; char path[1024] = "";
if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true)) if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true))
return (boost::filesystem::path(path) / "Ethereum").string(); return (boost::filesystem::path(path) / _prefix).string();
else else
{ {
#ifndef _MSC_VER // todo? #ifndef _MSC_VER // todo?
@ -57,7 +60,7 @@ std::string dev::getDataDir()
// This eventually needs to be put in proper wrapper (to support sandboxing) // This eventually needs to be put in proper wrapper (to support sandboxing)
return (dataDirPath / "Library/Application Support/Ethereum").string(); return (dataDirPath / "Library/Application Support/Ethereum").string();
#else #else
return (dataDirPath / ".ethereum").string(); return (dataDirPath / ("." + _prefix)).string();
#endif #endif
#endif #endif
} }

2
libdevcrypto/FileSystem.h

@ -30,6 +30,6 @@ namespace dev
{ {
/// @returns the path for user data. /// @returns the path for user data.
std::string getDataDir(); std::string getDataDir(std::string _prefix = "ethereum");
} }

11
libethcore/Common.h

@ -71,5 +71,16 @@ static const u256 wei = exp10<0>();
using Nonce = h64; using Nonce = h64;
using BlockNumber = unsigned;
static const BlockNumber LatestBlock = (BlockNumber)-2;
static const BlockNumber PendingBlock = (BlockNumber)-1;
enum class RelativeBlock: BlockNumber
{
Latest = LatestBlock,
Pending = PendingBlock
};
} }
} }

4
libethcore/Ethasher.cpp

@ -71,10 +71,10 @@ bytesConstRef Ethasher::full(BlockInfo const& _header)
m_fulls.erase(m_fulls.begin()); m_fulls.erase(m_fulls.begin());
} }
try { try {
boost::filesystem::create_directories(getDataDir() + "/ethashcache"); boost::filesystem::create_directories(getDataDir("ethash"));
} catch (...) {} } catch (...) {}
std::string memoFile = getDataDir() + "/ethashcache/full"; std::string memoFile = getDataDir("ethash") + "/full";
auto info = rlpList(c_ethashRevision, _header.seedHash()); auto info = rlpList(c_ethashRevision, _header.seedHash());
if (boost::filesystem::exists(memoFile) && contents(memoFile + ".info") != info) if (boost::filesystem::exists(memoFile) && contents(memoFile + ".info") != info)
boost::filesystem::remove(memoFile); boost::filesystem::remove(memoFile);

1
libethcore/Exceptions.h

@ -59,7 +59,6 @@ struct InvalidGasUsed: virtual dev::Exception {};
class InvalidTransactionsHash: virtual public dev::Exception {}; class InvalidTransactionsHash: virtual public dev::Exception {};
struct InvalidTransaction: virtual dev::Exception {}; struct InvalidTransaction: virtual dev::Exception {};
struct InvalidDifficulty: virtual dev::Exception {}; struct InvalidDifficulty: virtual dev::Exception {};
struct InvalidSeedHash: virtual dev::Exception {};
class InvalidGasLimit: virtual public dev::Exception {}; class InvalidGasLimit: virtual public dev::Exception {};
struct InvalidTransactionGasUsed: virtual dev::Exception {}; struct InvalidTransactionGasUsed: virtual dev::Exception {};
struct InvalidTransactionsStateRoot: virtual dev::Exception {}; struct InvalidTransactionsStateRoot: virtual dev::Exception {};

1
libethcore/Params.cpp

@ -37,6 +37,7 @@ u256 const c_gasLimitBoundDivisor = 1024;
u256 const c_minimumDifficulty = 131072; u256 const c_minimumDifficulty = 131072;
u256 const c_difficultyBoundDivisor = 2048; u256 const c_difficultyBoundDivisor = 2048;
u256 const c_durationLimit = 8; u256 const c_durationLimit = 8;
u256 const c_stackLimit = 1024;
u256 const c_tierStepGas[] = {0, 2, 3, 5, 8, 10, 20, 0}; u256 const c_tierStepGas[] = {0, 2, 3, 5, 8, 10, 20, 0};
u256 const c_expGas = 10; u256 const c_expGas = 10;
u256 const c_expByteGas = 10; u256 const c_expByteGas = 10;

1
libethcore/Params.h

@ -38,6 +38,7 @@ extern u256 const c_gasLimitBoundDivisor;
extern u256 const c_minimumDifficulty; extern u256 const c_minimumDifficulty;
extern u256 const c_difficultyBoundDivisor; extern u256 const c_difficultyBoundDivisor;
extern u256 const c_durationLimit; extern u256 const c_durationLimit;
extern u256 const c_stackLimit;
extern u256 const c_tierStepGas[8]; ///< Once per operation, for a selection of them. extern u256 const c_tierStepGas[8]; ///< Once per operation, for a selection of them.
extern u256 const c_expGas; ///< Once per EXP instuction. extern u256 const c_expGas; ///< Once per EXP instuction.

36
libethereum/Client.cpp

@ -357,11 +357,11 @@ LocalisedLogEntries Client::checkWatch(unsigned _watchId)
return ret; return ret;
} }
void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _sha3) void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _transactionHash)
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
for (pair<h256 const, InstalledFilter>& i: m_filters) for (pair<h256 const, InstalledFilter>& i: m_filters)
if ((unsigned)i.second.filter.latest() > m_bc.number()) if (i.second.filter.envelops(RelativeBlock::Pending, m_bc.number() + 1))
{ {
// acceptable number. // acceptable number.
auto m = i.second.filter.matches(_receipt); auto m = i.second.filter.matches(_receipt);
@ -369,7 +369,7 @@ void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& i
{ {
// filter catches them // filter catches them
for (LogEntry const& l: m) for (LogEntry const& l: m)
i.second.changes.push_back(LocalisedLogEntry(l, m_bc.number() + 1, _sha3)); i.second.changes.push_back(LocalisedLogEntry(l, m_bc.number() + 1, _transactionHash));
io_changed.insert(i.first); io_changed.insert(i.first);
} }
} }
@ -383,7 +383,7 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed)
Guard l(m_filterLock); Guard l(m_filterLock);
for (pair<h256 const, InstalledFilter>& i: m_filters) for (pair<h256 const, InstalledFilter>& i: m_filters)
if ((unsigned)i.second.filter.latest() >= d.number && (unsigned)i.second.filter.earliest() <= d.number && i.second.filter.matches(d.logBloom)) if (i.second.filter.envelops(RelativeBlock::Latest, d.number) && i.second.filter.matches(d.logBloom))
// acceptable number & looks like block may contain a matching log entry. // acceptable number & looks like block may contain a matching log entry.
for (size_t j = 0; j < br.receipts.size(); j++) for (size_t j = 0; j < br.receipts.size(); j++)
{ {
@ -391,10 +391,10 @@ void Client::appendFromNewBlock(h256 const& _block, h256Set& io_changed)
auto m = i.second.filter.matches(tr); auto m = i.second.filter.matches(tr);
if (m.size()) if (m.size())
{ {
auto sha3 = transaction(d.hash, j).sha3(); auto transactionHash = transaction(d.hash, j).sha3();
// filter catches them // filter catches them
for (LogEntry const& l: m) for (LogEntry const& l: m)
i.second.changes.push_back(LocalisedLogEntry(l, (unsigned)d.number, sha3)); i.second.changes.push_back(LocalisedLogEntry(l, (unsigned)d.number, transactionHash));
io_changed.insert(i.first); io_changed.insert(i.first);
} }
} }
@ -491,7 +491,7 @@ void Client::submitTransaction(Secret _secret, u256 _value, Address _dest, bytes
m_tq.attemptImport(t.rlp()); m_tq.attemptImport(t.rlp());
} }
ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
ExecutionResult ret; ExecutionResult ret;
try try
@ -514,7 +514,7 @@ ExecutionResult Client::call(Secret _secret, u256 _value, Address _dest, bytes c
return ret; return ret;
} }
ExecutionResult Client::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) ExecutionResult Client::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
ExecutionResult ret; ExecutionResult ret;
try try
@ -739,12 +739,12 @@ unsigned Client::numberOf(int _n) const
return m_bc.details().number + max(-(int)m_bc.details().number, 1 + _n); return m_bc.details().number + max(-(int)m_bc.details().number, 1 + _n);
} }
State Client::asOf(int _h) const State Client::asOf(unsigned _h) const
{ {
ReadGuard l(x_stateDB); ReadGuard l(x_stateDB);
if (_h == 0) if (_h == PendingBlock)
return m_postMine; return m_postMine;
else if (_h == -1) else if (_h == LatestBlock)
return m_preMine; return m_preMine;
else else
return State(m_stateDB, m_bc, m_bc.numberHash(numberOf(_h))); return State(m_stateDB, m_bc, m_bc.numberHash(numberOf(_h)));
@ -768,7 +768,7 @@ eth::State Client::state(unsigned _txi) const
return m_postMine.fromPending(_txi); return m_postMine.fromPending(_txi);
} }
StateDiff Client::diff(unsigned _txi, int _block) const StateDiff Client::diff(unsigned _txi, BlockNumber _block) const
{ {
State st = asOf(_block); State st = asOf(_block);
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
@ -780,7 +780,7 @@ StateDiff Client::diff(unsigned _txi, h256 _block) const
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
std::vector<Address> Client::addresses(int _block) const std::vector<Address> Client::addresses(BlockNumber _block) const
{ {
vector<Address> ret; vector<Address> ret;
for (auto const& i: asOf(_block).addresses()) for (auto const& i: asOf(_block).addresses())
@ -788,27 +788,27 @@ std::vector<Address> Client::addresses(int _block) const
return ret; return ret;
} }
u256 Client::balanceAt(Address _a, int _block) const u256 Client::balanceAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).balance(_a); return asOf(_block).balance(_a);
} }
std::map<u256, u256> Client::storageAt(Address _a, int _block) const std::map<u256, u256> Client::storageAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).storage(_a); return asOf(_block).storage(_a);
} }
u256 Client::countAt(Address _a, int _block) const u256 Client::countAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).transactionsFrom(_a); return asOf(_block).transactionsFrom(_a);
} }
u256 Client::stateAt(Address _a, u256 _l, int _block) const u256 Client::stateAt(Address _a, u256 _l, BlockNumber _block) const
{ {
return asOf(_block).storage(_a, _l); return asOf(_block).storage(_a, _l);
} }
bytes Client::codeAt(Address _a, int _block) const bytes Client::codeAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).code(_a); return asOf(_block).code(_a);
} }

21
libethereum/Client.h

@ -225,11 +225,11 @@ public:
virtual void flushTransactions() override; virtual void flushTransactions() override;
/// Makes the given call. Nothing is recorded into the state. /// Makes the given call. Nothing is recorded into the state.
virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) override; virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = PendingBlock) override;
/// Does the given creation. Nothing is recorded into the state. /// Does the given creation. Nothing is recorded into the state.
/// @returns the pair of the Address of the created contract together with its code. /// @returns the pair of the Address of the created contract together with its code.
virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) override; virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = PendingBlock) override;
/// Makes the given call. Nothing is recorded into the state. This cheats by creating a null address and endowing it with a lot of ETH. /// Makes the given call. Nothing is recorded into the state. This cheats by creating a null address and endowing it with a lot of ETH.
ExecutionResult call(Address _dest, bytes const& _data = bytes(), u256 _gas = 125000, u256 _value = 0, u256 _gasPrice = 1 * ether); ExecutionResult call(Address _dest, bytes const& _data = bytes(), u256 _gas = 125000, u256 _value = 0, u256 _gasPrice = 1 * ether);
@ -244,11 +244,11 @@ public:
using Interface::codeAt; using Interface::codeAt;
using Interface::storageAt; using Interface::storageAt;
virtual u256 balanceAt(Address _a, int _block) const; virtual u256 balanceAt(Address _a, BlockNumber _block) const;
virtual u256 countAt(Address _a, int _block) const; virtual u256 countAt(Address _a, BlockNumber _block) const;
virtual u256 stateAt(Address _a, u256 _l, int _block) const; virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const;
virtual bytes codeAt(Address _a, int _block) const; virtual bytes codeAt(Address _a, BlockNumber _block) const;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const; virtual std::map<u256, u256> storageAt(Address _a, BlockNumber _block) const;
virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override; virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;
virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override; virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override;
@ -282,11 +282,11 @@ public:
/// Differences between transactions. /// Differences between transactions.
using Interface::diff; using Interface::diff;
virtual StateDiff diff(unsigned _txi, h256 _block) const; virtual StateDiff diff(unsigned _txi, h256 _block) const;
virtual StateDiff diff(unsigned _txi, int _block) const; virtual StateDiff diff(unsigned _txi, BlockNumber _block) const;
/// Get a list of all active addresses. /// Get a list of all active addresses.
using Interface::addresses; using Interface::addresses;
virtual std::vector<Address> addresses(int _block) const; virtual std::vector<Address> addresses(BlockNumber _block) const;
/// Get the remaining gas limit in this block. /// Get the remaining gas limit in this block.
virtual u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); } virtual u256 gasLimitRemaining() const { return m_postMine.gasLimitRemaining(); }
@ -383,7 +383,8 @@ private:
/// Return the actual block number of the block with the given int-number (positive is the same, INT_MIN is genesis block, < 0 is negative age, thus -1 is most recently mined, 0 is pending. /// Return the actual block number of the block with the given int-number (positive is the same, INT_MIN is genesis block, < 0 is negative age, thus -1 is most recently mined, 0 is pending.
unsigned numberOf(int _b) const; unsigned numberOf(int _b) const;
State asOf(int _h) const; /// Returns the state object for the full block (i.e. the terminal state) for index _h.
/// Works properly with LatestBlock and PendingBlock.
State asOf(unsigned _h) const; State asOf(unsigned _h) const;
VersionChecker m_vc; ///< Dummy object to check & update the protocol version. VersionChecker m_vc; ///< Dummy object to check & update the protocol version.

22
libethereum/Interface.h

@ -73,16 +73,16 @@ public:
virtual void flushTransactions() = 0; virtual void flushTransactions() = 0;
/// Makes the given call. Nothing is recorded into the state. /// Makes the given call. Nothing is recorded into the state.
virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) = 0; virtual ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = 0) = 0;
/// Does the given creation. Nothing is recorded into the state. /// Does the given creation. Nothing is recorded into the state.
/// @returns the pair of the Address of the created contract together with its code. /// @returns the pair of the Address of the created contract together with its code.
virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) = 0; virtual ExecutionResult create(Secret _secret, u256 _value, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, BlockNumber _blockNumber = 0) = 0;
// [STATE-QUERY API] // [STATE-QUERY API]
int getDefault() const { return m_default; } int getDefault() const { return m_default; }
void setDefault(int _block) { m_default = _block; } void setDefault(BlockNumber _block) { m_default = _block; }
u256 balanceAt(Address _a) const { return balanceAt(_a, m_default); } u256 balanceAt(Address _a) const { return balanceAt(_a, m_default); }
u256 countAt(Address _a) const { return countAt(_a, m_default); } u256 countAt(Address _a) const { return countAt(_a, m_default); }
@ -90,11 +90,11 @@ public:
bytes codeAt(Address _a) const { return codeAt(_a, m_default); } bytes codeAt(Address _a) const { return codeAt(_a, m_default); }
std::map<u256, u256> storageAt(Address _a) const { return storageAt(_a, m_default); } std::map<u256, u256> storageAt(Address _a) const { return storageAt(_a, m_default); }
virtual u256 balanceAt(Address _a, int _block) const = 0; virtual u256 balanceAt(Address _a, BlockNumber _block) const = 0;
virtual u256 countAt(Address _a, int _block) const = 0; virtual u256 countAt(Address _a, BlockNumber _block) const = 0;
virtual u256 stateAt(Address _a, u256 _l, int _block) const = 0; virtual u256 stateAt(Address _a, u256 _l, BlockNumber _block) const = 0;
virtual bytes codeAt(Address _a, int _block) const = 0; virtual bytes codeAt(Address _a, BlockNumber _block) const = 0;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const = 0; virtual std::map<u256, u256> storageAt(Address _a, BlockNumber _block) const = 0;
// [LOGS API] // [LOGS API]
@ -135,11 +135,11 @@ public:
/// Differences between transactions. /// Differences between transactions.
StateDiff diff(unsigned _txi) const { return diff(_txi, m_default); } StateDiff diff(unsigned _txi) const { return diff(_txi, m_default); }
virtual StateDiff diff(unsigned _txi, h256 _block) const = 0; virtual StateDiff diff(unsigned _txi, h256 _block) const = 0;
virtual StateDiff diff(unsigned _txi, int _block) const = 0; virtual StateDiff diff(unsigned _txi, BlockNumber _block) const = 0;
/// Get a list of all active addresses. /// Get a list of all active addresses.
virtual Addresses addresses() const { return addresses(m_default); } virtual Addresses addresses() const { return addresses(m_default); }
virtual Addresses addresses(int _block) const = 0; virtual Addresses addresses(BlockNumber _block) const = 0;
/// Get the fee associated for a transaction with the given data. /// Get the fee associated for a transaction with the given data.
template <class T> static bigint txGas(T const& _data, u256 _gas = 0) { bigint ret = c_txGas + _gas; for (auto i: _data) ret += i ? c_txDataNonZeroGas : c_txDataZeroGas; return ret; } template <class T> static bigint txGas(T const& _data, u256 _gas = 0) { bigint ret = c_txGas + _gas; for (auto i: _data) ret += i ? c_txDataNonZeroGas : c_txDataZeroGas; return ret; }
@ -177,7 +177,7 @@ public:
virtual MineProgress miningProgress() const = 0; virtual MineProgress miningProgress() const = 0;
protected: protected:
int m_default = -1; int m_default = PendingBlock;
}; };
class Watch; class Watch;

27
libethereum/LogFilter.cpp

@ -46,6 +46,33 @@ h256 LogFilter::sha3() const
return dev::sha3(s.out()); return dev::sha3(s.out());
} }
static bool isNoLater(RelativeBlock _logBlockRelation, u256 _logBlockNumber, unsigned _latest)
{
if (_latest == PendingBlock)
return true;
else if (_latest == LatestBlock)
return _logBlockRelation == RelativeBlock::Latest;
else
return _logBlockNumber <= _latest;
}
static bool isNoEarlier(RelativeBlock _logBlockRelation, u256 _logBlockNumber, unsigned _earliest)
{
if (_earliest == PendingBlock)
return _logBlockRelation == RelativeBlock::Pending;
else if (_earliest == LatestBlock)
return true;
else
return _logBlockNumber >= _earliest;
}
bool LogFilter::envelops(RelativeBlock _logBlockRelation, u256 _logBlockNumber) const
{
return
isNoLater(_logBlockRelation, _logBlockNumber, m_latest) &&
isNoEarlier(_logBlockRelation, _logBlockNumber, m_earliest);
}
bool LogFilter::matches(LogBloom _bloom) const bool LogFilter::matches(LogBloom _bloom) const
{ {
if (m_addresses.size()) if (m_addresses.size())

11
libethereum/LogFilter.h

@ -45,14 +45,15 @@ class State;
class LogFilter class LogFilter
{ {
public: public:
LogFilter(int _earliest = 0, int _latest = -1): m_earliest(_earliest), m_latest(_latest) {} LogFilter(unsigned _earliest = 0, unsigned _latest = PendingBlock): m_earliest(_earliest), m_latest(_latest) {}
void streamRLP(RLPStream& _s) const; void streamRLP(RLPStream& _s) const;
h256 sha3() const; h256 sha3() const;
int earliest() const { return m_earliest; } unsigned earliest() const { return m_earliest; }
int latest() const { return m_latest; } unsigned latest() const { return m_latest; }
bool envelops(RelativeBlock _logBlockRelation, u256 _logBlockNumber) const;
std::vector<LogBloom> bloomPossibilities() const; std::vector<LogBloom> bloomPossibilities() const;
bool matches(LogBloom _bloom) const; bool matches(LogBloom _bloom) const;
bool matches(State const& _s, unsigned _i) const; bool matches(State const& _s, unsigned _i) const;
@ -68,8 +69,8 @@ public:
private: private:
AddressSet m_addresses; AddressSet m_addresses;
std::array<h256Set, 4> m_topics; std::array<h256Set, 4> m_topics;
int m_earliest = 0; unsigned m_earliest = 0;
int m_latest = -1; unsigned m_latest = LatestBlock;
}; };
} }

2
libethereum/Transaction.cpp

@ -46,6 +46,8 @@ TransactionException dev::eth::toTransactionException(VMException const& _e)
return TransactionException::BadJumpDestination; return TransactionException::BadJumpDestination;
if (!!dynamic_cast<OutOfGas const*>(&_e)) if (!!dynamic_cast<OutOfGas const*>(&_e))
return TransactionException::OutOfGas; return TransactionException::OutOfGas;
if (!!dynamic_cast<OutOfStack const*>(&_e))
return TransactionException::OutOfStack;
if (!!dynamic_cast<StackUnderflow const*>(&_e)) if (!!dynamic_cast<StackUnderflow const*>(&_e))
return TransactionException::StackUnderflow; return TransactionException::StackUnderflow;
return TransactionException::Unknown; return TransactionException::Unknown;

1
libethereum/Transaction.h

@ -56,6 +56,7 @@ enum class TransactionException
BadInstruction, BadInstruction,
BadJumpDestination, BadJumpDestination,
OutOfGas, ///< Ran out of gas executing code of the transaction. OutOfGas, ///< Ran out of gas executing code of the transaction.
OutOfStack, ///< Ran out of stack executing code of the transaction.
StackUnderflow StackUnderflow
}; };

4
libevm/ExtVMFace.h

@ -63,10 +63,10 @@ using LogEntries = std::vector<LogEntry>;
struct LocalisedLogEntry: public LogEntry struct LocalisedLogEntry: public LogEntry
{ {
LocalisedLogEntry() {} LocalisedLogEntry() {}
LocalisedLogEntry(LogEntry const& _le, unsigned _number, h256 _sha3 = {}): LogEntry(_le), number(_number), sha3(_sha3) {} LocalisedLogEntry(LogEntry const& _le, unsigned _number, h256 _transactionHash = h256()): LogEntry(_le), number(_number), transactionHash(_transactionHash) {}
unsigned number = 0; unsigned number = 0;
h256 sha3; h256 transactionHash;
}; };
using LocalisedLogEntries = std::vector<LocalisedLogEntry>; using LocalisedLogEntries = std::vector<LocalisedLogEntry>;

6
libevm/VM.cpp

@ -36,6 +36,7 @@ struct InstructionMetric
{ {
int gasPriceTier; int gasPriceTier;
int args; int args;
int ret;
}; };
static array<InstructionMetric, 256> metrics() static array<InstructionMetric, 256> metrics()
@ -46,12 +47,15 @@ static array<InstructionMetric, 256> metrics()
InstructionInfo inst = instructionInfo((Instruction)i); InstructionInfo inst = instructionInfo((Instruction)i);
s_ret[i].gasPriceTier = inst.gasPriceTier; s_ret[i].gasPriceTier = inst.gasPriceTier;
s_ret[i].args = inst.args; s_ret[i].args = inst.args;
s_ret[i].ret = inst.ret;
} }
return s_ret; return s_ret;
} }
bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps) bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
{ {
m_stack.reserve((unsigned)c_stackLimit);
static const array<InstructionMetric, 256> c_metrics = metrics(); static const array<InstructionMetric, 256> c_metrics = metrics();
auto memNeed = [](u256 _offset, dev::u256 _size) { return _size ? (bigint)_offset + _size : (bigint)0; }; auto memNeed = [](u256 _offset, dev::u256 _size) { return _size ? (bigint)_offset + _size : (bigint)0; };
@ -89,7 +93,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
// should work, but just seems to result in immediate errorless exit on initial execution. yeah. weird. // should work, but just seems to result in immediate errorless exit on initial execution. yeah. weird.
//m_onFail = std::function<void()>(onOperation); //m_onFail = std::function<void()>(onOperation);
require(metric.args); require(metric.args, metric.ret);
auto onOperation = [&]() auto onOperation = [&]()
{ {

2
libevm/VM.h

@ -56,7 +56,7 @@ public:
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final; virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
void require(u256 _n) { if (m_stack.size() < _n) { if (m_onFail) m_onFail(); BOOST_THROW_EXCEPTION(StackUnderflow() << RequirementError((bigint)_n, (bigint)m_stack.size())); } } void require(u256 _n, u256 _d) { if (m_stack.size() < _n) { if (m_onFail) m_onFail(); BOOST_THROW_EXCEPTION(StackUnderflow() << RequirementError((bigint)_n, (bigint)m_stack.size())); } if (m_stack.size() - _n + _d >= c_stackLimit) { if (m_onFail) m_onFail(); BOOST_THROW_EXCEPTION(OutOfStack() << RequirementError((bigint)(_d - _n), (bigint)m_stack.size())); } }
void requireMem(unsigned _n) { if (m_temp.size() < _n) { m_temp.resize(_n); } } void requireMem(unsigned _n) { if (m_temp.size() < _n) { m_temp.resize(_n); } }
u256 curPC() const { return m_curPC; } u256 curPC() const { return m_curPC; }

1
libevm/VMFace.h

@ -31,6 +31,7 @@ struct BreakPointHit: virtual VMException {};
struct BadInstruction: virtual VMException {}; struct BadInstruction: virtual VMException {};
struct BadJumpDestination: virtual VMException {}; struct BadJumpDestination: virtual VMException {};
struct OutOfGas: virtual VMException {}; struct OutOfGas: virtual VMException {};
struct OutOfStack: virtual VMException {};
struct StackUnderflow: virtual VMException {}; struct StackUnderflow: virtual VMException {};
/// EVM Virtual Machine interface /// EVM Virtual Machine interface

31
libjsqrc/ethereumjs/dist/ethereum.js

@ -1527,7 +1527,7 @@ var addEventsToContract = function (contract, desc, address) {
var parser = eventImpl.outputParser(e); var parser = eventImpl.outputParser(e);
return parser(data); return parser(data);
}; };
return web3.eth.filter(o, undefined, undefined, outputFormatter); return web3.eth.filter(o, undefined, undefined, outputFormatter);
}; };
// this property should be used by eth.filter to check if object is an event // this property should be used by eth.filter to check if object is an event
@ -2005,16 +2005,6 @@ var getOptions = function (options) {
options.toBlock = options.latest; options.toBlock = options.latest;
} }
if (options.skip) {
console.warn('"skip" is deprecated, is "offset" instead');
options.offset = options.skip;
}
if (options.max) {
console.warn('"max" is deprecated, is "limit" instead');
options.limit = options.max;
}
// make sure topics, get converted to hex // make sure topics, get converted to hex
if(options.topics instanceof Array) { if(options.topics instanceof Array) {
options.topics = options.topics.map(function(topic){ options.topics = options.topics.map(function(topic){
@ -2022,13 +2012,18 @@ var getOptions = function (options) {
}); });
} }
var asBlockNumber = function(n) {
if (n == null)
return null;
if (n == 'latest' || n == 'pending')
return n;
return utils.toHex(n);
};
// evaluate lazy properties // evaluate lazy properties
return { return {
fromBlock: utils.toHex(options.fromBlock), fromBlock: asBlockNumber(options.fromBlock),
toBlock: utils.toHex(options.toBlock), toBlock: asBlockNumber(options.toBlock),
limit: utils.toHex(options.limit),
offset: utils.toHex(options.offset),
to: options.to, to: options.to,
address: options.address, address: options.address,
topics: options.topics topics: options.topics
@ -2053,9 +2048,9 @@ var filter = function(options, implementation, formatter) {
// call the callbacks // call the callbacks
var onMessages = function (messages) { var onMessages = function (messages) {
messages.forEach(function (message) { messages.forEach(function (message) {
message = formatter ? formatter(message) : message; message = formatter ? formatter(message) : message;
callbacks.forEach(function (callback) { callbacks.forEach(function (callback) {
callback(message); callback(message);
}); });
}); });
}; };
@ -2855,4 +2850,4 @@ module.exports = web3;
},{"./lib/solidity/abi":1,"./lib/web3":6,"./lib/web3/contract":7,"./lib/web3/httpprovider":13,"./lib/web3/qtsync":16}]},{},["web3"]) },{"./lib/solidity/abi":1,"./lib/web3":6,"./lib/web3/contract":7,"./lib/web3/httpprovider":13,"./lib/web3/qtsync":16}]},{},["web3"])
//# sourceMappingURL=ethereum.js.map //# sourceMappingURL=ethereum.js.map

8
libjsqrc/ethereumjs/dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/dist/ethereum.min.js

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/lib/web3/contract.js

@ -159,7 +159,7 @@ var addEventsToContract = function (contract, desc, address) {
var parser = eventImpl.outputParser(e); var parser = eventImpl.outputParser(e);
return parser(data); return parser(data);
}; };
return web3.eth.filter(o, undefined, undefined, outputFormatter); return web3.eth.filter(o, undefined, undefined, outputFormatter);
}; };
// this property should be used by eth.filter to check if object is an event // this property should be used by eth.filter to check if object is an event

27
libjsqrc/ethereumjs/lib/web3/filter.js

@ -64,16 +64,6 @@ var getOptions = function (options) {
options.toBlock = options.latest; options.toBlock = options.latest;
} }
if (options.skip) {
console.warn('"skip" is deprecated, is "offset" instead');
options.offset = options.skip;
}
if (options.max) {
console.warn('"max" is deprecated, is "limit" instead');
options.limit = options.max;
}
// make sure topics, get converted to hex // make sure topics, get converted to hex
if(options.topics instanceof Array) { if(options.topics instanceof Array) {
options.topics = options.topics.map(function(topic){ options.topics = options.topics.map(function(topic){
@ -81,13 +71,18 @@ var getOptions = function (options) {
}); });
} }
var asBlockNumber = function(n) {
if (n == null)
return null;
if (n == 'latest' || n == 'pending')
return n;
return utils.toHex(n);
};
// evaluate lazy properties // evaluate lazy properties
return { return {
fromBlock: utils.toHex(options.fromBlock), fromBlock: asBlockNumber(options.fromBlock),
toBlock: utils.toHex(options.toBlock), toBlock: asBlockNumber(options.toBlock),
limit: utils.toHex(options.limit),
offset: utils.toHex(options.offset),
to: options.to, to: options.to,
address: options.address, address: options.address,
topics: options.topics topics: options.topics
@ -112,9 +107,9 @@ var filter = function(options, implementation, formatter) {
// call the callbacks // call the callbacks
var onMessages = function (messages) { var onMessages = function (messages) {
messages.forEach(function (message) { messages.forEach(function (message) {
message = formatter ? formatter(message) : message; message = formatter ? formatter(message) : message;
callbacks.forEach(function (callback) { callbacks.forEach(function (callback) {
callback(message); callback(message);
}); });
}); });
}; };

45
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -112,18 +112,20 @@ static Json::Value toJson(dev::eth::TransactionSkeleton const& _t)
static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e)
{ {
Json::Value res; Json::Value res;
if (_e.transactionHash)
res["data"] = toJS(_e.data); {
res["address"] = toJS(_e.address); res["data"] = toJS(_e.data);
res["topics"] = Json::Value(Json::arrayValue); res["address"] = toJS(_e.address);
for (auto const& t: _e.topics) res["topics"] = Json::Value(Json::arrayValue);
res["topics"].append(toJS(t)); for (auto const& t: _e.topics)
res["number"] = _e.number; res["topics"].append(toJS(t));
res["hash"] = toJS(_e.sha3); res["number"] = _e.number;
res["hash"] = toJS(_e.transactionHash);
}
return res; return res;
} }
static Json::Value toJson(dev::eth::LocalisedLogEntries const& _es) // commented to avoid warning. Uncomment once in use @ poC-7. static Json::Value toJson(dev::eth::LocalisedLogEntries const& _es)
{ {
Json::Value res(Json::arrayValue); Json::Value res(Json::arrayValue);
for (dev::eth::LocalisedLogEntry const& e: _es) for (dev::eth::LocalisedLogEntry const& e: _es)
@ -139,6 +141,18 @@ static Json::Value toJson(map<u256, u256> const& _storage)
return res; return res;
} }
static unsigned toBlockNumber(std::string const& _js)
{
if (_js == "latest")
return LatestBlock;
else if (_js == "earliest")
return 0;
else if (_js == "pending")
return PendingBlock;
else
return (unsigned)jsToInt(_js);
}
static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to avoid warning. Uncomment once in use @ PoC-7. static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to avoid warning. Uncomment once in use @ PoC-7.
{ {
dev::eth::LogFilter filter; dev::eth::LogFilter filter;
@ -147,9 +161,9 @@ static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to
// check only !empty. it should throw exceptions if input params are incorrect // check only !empty. it should throw exceptions if input params are incorrect
if (!_json["fromBlock"].empty()) if (!_json["fromBlock"].empty())
filter.withEarliest(jsToInt(_json["fromBlock"].asString())); filter.withEarliest(toBlockNumber(_json["fromBlock"].asString()));
if (!_json["toBlock"].empty()) if (!_json["toBlock"].empty())
filter.withLatest(jsToInt(_json["toBlock"].asString())); filter.withLatest(toBlockNumber(_json["toBlock"].asString()));
if (!_json["address"].empty()) if (!_json["address"].empty())
{ {
if (_json["address"].isArray()) if (_json["address"].isArray())
@ -227,15 +241,6 @@ static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message
return res; return res;
} }
static int toBlockNumber(string const& _string)
{
if (_string.compare("latest") == 0)
return -1;
if (_string.compare("pending") == 0)
return 0;
return jsToInt(_string);
}
WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts): WebThreeStubServerBase::WebThreeStubServerBase(AbstractServerConnector& _conn, vector<dev::KeyPair> const& _accounts):
AbstractWebThreeStubServer(_conn), m_accounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this))) AbstractWebThreeStubServer(_conn), m_accounts(make_shared<AccountHolder>(bind(&WebThreeStubServerBase::client, this)))
{ {

18
mix/MixClient.cpp

@ -283,7 +283,7 @@ void MixClient::flushTransactions()
{ {
} }
dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
u256 n; u256 n;
State temp; State temp;
@ -299,7 +299,7 @@ dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _
return lastExecution().result; return lastExecution().result;
} }
dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{ {
u256 n; u256 n;
State temp; State temp;
@ -315,27 +315,27 @@ dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes c
return lastExecution().result; return lastExecution().result;
} }
u256 MixClient::balanceAt(Address _a, int _block) const u256 MixClient::balanceAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).balance(_a); return asOf(_block).balance(_a);
} }
u256 MixClient::countAt(Address _a, int _block) const u256 MixClient::countAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).transactionsFrom(_a); return asOf(_block).transactionsFrom(_a);
} }
u256 MixClient::stateAt(Address _a, u256 _l, int _block) const u256 MixClient::stateAt(Address _a, u256 _l, BlockNumber _block) const
{ {
return asOf(_block).storage(_a, _l); return asOf(_block).storage(_a, _l);
} }
bytes MixClient::codeAt(Address _a, int _block) const bytes MixClient::codeAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).code(_a); return asOf(_block).code(_a);
} }
std::map<u256, u256> MixClient::storageAt(Address _a, int _block) const std::map<u256, u256> MixClient::storageAt(Address _a, BlockNumber _block) const
{ {
return asOf(_block).storage(_a); return asOf(_block).storage(_a);
} }
@ -567,13 +567,13 @@ eth::StateDiff MixClient::diff(unsigned _txi, h256 _block) const
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
eth::StateDiff MixClient::diff(unsigned _txi, int _block) const eth::StateDiff MixClient::diff(unsigned _txi, BlockNumber _block) const
{ {
State st = asOf(_block); State st = asOf(_block);
return st.fromPending(_txi).diff(st.fromPending(_txi + 1)); return st.fromPending(_txi).diff(st.fromPending(_txi + 1));
} }
Addresses MixClient::addresses(int _block) const Addresses MixClient::addresses(BlockNumber _block) const
{ {
Addresses ret; Addresses ret;
for (auto const& i: asOf(_block).addresses()) for (auto const& i: asOf(_block).addresses())

19
mix/MixClient.h

@ -25,6 +25,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <libethcore/Common.h>
#include <libethereum/Interface.h> #include <libethereum/Interface.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include "MachineStates.h" #include "MachineStates.h"
@ -52,13 +53,13 @@ public:
Address submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override; Address submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override;
void inject(bytesConstRef _rlp) override; void inject(bytesConstRef _rlp) override;
void flushTransactions() override; void flushTransactions() override;
dev::eth::ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) override; dev::eth::ExecutionResult call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber) override;
dev::eth::ExecutionResult create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) override; dev::eth::ExecutionResult create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, eth::BlockNumber _blockNumber) override;
u256 balanceAt(Address _a, int _block) const override; u256 balanceAt(Address _a, eth::BlockNumber _block) const override;
u256 countAt(Address _a, int _block) const override; u256 countAt(Address _a, eth::BlockNumber _block) const override;
u256 stateAt(Address _a, u256 _l, int _block) const override; u256 stateAt(Address _a, u256 _l, eth::BlockNumber _block) const override;
bytes codeAt(Address _a, int _block) const override; bytes codeAt(Address _a, eth::BlockNumber _block) const override;
std::map<u256, u256> storageAt(Address _a, int _block) const override; std::map<u256, u256> storageAt(Address _a, eth::BlockNumber _block) const override;
eth::LocalisedLogEntries logs(unsigned _watchId) const override; eth::LocalisedLogEntries logs(unsigned _watchId) const override;
eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override; eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override;
unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override; unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override;
@ -79,8 +80,8 @@ public:
unsigned number() const override; unsigned number() const override;
eth::Transactions pending() const override; eth::Transactions pending() const override;
eth::StateDiff diff(unsigned _txi, h256 _block) const override; eth::StateDiff diff(unsigned _txi, h256 _block) const override;
eth::StateDiff diff(unsigned _txi, int _block) const override; eth::StateDiff diff(unsigned _txi, eth::BlockNumber _block) const override;
Addresses addresses(int _block) const override; Addresses addresses(eth::BlockNumber _block) const override;
u256 gasLimitRemaining() const override; u256 gasLimitRemaining() const override;
void setAddress(Address _us) override; void setAddress(Address _us) override;
Address address() const override; Address address() const override;

12
neth/main.cpp

@ -954,7 +954,7 @@ int main(int argc, char** argv)
auto s = t.receiveAddress() ? auto s = t.receiveAddress() ?
boost::format(" %1% %2%> %3%: %4% [%5%]") % boost::format(" %1% %2%> %3%: %4% [%5%]") %
toString(t.safeSender()) % toString(t.safeSender()) %
(c->codeAt(t.receiveAddress(), 0).size() ? '*' : '-') % (c->codeAt(t.receiveAddress(), PendingBlock).size() ? '*' : '-') %
toString(t.receiveAddress()) % toString(t.receiveAddress()) %
toString(formatBalance(t.value())) % toString(formatBalance(t.value())) %
toString((unsigned)t.nonce()) : toString((unsigned)t.nonce()) :
@ -979,7 +979,7 @@ int main(int argc, char** argv)
auto s = t.receiveAddress() ? auto s = t.receiveAddress() ?
boost::format("%1% %2%> %3%: %4% [%5%]") % boost::format("%1% %2%> %3%: %4% [%5%]") %
toString(t.safeSender()) % toString(t.safeSender()) %
(c->codeAt(t.receiveAddress(), 0).size() ? '*' : '-') % (c->codeAt(t.receiveAddress(), PendingBlock).size() ? '*' : '-') %
toString(t.receiveAddress()) % toString(t.receiveAddress()) %
toString(formatBalance(t.value())) % toString(formatBalance(t.value())) %
toString((unsigned)t.nonce()) : toString((unsigned)t.nonce()) :
@ -999,25 +999,25 @@ int main(int argc, char** argv)
int cc = 1; int cc = 1;
auto acs = c->addresses(); auto acs = c->addresses();
for (auto const& i: acs) for (auto const& i: acs)
if (c->codeAt(i, 0).size()) if (c->codeAt(i, PendingBlock).size())
{ {
auto s = boost::format("%1%%2% : %3% [%4%]") % auto s = boost::format("%1%%2% : %3% [%4%]") %
toString(i) % toString(i) %
pretty(i, c->postState()) % pretty(i, c->postState()) %
toString(formatBalance(c->balanceAt(i))) % toString(formatBalance(c->balanceAt(i))) %
toString((unsigned)c->countAt(i, 0)); toString((unsigned)c->countAt(i, PendingBlock));
mvwaddnstr(contractswin, cc++, x, s.str().c_str(), qwidth); mvwaddnstr(contractswin, cc++, x, s.str().c_str(), qwidth);
if (cc > qheight - 2) if (cc > qheight - 2)
break; break;
} }
for (auto const& i: acs) for (auto const& i: acs)
if (c->codeAt(i, 0).empty()) if (c->codeAt(i, PendingBlock).empty())
{ {
auto s = boost::format("%1%%2% : %3% [%4%]") % auto s = boost::format("%1%%2% : %3% [%4%]") %
toString(i) % toString(i) %
pretty(i, c->postState()) % pretty(i, c->postState()) %
toString(formatBalance(c->balanceAt(i))) % toString(formatBalance(c->balanceAt(i))) %
toString((unsigned)c->countAt(i, 0)); toString((unsigned)c->countAt(i, PendingBlock));
mvwaddnstr(addswin, y++, x, s.str().c_str(), width / 2 - 4); mvwaddnstr(addswin, y++, x, s.str().c_str(), width / 2 - 4);
if (y > height * 3 / 5 - 4) if (y > height * 3 / 5 - 4)
break; break;

20
third/MainWin.cpp

@ -212,13 +212,13 @@ void Main::installWatches()
void Main::installNameRegWatch() void Main::installNameRegWatch()
{ {
ethereum()->uninstallWatch(m_nameRegFilter); ethereum()->uninstallWatch(m_nameRegFilter);
m_nameRegFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, 0))), [=](LocalisedLogEntries const&){ onNameRegChange(); }); m_nameRegFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, PendingBlock))), [=](LocalisedLogEntries const&){ onNameRegChange(); });
} }
void Main::installCurrenciesWatch() void Main::installCurrenciesWatch()
{ {
ethereum()->uninstallWatch(m_currenciesFilter); ethereum()->uninstallWatch(m_currenciesFilter);
m_currenciesFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, 1))), [=](LocalisedLogEntries const&){ onCurrenciesChange(); }); m_currenciesFilter = installWatch(dev::eth::LogFilter().address(u160(ethereum()->stateAt(c_config, LatestBlock))), [=](LocalisedLogEntries const&){ onCurrenciesChange(); });
} }
void Main::installBalancesWatch() void Main::installBalancesWatch()
@ -226,8 +226,8 @@ void Main::installBalancesWatch()
dev::eth::LogFilter tf; dev::eth::LogFilter tf;
vector<Address> altCoins; vector<Address> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1)); Address coinsAddr = right160(ethereum()->stateAt(c_config, LatestBlock));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1))); altCoins.push_back(right160(ethereum()->stateAt(coinsAddr, i + 1)));
for (auto i: m_myKeys) for (auto i: m_myKeys)
for (auto c: altCoins) for (auto c: altCoins)
@ -294,7 +294,7 @@ QString Main::pretty(dev::Address _a) const
{ {
h256 n; h256 n;
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, PendingBlock))
n = ethereum()->stateAt(nameReg, (u160)(_a)); n = ethereum()->stateAt(nameReg, (u160)(_a));
return fromRaw(n); return fromRaw(n);
@ -321,7 +321,7 @@ Address Main::fromString(QString const& _a) const
memset(n.data() + sn.size(), 0, 32 - sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size());
if (_a.size()) if (_a.size())
{ {
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, PendingBlock))
if (h256 a = ethereum()->stateAt(nameReg, n)) if (h256 a = ethereum()->stateAt(nameReg, n))
return right160(a); return right160(a);
} }
@ -350,10 +350,10 @@ QString Main::lookup(QString const& _a) const
*/ */
h256 ret; h256 ret;
if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, 0)) if (h160 dnsReg = (u160)ethereum()->stateAt(c_config, 4, PendingBlock))
ret = ethereum()->stateAt(dnsReg, n); ret = ethereum()->stateAt(dnsReg, n);
/* if (!ret) /* if (!ret)
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0, PendingBlock))
ret = ethereum()->stateAt(nameReg, n2); ret = ethereum()->stateAt(nameReg, n2);
*/ */
if (ret && !((u256)ret >> 32)) if (ret && !((u256)ret >> 32))
@ -476,8 +476,8 @@ void Main::refreshBalances()
ui->ourAccounts->clear(); ui->ourAccounts->clear();
u256 totalBalance = 0; u256 totalBalance = 0;
map<Address, pair<QString, u256>> altCoins; map<Address, pair<QString, u256>> altCoins;
Address coinsAddr = right160(ethereum()->stateAt(c_config, 1)); Address coinsAddr = right160(ethereum()->stateAt(c_config, LatestBlock));
for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, 0); ++i) for (unsigned i = 0; i < ethereum()->stateAt(coinsAddr, PendingBlock); ++i)
altCoins[right160(ethereum()->stateAt(coinsAddr, ethereum()->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(ethereum()->stateAt(coinsAddr, i + 1)), 0); altCoins[right160(ethereum()->stateAt(coinsAddr, ethereum()->stateAt(coinsAddr, i + 1)))] = make_pair(fromRaw(ethereum()->stateAt(coinsAddr, i + 1)), 0);
for (auto i: m_myKeys) for (auto i: m_myKeys)
{ {

Loading…
Cancel
Save