Browse Source

Merge pull request #1413 from yann300/bugFix

Mix - Bug fixes
cl-refactor
Gav Wood 10 years ago
parent
commit
ff82fb1361
  1. 21
      mix/ClientModel.cpp
  2. 16
      mix/ContractCallDataEncoder.cpp
  3. 6
      mix/DebuggingStateWrapper.h
  4. 10
      mix/MixClient.cpp
  5. 20
      mix/qml/CodeEditorView.qml
  6. 25
      mix/qml/LogsPane.qml
  7. 1
      mix/qml/QHashTypeView.qml
  8. 1
      mix/qml/QIntTypeView.qml
  9. 1
      mix/qml/QStringTypeView.qml
  10. 5
      mix/qml/StatusPane.qml
  11. 11
      mix/qml/StructView.qml
  12. 5
      mix/qml/WebCodeEditor.qml
  13. 6
      mix/qml/html/WebContainer.html
  14. 16
      mix/qml/html/codeeditor.js

21
mix/ClientModel.cpp

@ -242,7 +242,12 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
break;
}
if (!f)
BOOST_THROW_EXCEPTION(FunctionNotFoundException() << FunctionName(transaction.functionId.toStdString()));
{
emit runFailed("Function '" + transaction.functionId + tr("' not found. Please check transactions or the contract code."));
m_running = false;
emit runStateChanged();
return;
}
if (!transaction.functionId.isEmpty())
encoder.encode(f);
for (QVariableDeclaration const* p: f->parametersList())
@ -269,7 +274,12 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
{
auto contractAddressIter = m_contractAddresses.find(transaction.contractId);
if (contractAddressIter == m_contractAddresses.end())
BOOST_THROW_EXCEPTION(dev::Exception() << dev::errinfo_comment("Contract not deployed: " + transaction.contractId.toStdString()));
{
emit runFailed("Contract '" + transaction.contractId + tr(" not deployed.") + "' " + tr(" Cannot call ") + transaction.functionId);
m_running = false;
emit runStateChanged();
return;
}
callContract(contractAddressIter->second, encoder.encodedData(), transaction);
}
}
@ -283,7 +293,6 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
std::cerr << boost::current_exception_diagnostic_information();
emit runFailed(QString::fromStdString(boost::current_exception_diagnostic_information()));
}
catch(std::exception const& e)
{
std::cerr << boost::current_exception_diagnostic_information();
@ -376,6 +385,8 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t)
for(auto l: solLocals)
if (l.first < (int)s.stack.size())
{
if (l.second->type()->name().startsWith("mapping"))
break; //mapping type not yet managed
localDeclarations.push_back(QVariant::fromValue(l.second));
localValues[l.second->name()] = formatValue(l.second->type()->type(), s.stack[l.first]);
}
@ -400,6 +411,8 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t)
storageDec = new QVariableDeclaration(debugData, storageIter.value().name.toStdString(), storageIter.value().type);
storageDeclarations[storageDec->name()] = storageDec;
}
if (storageDec->type()->name().startsWith("mapping"))
break; //mapping type not yet managed
storageDeclarationList.push_back(QVariant::fromValue(storageDec));
storageValues[storageDec->name()] = formatValue(storageDec->type()->type(), st.second);
}
@ -408,7 +421,7 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t)
storage["values"] = storageValues;
prevInstructionIndex = instructionIndex;
solState = new QSolState(debugData, std::move(storage), std::move(solCallStack), std::move(locals), instruction.getLocation().start, instruction.getLocation().end);
solState = new QSolState(debugData, std::move(storage), std::move(solCallStack), std::move(locals), instruction.getLocation().start, instruction.getLocation().end, QString::fromUtf8(instruction.getLocation().sourceName->c_str()));
}
states.append(QVariant::fromValue(new QMachineState(debugData, instructionIndex, s, codes[s.codeIndex], data[s.dataIndex], solState)));

16
mix/ContractCallDataEncoder.cpp

