Skip to content

Commit

Permalink
- send tr run exception to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Nov 27, 2015
1 parent 93be7fc commit 5158efd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
6 changes: 3 additions & 3 deletions qml/BlockChain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,15 @@ ColumnLayout {
tr.logs = _r.logs
tr.isCall = false
tr.sender = _r.sender
tr.outOfGas = _r.outOfGas
tr.exception = _r.exception
tr.returnParameters = _r.returnParameters
var trModel = blockModel.getTransaction(blockIndex, trIndex)
trModel.returned = _r.returned
trModel.recordIndex = _r.recordIndex
trModel.logs = _r.logs
trModel.sender = _r.sender
trModel.returnParameters = _r.returnParameters
trModel.outOfGas = _r.outOfGas
trModel.exception = _r.exception
blockModel.setTransaction(blockIndex, trIndex, trModel)
blockChainRepeater.select(blockIndex, trIndex, -1)
txExecuted(blockIndex, trIndex, -1)
Expand Down Expand Up @@ -630,7 +630,7 @@ ColumnLayout {
itemTr.recordIndex = _r.recordIndex
itemTr.logs = _r.logs
itemTr.returnParameters = _r.returnParameters
itemTr.outOfGas = _r.outOfGas
itemTr.exception = _r.exception
if (!itemTr.isContractCreation)
itemTr.parameters = _r.parameters
else if (transactionDialog.parameters)
Expand Down
5 changes: 3 additions & 2 deletions qml/Transaction.qml
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ ColumnLayout
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: {
if (!tx.outOfGas)

if (!tx || tx.exception === "None")
return ""
else
{
color = "red"
font.italic = true
return "out of gas"
return tx.exception
}
}
}
Expand Down
1 change: 1 addition & 0 deletions qml/TransactionDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ Dialog {
{
scenarioLoaded = true
var item = getItem()
item.gasAuto = true
gasEstimationClient.executeTr(item);
txRequested = true
}
Expand Down
29 changes: 27 additions & 2 deletions src/ClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ RecordLogEntry* ClientModel::lastBlock() const
strGas << blockInfo.gasUsed();
stringstream strNumber;
strNumber << blockInfo.number();
RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap(), QVariantMap(), QVariantList(), RecordLogEntry::TxSource::MixGui, false);
RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap(), QVariantMap(), QVariantList(), RecordLogEntry::TxSource::MixGui, RecordLogEntry::TransactionException::None);
QQmlEngine::setObjectOwnership(record, QQmlEngine::JavaScriptOwnership);
return record;
}
Expand All @@ -824,40 +824,65 @@ void ClientModel::onNewTransaction(RecordLogEntry::TxSource _source)
{
ExecutionResult const& tr = m_client->lastExecution();

RecordLogEntry::TransactionException exception = RecordLogEntry::TransactionException::None;
switch (tr.excepted)
{
case TransactionException::None:
break;
case TransactionException::NotEnoughCash:
{
exception = RecordLogEntry::TransactionException::NotEnoughCash;
emit runFailed("Insufficient balance");
break;
}
case TransactionException::OutOfGasIntrinsic:
case TransactionException::OutOfGasBase:
case TransactionException::OutOfGas:
{
exception = RecordLogEntry::TransactionException::OutOfGas;
emit runFailed("Not enough gas");
break;
}
case TransactionException::BlockGasLimitReached:
{
exception = RecordLogEntry::TransactionException::BlockGasLimitReached;
emit runFailed("Block gas limit reached");
break;
}
case TransactionException::BadJumpDestination:
{
exception = RecordLogEntry::TransactionException::BadJumpDestination;
emit runFailed("Solidity exception (bad jump)");
break;
}
case TransactionException::OutOfStack:
{
exception = RecordLogEntry::TransactionException::OutOfStack;
emit runFailed("Out of stack");
break;
}

case TransactionException::StackUnderflow:
{
exception = RecordLogEntry::TransactionException::StackUnderflow;
emit runFailed("Stack underflow");
break;
}
//these should not happen in mix
case TransactionException::Unknown:
case TransactionException::BadInstruction:
case TransactionException::InvalidSignature:
case TransactionException::InvalidNonce:
case TransactionException::InvalidFormat:
case TransactionException::BadRLP:
{
exception = RecordLogEntry::TransactionException::Unknown;
emit runFailed("Internal execution error");
break;
}

}


unsigned block = m_client->number() + 1;
unsigned recordIndex = tr.executonIndex;
Expand Down Expand Up @@ -1010,7 +1035,7 @@ void ClientModel::onNewTransaction(RecordLogEntry::TxSource _source)
label = address;

RecordLogEntry* log = new RecordLogEntry(recordIndex, transactionIndex, contract, function, value, address, returned, tr.isCall(), RecordLogEntry::RecordType::Transaction,
gasUsed, sender, label, inputParameters, returnParameters, logs, _source, tr.excepted == TransactionException::OutOfGasBase);
gasUsed, sender, label, inputParameters, returnParameters, logs, _source, exception);
if (transactionIndex != QObject::tr("Call"))
m_lastTransactionIndex = transactionIndex;

