From e33ae2e9469d35027a1588d8f5c035d9083c8114 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 21 Apr 2015 18:09:41 +0200 Subject: [PATCH] bugfix: contract type as param. --- mix/ClientModel.cpp | 16 ++++++---------- mix/ClientModel.h | 1 + mix/qml/Debugger.qml | 5 +---- mix/qml/QAddressView.qml | 13 +++++++++++-- mix/qml/StateDialog.qml | 14 +++++++++++--- mix/qml/StructView.qml | 11 ++++++++--- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 901478659..52e95a3f7 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -237,7 +237,7 @@ void ClientModel::executeSequence(vector const& _sequence, { try { - map deployedContracts; + vector
deployedContracts; onStateReset(); for (TransactionSettings const& transaction: _sequence) { @@ -249,7 +249,7 @@ void ClientModel::executeSequence(vector const& _sequence, TransactionSettings stdTransaction = transaction; stdTransaction.gasAuto = true; Address address = deployContract(stdContractCode, stdTransaction); - deployedContracts.insert(make_pair(address, transaction.contractId)); + deployedContracts.push_back(address); m_stdContractAddresses[stdTransaction.contractId] = address; m_stdContractNames[address] = stdTransaction.contractId; } @@ -284,13 +284,9 @@ void ClientModel::executeSequence(vector const& _sequence, QVariant value = transaction.parameterValues.value(p->name()); if (type->type().type == SolidityType::Type::Address && value.toString().startsWith("<")) { - for (auto it = deployedContracts.begin(); it != deployedContracts.end(); ++it) - { - if (value.toString().remove("<").remove(">") == it->second) - { - value = QVariant(QString::fromStdString(toHex(it->first.ref()))); - } - } + value = value.toString().remove("<").remove(">"); + QStringList nb = value.toString().split(" - "); + value = QVariant(QString::fromStdString("0x" + toHex(deployedContracts.at(nb.back().toInt()).ref()))); } encoder.encode(value, type->type()); } @@ -300,7 +296,7 @@ void ClientModel::executeSequence(vector const& _sequence, bytes param = encoder.encodedData(); contractCode.insert(contractCode.end(), param.begin(), param.end()); Address newAddress = deployContract(contractCode, transaction); - deployedContracts.insert(make_pair(newAddress, transaction.contractId)); + deployedContracts.push_back(newAddress); auto contractAddressIter = m_contractAddresses.find(transaction.contractId); if (contractAddressIter == m_contractAddresses.end() || newAddress != contractAddressIter->second) { diff --git a/mix/ClientModel.h b/mix/ClientModel.h index dcb62f55d..63e21d67d 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -71,6 +71,7 @@ struct TransactionSettings QString stdContractUrl; /// Sender Secret sender; + }; diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index 87a27cf79..32d790009 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -211,7 +211,7 @@ Rectangle { anchors.top: parent.top anchors.topMargin: 15 anchors.left: parent.left; - anchors.leftMargin: machineStates.sideMargin + anchors.leftMargin: machineStates.sideMargin width: debugScrollArea.width - machineStates.sideMargin * 2 - 20 ; spacing: machineStates.sideMargin @@ -641,9 +641,6 @@ Rectangle { } } - - - Rectangle { id: storageRect diff --git a/mix/qml/QAddressView.qml b/mix/qml/QAddressView.qml index e7327e96e..2c1d43276 100644 --- a/mix/qml/QAddressView.qml +++ b/mix/qml/QAddressView.qml @@ -1,12 +1,13 @@ import QtQuick 2.0 import QtQuick.Controls 1.3 +import QtQuick.Controls.Styles 1.3 Item { property alias value: textinput.text property alias contractCreationTr: ctrModel id: editRoot - height: 30 + height: 20 width: 200 SourceSansProBold @@ -16,6 +17,7 @@ Item function init() { + trCombobox.visible = ctrModel.count > 1; //index 0 is a blank value. if (value.indexOf("<") === 0) { for (var k = 0; k < ctrModel.count; k++) @@ -34,11 +36,13 @@ Item Rectangle { anchors.fill: parent radius: 4 + anchors.verticalCenter: parent.verticalCenter + height: 20 TextInput { id: textinput text: value width: parent.width - height: 30 + height: parent.width wrapMode: Text.WrapAnywhere clip: true font.family: boldFont.name @@ -70,9 +74,12 @@ Item id: trCombobox model: ctrModel textRole: "functionId" + height: 20 anchors.verticalCenter: parent.verticalCenter anchors.left: textinput.parent.right + anchors.leftMargin: 3 onCurrentIndexChanged: { + trCombobox.selected = false; if (currentText === "") return; else if (currentText !== " - ") @@ -81,7 +88,9 @@ Item trCombobox.selected = true; } else if (textinput.text.indexOf("<") === 0) + { textinput.text = ""; + } } } } diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index a2f9a09b7..93fe4464e 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -366,7 +366,17 @@ Dialog { DefaultLabel { Layout.preferredWidth: 150 - text: styleData.row >= 0 ? transactionsModel.get(styleData.row).functionId : "" + text: { + if (styleData.row >= 0) + { + if (transactionsModel.get(styleData.row).label !== undefined) + return transactionsModel.get(styleData.row).label; + else if (transactionsModel.get(styleData.row).functionId !== undefined) + return transactionsModel.get(styleData.row).functionId; + } + else + return ""; + } } } } @@ -378,7 +388,6 @@ Dialog { } } } - } RowLayout @@ -456,7 +465,6 @@ Dialog { onAccepted: { var item = transactionDialog.getItem(); - if (transactionDialog.transactionIndex < transactionsModel.count) { transactionsModel.set(transactionDialog.transactionIndex, item); stateTransactions[transactionDialog.transactionIndex] = item; diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index c94ab6a20..32ce3d618 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -20,7 +20,7 @@ Column RowLayout { id: row - height: 20 + (members[index].type.category === QSolidityType.Struct ? (20 * members[index].type.members.length) : 0) + height: 30 + (members[index].type.category === QSolidityType.Struct ? (20 * members[index].type.members.length) : 0) Layout.fillWidth: true DefaultLabel { height: 20 @@ -70,13 +70,18 @@ Column if (ptype.category === QSolidityType.Address) { item.contractCreationTr.append({"functionId": " - "}); + var trCr = -1; for (var k = 0; k < transactionsModel.count; k++) { if (k >= transactionIndex) break; var tr = transactionsModel.get(k); - if (tr.functionId === tr.contractId && modelData.type.name === qsTr("contract") + " " + tr.contractId) - item.contractCreationTr.append(tr); + if (tr.functionId === tr.contractId) + { + trCr++; + if (modelData.type.name === qsTr("contract") + " " + tr.contractId) + item.contractCreationTr.append({ "functionId": tr.contractId + " - " + trCr }); + } } item.value = getValue(); item.init();