@ -76,18 +76,22 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QVariant const& _data, Solidi
unsigned const alignSize = 32;
QString src = _data.toString();
bytes result;
if (src.length() >= 2 && ((src.startsWith("\"") && src.endsWith("\"")) || (src.startsWith("\'") && src.endsWith("\'"))))
{
if ((src.startsWith("\"") && src.endsWith("\"")) || (src.startsWith("\'") && src.endsWith("\'")))
src = src.remove(src.length() - 1, 1).remove(0, 1);
QByteArray bytesAr = src.toLocal8Bit();
result = bytes(bytesAr.begin(), bytesAr.end());
}
else if (src.startsWith("0x"))
QRegExp rx("[a-z]+");
if (src.startsWith("0x"))
{
result = fromHex(src.toStdString().substr(2));
if (_type.type != SolidityType::Type::Bytes)
result = padded(result, alignSize);
}
else if (rx.indexIn(src.toLower(), 0) != -1)
{
QByteArray bytesAr = src.toLocal8Bit();
result = bytes(bytesAr.begin(), bytesAr.end());
}
else
{
bigint i(src.toStdString());

6
mix/DebuggingStateWrapper.h

@ -65,10 +65,11 @@ class QSolState: public QObject
Q_PROPERTY(QVariantMap locals MEMBER m_locals CONSTANT)
Q_PROPERTY(int start MEMBER m_start CONSTANT)
Q_PROPERTY(int end MEMBER m_end CONSTANT)
Q_PROPERTY(QString sourceName MEMBER m_sourceName CONSTANT)
public:
QSolState(QObject* _parent, QVariantMap&& _storage, QVariantList&& _callStack, QVariantMap&& _locals, int _start, int _end):
QObject(_parent), m_storage(_storage), m_callStack(_callStack), m_locals(_locals), m_start(_start), m_end(_end)
QSolState(QObject* _parent, QVariantMap&& _storage, QVariantList&& _callStack, QVariantMap&& _locals, int _start, int _end, QString _sourceName):
QObject(_parent), m_storage(_storage), m_callStack(_callStack), m_locals(_locals), m_start(_start), m_end(_end), m_sourceName(_sourceName)
{ }
private:
@ -77,6 +78,7 @@ private:
QVariantMap m_locals;
int m_start;
int m_end;
QString m_sourceName;
};
/**

10
mix/MixClient.cpp

@ -44,7 +44,7 @@ namespace mix
const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
const u256 c_mixGenesisDifficulty = c_minimumDifficulty; //TODO: make it lower for Mix somehow
bytes MixBlockChain::createGenesisBlock(h256 _stateRoot)
{
RLPStream block(3);
@ -80,6 +80,7 @@ void MixClient::resetState(std::map<Secret, u256> _accounts)
SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB);
accountState.init();
m_userAccounts.clear();
std::map<Address, Account> genesisState;
for (auto account: _accounts)
{
@ -260,8 +261,8 @@ Address MixClient::submitTransaction(Secret _secret, u256 _endowment, bytes cons
dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{
State temp = asOf(_blockNumber);
(void)_blockNumber;
State temp = asOf(eth::PendingBlock);
u256 n = temp.transactionsFrom(toAddress(_secret));
Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);
bytes rlp = t.rlp();
@ -272,11 +273,12 @@ dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _
dev::eth::ExecutionResult MixClient::create(Secret _secret, u256 _value, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber)
{
(void)_blockNumber;
u256 n;
State temp;
{
ReadGuard lr(x_state);
temp = asOf(_blockNumber);
temp = asOf(eth::PendingBlock);
n = temp.transactionsFrom(toAddress(_secret));
}
Transaction t(_value, _gasPrice, _gas, _data, n, _secret);

20
mix/qml/CodeEditorView.qml

@ -67,10 +67,26 @@ Item {
return null;
}
function highlightExecution(documentId, location) {
function highlightExecution(documentId, location)
{
var editor = getEditor(documentId);
if (editor)
editor.highlightExecution(location);
{
if (documentId !== location.sourceName)
findAndHightlight(location.start, location.end, location.sourceName)
else
editor.highlightExecution(location);
}
}
// Execution is not in the current document. Try:
// Open targeted document and hightlight (TODO) or
// Warn user that file is not available
function findAndHightlight(start, end, sourceName)
{
var editor = getEditor(currentDocumentId);
if (editor)
editor.showWarning(qsTr("Currently debugging in " + sourceName + ". Source not available."));
}
function editingContract() {

25
mix/qml/LogsPane.qml

@ -153,31 +153,6 @@ Rectangle
}
}
ToolButton {
id: compilationButton
checkable: true
height: LogsPaneStyle.generic.layout.headerButtonHeight
anchors.verticalCenter: parent.verticalCenter
checked: false
onCheckedChanged: {
proxyModel.toogleFilter("compilation")
}
tooltip: qsTr("Compilation")
style:
ButtonStyle {
label:
Item {
DefaultLabel {
font.family: LogsPaneStyle.generic.layout.logLabelFont
font.pointSize: Style.absoluteSize(-3)
color: "#5391d8"
anchors.centerIn: parent
text: qsTr("Compilation")
}
}
}
}
DefaultTextField
{
id: searchBox

1
mix/qml/QHashTypeView.qml

@ -15,7 +15,6 @@ Item
Rectangle {
anchors.fill: parent
radius: 4
color: "#f7f7f7"
TextInput {
id: textinput
text: value

1
mix/qml/QIntTypeView.qml

@ -16,7 +16,6 @@ Item
Rectangle {
anchors.fill: parent
radius: 4
color: "#f7f7f7"
TextInput {
id: textinput
text: value

1
mix/qml/QStringTypeView.qml

@ -15,7 +15,6 @@ Item
Rectangle {
anchors.fill: parent
radius: 4
color: "#f7f7f7"
TextInput {
id: textinput
text: value

5
mix/qml/StatusPane.qml

@ -24,7 +24,6 @@ Rectangle {
var errorInfo = ErrorLocationFormater.extractErrorInfo(message, true);
status.text = errorInfo.errorLocation + " " + errorInfo.errorDetail;
debugImg.state = "";
errorMessage(status.text, "Compilation");
}
debugRunActionIcon.enabled = codeModel.hasContract;
}
@ -77,9 +76,9 @@ Rectangle {
function format(_message)
{
var formatted = _message.match(/(?:<dev::eth::)(.+)(?:>)/);
if (formatted === null)
if (formatted)
formatted = _message.match(/(?:<dev::)(.+)(?:>)/);
if (formatted.length > 1)
if (formatted && formatted.length > 1)
formatted = formatted[1];
else
return _message;

11
mix/qml/StructView.qml

@ -24,24 +24,24 @@ Column
height: 20
id: typeLabel
text: modelData.type.name
Layout.preferredWidth: 60
anchors.verticalCenter: parent.verticalCenter
}
DefaultLabel {
id: nameLabel
text: modelData.name
Layout.preferredWidth: 100
anchors.verticalCenter: parent.verticalCenter
}
DefaultLabel {
id: equalLabel
text: "="
Layout.preferredWidth: 15
anchors.verticalCenter: parent.verticalCenter
}
Loader
{
id: typeLoader
Layout.preferredWidth: 150
anchors.verticalCenter: parent.verticalCenter
sourceComponent:
{
var t = modelData.type.category;
@ -63,7 +63,8 @@ Column
var ptype = members[index].type;
var pname = members[index].name;
var vals = value;
if (ptype.category === QSolidityType.Struct && !item.members) {
if (ptype.category === QSolidityType.Struct && !item.members)
{
item.value = getValue();
item.members = ptype.members;
}

5
mix/qml/WebCodeEditor.qml

@ -45,6 +45,11 @@ Item {
editorBrowser.runJavaScript("highlightExecution(" + location.start + "," + location.end + ")");
}
function showWarning(content) {
if (initialized)
editorBrowser.runJavaScript("showWarning('" + content + "')");
}
function getBreakpoints() {
return currentBreakpoints;
}

6
mix/qml/html/WebContainer.html

@ -23,9 +23,9 @@ updateContracts = function(contracts) {
var contractProto = window.web3.eth.contract(contracts[c].interface);
var contract = new contractProto(contracts[c].address);
window.contracts[c] = {
address: c.address,
interface: c.interface,
contract: contract,
address: contracts[c].address,
interface: contracts[c].interface,
contract: contract
};
}
}

16
mix/qml/html/codeeditor.js

@ -134,6 +134,8 @@ highlightExecution = function(start, end) {
executionMark.clear();
if (start === 0 && end + 1 === editor.getValue().length)
return; // Do not hightlight the whole document.
if (debugWarning)
debugWarning.clear();
executionMark = editor.markText(editor.posFromIndex(start), editor.posFromIndex(end), { className: "CodeMirror-exechighlight" });
}
@ -148,6 +150,20 @@ isClean = function()
return editor.isClean(changeId);
}
var debugWarning = null;
showWarning = function(content)
{
if (executionMark)
executionMark.clear();
if (debugWarning)
debugWarning.clear();
var node = document.createElement("div");
node.id = "annotation"
node.innerHTML = content;
node.className = "CodeMirror-errorannotation-context";
debugWarning = editor.addLineWidget(0, node, { coverGutter: false, above: true });
}
var annotation = null;
var compilationCompleteBool = true;
compilationError = function(line, column, content)

Loading…
Cancel
Save