Expand Down
35 changes: 30 additions & 5 deletions src/ClientModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <atomic>
#include <map>
#include <QMetaEnum>
#include <QString>
#include <QQmlListProperty>
#include <QVariantMap>
Expand Down Expand Up @@ -98,6 +99,7 @@ struct TransactionSettings
class RecordLogEntry: public QObject
{
Q_OBJECT
Q_ENUMS(TransactionException)
Q_ENUMS(TxSource)
Q_ENUMS(RecordType)
/// Recording index
Expand Down Expand Up @@ -132,8 +134,8 @@ class RecordLogEntry: public QObject
Q_PROPERTY(QVariantList logs MEMBER m_logs CONSTANT)
/// logs
Q_PROPERTY(TxSource source MEMBER m_source CONSTANT)
/// out of gas
Q_PROPERTY(bool outOfGas MEMBER m_outOfGas CONSTANT)
/// exception
Q_PROPERTY(QString exception MEMBER m_strException CONSTANT)

public:
enum RecordType
Expand All @@ -148,13 +150,35 @@ class RecordLogEntry: public QObject
MixGui
};

enum TransactionException
{
None,
Unknown,
BadRLP,
InvalidFormat,
OutOfGasIntrinsic, ///< Too little gas to pay for the base transaction cost.
InvalidSignature,
InvalidNonce,
NotEnoughCash,
OutOfGasBase, ///< Too little gas to pay for the base transaction cost.
BlockGasLimitReached,
BadInstruction,
BadJumpDestination,
OutOfGas, ///< Ran out of gas executing code of the transaction.
OutOfStack, ///< Ran out of stack executing code of the transaction.
StackUnderflow
};

RecordLogEntry():
m_recordIndex(0), m_call(false), m_type(RecordType::Transaction) {}
RecordLogEntry(unsigned _recordIndex, QString _transactionIndex, QString _contract, QString _function, QString _value, QString _address, QString _returned, bool _call, RecordType _type, QString _gasUsed,
QString _sender, QString _label, QVariantMap _inputParameters, QVariantMap _returnParameters, QVariantList _logs, TxSource _source, bool _outOfGas):
QString _sender, QString _label, QVariantMap _inputParameters, QVariantMap _returnParameters, QVariantList _logs, TxSource _source, TransactionException _exception):
m_recordIndex(_recordIndex), m_transactionIndex(_transactionIndex), m_contract(_contract), m_function(_function), m_value(_value), m_address(_address), m_returned(_returned), m_call(_call), m_type(_type), m_gasUsed(_gasUsed),
m_sender(_sender), m_label(_label), m_inputParameters(_inputParameters), m_returnParameters(_returnParameters), m_logs(_logs), m_source(_source), m_outOfGas(_outOfGas) {}
m_sender(_sender), m_label(_label), m_inputParameters(_inputParameters), m_returnParameters(_returnParameters), m_logs(_logs), m_source(_source), m_exception(_exception)
{
QMetaEnum ex = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("TransactionException"));
m_strException = QString(ex.valueToKey(m_exception));
}

private:
unsigned m_recordIndex;
Expand All @@ -173,7 +197,8 @@ class RecordLogEntry: public QObject
QVariantMap m_returnParameters;
QVariantList m_logs;
TxSource m_source;
bool m_outOfGas;
TransactionException m_exception;
QString m_strException;
};

/**
Expand Down

0 comments on commit 5158efd

Please sign in to comment.