From b78634637bc78d877120041d7b38a2aa9c357af9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 22 Mar 2015 19:40:04 +0100 Subject: [PATCH] Transact now prevents executing failing transactions. --- alethzero/Transact.cpp | 45 ++++++++++++++++++++++++------------------ alethzero/Transact.h | 1 + 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/alethzero/Transact.cpp b/alethzero/Transact.cpp index 35a9c47d2..c9cd5e7b4 100644 --- a/alethzero/Transact.cpp +++ b/alethzero/Transact.cpp @@ -186,6 +186,7 @@ void Transact::rejigData() { if (!ethereum()) return; + m_allGood = true; if (isCreation()) { string src = ui->data->toPlainText().toStdString(); @@ -210,11 +211,11 @@ void Transact::rejigData() { ostringstream error; solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", compiler); - solidity = "

Solidity

" + QString::fromStdString(error.str()).toHtmlEscaped() + "
"; + errors.push_back("Solidity: " + error.str()); } catch (...) { - solidity = "

Solidity

Uncaught exception.
"; + errors.push_back("Solidity: Uncaught exception"); } } #ifndef _MSC_VER @@ -223,8 +224,6 @@ void Transact::rejigData() try { m_data = dev::asBytes(::compile(src)); - for (auto& i: errors) - i = "(LLL " + i + ")"; } catch (string const& err) { @@ -237,22 +236,18 @@ void Transact::rejigData() m_data = compileLLL(src, ui->optimize->isChecked(), &errors); if (errors.empty()) { - auto asmcode = compileLLLToAsm(src, false); - lll = "

Pre

" + QString::fromStdString(asmcode).toHtmlEscaped() + "
"; - if (ui->optimize->isChecked()) - { - asmcode = compileLLLToAsm(src, true); - lll = "

Opt

" + QString::fromStdString(asmcode).toHtmlEscaped() + "
" + lll; - } + auto asmcode = compileLLLToAsm(src, ui->optimize->isChecked()); + lll = "

LLL

" + QString::fromStdString(asmcode).toHtmlEscaped() + "
"; } } - QString errs; + QString htmlErrors; qint64 gasNeeded = 0; if (errors.size()) { - errs = "

Errors

"; + htmlErrors = "

Errors

"; for (auto const& i: errors) - errs.append("
" + QString::fromStdString(i).toHtmlEscaped() + "
"); + htmlErrors.append("
" + QString::fromStdString(i).toHtmlEscaped() + "
"); + m_allGood = false; } else { @@ -260,26 +255,32 @@ void Transact::rejigData() { auto s = findSecret(value() + ethereum()->gasLimitRemaining() * gasPrice()); if (!s) - errs += "
ERROR No single account contains enough gas.
"; + htmlErrors += "
WARNING No single account contains a comfortable amount of gas.
"; // 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("
INFO Gas required: %1 base, %2 init
").arg(base).arg((qint64)er.gasUsed - base); + htmlErrors += QString("
INFO Gas required: %1 base, %2 init
").arg(base).arg((qint64)er.gasUsed - base); if (er.excepted != TransactionException::None) - errs += "
ERROR " + QString::fromStdString(toString(er.excepted)) + "
"; + { + htmlErrors += "
ERROR " + QString::fromStdString(toString(er.excepted)) + "
"; + m_allGood = false; + } if (er.codeDeposit == CodeDeposit::Failed) - errs += "
ERROR Code deposit failed due to insufficient gas
"; + { + htmlErrors += "
ERROR Code deposit failed due to insufficient gas
"; + m_allGood = false; + } } } else gasNeeded = (qint64)Interface::txGas(m_data, 0); } - ui->code->setHtml(errs + lll + solidity + "

Code

" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped() + "

Hex

" Div(Mono) + QString::fromStdString(toHex(m_data)) + ""); + ui->code->setHtml(htmlErrors + lll + solidity + "

Code

" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped() + "

Hex

" Div(Mono) + QString::fromStdString(toHex(m_data)) + ""); if (ui->gas->value() == ui->gas->minimum()) { @@ -296,6 +297,7 @@ void Transact::rejigData() } else { + m_allGood = true; auto base = (qint64)Interface::txGas(m_data, 0); m_data = parseData(ui->data->toPlainText().toStdString()); auto to = m_context->fromString(ui->destination->currentText()); @@ -326,7 +328,10 @@ void Transact::rejigData() errs += QString("
INFO Gas required: %1 base, %2 exec
").arg(base).arg((qint64)er.gasUsed - base); if (er.excepted != TransactionException::None) + { errs += "
ERROR " + QString::fromStdString(toString(er.excepted)) + "
"; + m_allGood = false; + } } } else @@ -356,6 +361,8 @@ void Transact::rejigData() ui->code->setHtml(errs + "

NatSpec

" + natspec + "

Dump

" + QString::fromStdString(dev::memDump(m_data, 8, true)) + "

Hex

" + Div(Mono) + QString::fromStdString(toHex(m_data)) + ""); } updateFee(); + + ui->send->setEnabled(m_allGood); } Secret Transact::findSecret(u256 _totalReq) const diff --git a/alethzero/Transact.h b/alethzero/Transact.h index b3702a6ae..0ad9d5653 100644 --- a/alethzero/Transact.h +++ b/alethzero/Transact.h @@ -80,4 +80,5 @@ private: dev::eth::Client* m_ethereum = nullptr; Context* m_context = nullptr; NatSpecFace* m_natSpecDB = nullptr; + bool m_allGood = false; };