From 0f7459490bbdfc1580e3e76238b20129606fa7a7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 22 Jan 2015 19:58:54 +0100 Subject: [PATCH 1/6] Manage parameters in constructor #820 --- mix/ClientModel.cpp | 36 ++++++++++------- mix/ClientModel.h | 9 ++++- mix/QContractDefinition.cpp | 1 + mix/QContractDefinition.h | 4 ++ mix/qml.qrc | 2 + mix/qml/ProjectModel.qml | 1 - mix/qml/StateDialog.qml | 19 ++------- mix/qml/StateList.qml | 16 ++++++-- mix/qml/TransactionDialog.qml | 68 +++++++++++++++++++++++++++++---- mix/qml/js/QEtherHelper.js | 8 ++++ mix/qml/js/TransactionHelper.js | 13 +++++++ mix/qml/main.qml | 33 +++++++++++++++- 12 files changed, 164 insertions(+), 46 deletions(-) create mode 100644 mix/qml/js/QEtherHelper.js create mode 100644 mix/qml/js/TransactionHelper.js diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index eb61c8554..e91985f3f 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -67,11 +67,10 @@ void ClientModel::debugState(QVariantMap _state) QVariantList transactions = _state.value("transactions").toList(); std::vector transactionSequence; - + TransactionSettings constructorTr; for (auto const& t: transactions) { QVariantMap transaction = t.toMap(); - QString functionId = transaction.value("functionId").toString(); u256 gas = (qvariant_cast(transaction.value("gas")))->toU256Wei(); u256 value = (qvariant_cast(transaction.value("value")))->toU256Wei(); @@ -80,14 +79,20 @@ void ClientModel::debugState(QVariantMap _state) TransactionSettings transactionSettings(functionId, value, gas, gasPrice); for (auto p = params.cbegin(); p != params.cend(); ++p) - transactionSettings.parameterValues.insert(std::make_pair(p.key(), (qvariant_cast(p.value()))->toU256Wei())); + { + QBigInt* param = qvariant_cast(p.value()); + transactionSettings.parameterValues.insert(std::make_pair(p.key(), boost::get(param->internalValue()))); + } - transactionSequence.push_back(transactionSettings); + if (transaction.value("executeConstructor").toBool()) + constructorTr = transactionSettings; + else + transactionSequence.push_back(transactionSettings); } - executeSequence(transactionSequence, balance); + executeSequence(transactionSequence, balance, constructorTr); } -void ClientModel::executeSequence(std::vector const& _sequence, u256 _balance) +void ClientModel::executeSequence(std::vector const& _sequence, u256 _balance, TransactionSettings const& ctrTransaction) { if (m_running) throw (std::logic_error("debugging already running")); @@ -137,7 +142,7 @@ void ClientModel::executeSequence(std::vector const& _seque //run contract creation first m_client->resetState(_balance); - ExecutionResult debuggingContent = deployContract(contractCode); + ExecutionResult debuggingContent = deployContract(contractCode, ctrTransaction); Address address = debuggingContent.contractAddress; for (unsigned i = 0; i < _sequence.size(); ++i) debuggingContent = callContract(address, transactonData.at(i), _sequence.at(i)); @@ -189,13 +194,18 @@ void ClientModel::showDebugError(QString const& _error) m_context->displayMessageDialog(tr("Debugger"), _error); } -ExecutionResult ClientModel::deployContract(bytes const& _code) +ExecutionResult ClientModel::deployContract(bytes const& _code, TransactionSettings const& ctrTransaction) { - u256 gasPrice = 10000000000000; - u256 gas = 125000; - u256 amount = 100; - - Address contractAddress = m_client->transact(m_client->userAccount().secret(), amount, _code, gas, gasPrice); + Address contractAddress; + if (!ctrTransaction.isEmpty()) + contractAddress = m_client->transact(m_client->userAccount().secret(), ctrTransaction.value, _code, ctrTransaction.gas, ctrTransaction.gasPrice); + else + { + u256 gasPrice = 10000000000000; + u256 gas = 125000; + u256 amount = 100; + contractAddress = m_client->transact(m_client->userAccount().secret(), amount, _code, gas, gasPrice); + } ExecutionResult r = m_client->lastExecutionResult(); r.contractAddress = contractAddress; return r; diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 0e7f9c092..2e262c5dd 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -42,6 +42,7 @@ class AppContext; /// Backend transaction config class struct TransactionSettings { + TransactionSettings() {} TransactionSettings(QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice): functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {} @@ -55,6 +56,10 @@ struct TransactionSettings u256 gasPrice; /// Mapping from contract function parameter name to value std::map parameterValues; + +public: + /// @returns true if the functionId has not be set + bool isEmpty() const { return functionId.isNull() || functionId.isEmpty(); } }; @@ -100,8 +105,8 @@ signals: void dataAvailable(QList const& _returnParams = QList(), QList const& _wStates = QList(), AssemblyDebuggerData const& _code = AssemblyDebuggerData()); private: - void executeSequence(std::vector const& _sequence, u256 _balance); - ExecutionResult deployContract(bytes const& _code); + void executeSequence(std::vector const& _sequence, u256 _balance, TransactionSettings const& ctrTransaction = TransactionSettings()); + ExecutionResult deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); ExecutionResult callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); AppContext* m_context; diff --git a/mix/QContractDefinition.cpp b/mix/QContractDefinition.cpp index bee9cfe49..326becdbb 100644 --- a/mix/QContractDefinition.cpp +++ b/mix/QContractDefinition.cpp @@ -33,6 +33,7 @@ using namespace dev::mix; QContractDefinition::QContractDefinition(dev::solidity::ContractDefinition const* _contract): QBasicNodeDefinition(_contract) { + m_constructor = new QFunctionDefinition(_contract->getConstructor(), -1); auto interfaceFunctions = _contract->getInterfaceFunctions(); unsigned i = 0; for (auto it = interfaceFunctions.cbegin(); it != interfaceFunctions.cend(); ++it, ++i) diff --git a/mix/QContractDefinition.h b/mix/QContractDefinition.h index e9c618804..890b8bc0f 100644 --- a/mix/QContractDefinition.h +++ b/mix/QContractDefinition.h @@ -36,15 +36,19 @@ class QContractDefinition: public QBasicNodeDefinition { Q_OBJECT Q_PROPERTY(QQmlListProperty functions READ functions CONSTANT) + Q_PROPERTY(dev::mix::QFunctionDefinition* constructor READ constructor CONSTANT) public: QContractDefinition() {} QContractDefinition(solidity::ContractDefinition const* _contract); /// Get all the functions of the contract. QQmlListProperty functions() const { return QQmlListProperty(const_cast(this), const_cast(this)->m_functions); } + /// Get the constructor of the contract. + QFunctionDefinition* constructor() const { return m_constructor; } QList const& functionsList() const { return m_functions; } private: QList m_functions; + QFunctionDefinition* m_constructor; }; } diff --git a/mix/qml.qrc b/mix/qml.qrc index 169d1ebcb..f2fc339f5 100644 --- a/mix/qml.qrc +++ b/mix/qml.qrc @@ -43,5 +43,7 @@ qml/Ether.qml qml/EtherValue.qml qml/BigIntValue.qml + qml/js/QEtherHelper.js + qml/js/TransactionHelper.js diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 91a4a97ca..61b1d6f94 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -4,7 +4,6 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 import QtQuick.Dialogs 1.1 import Qt.labs.settings 1.0 - import "js/ProjectModel.js" as ProjectModelCode Item { diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index 55a4df14f..bff335e5d 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -3,6 +3,8 @@ import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.0 import org.ethereum.qml.QEther 1.0 +import "js/QEtherHelper.js" as QEtherHelper +import "js/TransactionHelper.js" as TransactionHelper Window { id: modalStateDialog @@ -118,27 +120,12 @@ Window { transactionDialog.open(index, transactionsModel.get(index)); } - function ether(_value, _unit) - { - var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml"); - var ether = etherComponent.createObject(modalStateDialog); - ether.setValue(_value); - ether.setUnit(_unit); - return ether; - } - function addTransaction() { // Set next id here to work around Qt bug // https://bugreports.qt-project.org/browse/QTBUG-41327 // Second call to signal handler would just edit the item that was just created, no harm done - var item = { - value: ether("0", QEther.Wei), - functionId: "", - gas: ether("125000", QEther.Wei), - gasPrice: ether("100000", QEther.Wei) - }; - + var item = TransactionHelper.defaultTransaction(); transactionDialog.open(transactionsModel.count, item); } diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index c3270bf20..bf8f727ce 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 1.1 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import org.ethereum.qml.QEther 1.0 +import "js/QEtherHelper.js" as QEtherHelper Rectangle { color: "#ededed" @@ -67,15 +68,22 @@ Rectangle { id: stateListModel function addState() { - var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml"); - var ether = etherComponent.createObject(stateListContainer); - ether.setValue("100000000000000000000000000"); - ether.setUnit(QEther.Wei); + var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); var item = { title: "", balance: ether, transactions: [] }; + + var ctorTr = { + value: QEtherHelper.createEther("100", QEther.Wei), + functionId: qsTr("Constructor"), + gas: QEtherHelper.createEther("125000", QEther.Wei), + gasPrice: QEtherHelper.createEther("10000000000000", QEther.Wei), + executeConstructor: true + }; + + item.transactions.push(ctorTr); stateDialog.open(stateListModel.count, item); } diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 22995d66b..ad431d54c 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.0 import org.ethereum.qml.QEther 1.0 +import "js/TransactionHelper.js" as TransactionHelper Window { id: modalTransactionDialog @@ -18,15 +19,29 @@ Window { property alias transactionValue: valueField.value; property alias functionId: functionComboBox.currentText; property var itemParams; + property bool isConstructorTransaction; + property bool useTransactionDefaultValue: false signal accepted; function open(index, item) { + valueLabel.visible = !useTransactionDefaultValue; + valueField.visible = !useTransactionDefaultValue; + gasLabel.visible = !useTransactionDefaultValue; + gasFieldRect.visible = !useTransactionDefaultValue; + gasPriceLabel.visible = !useTransactionDefaultValue; + gasPriceRect.visible = !useTransactionDefaultValue; + transactionIndex = index; gasField.value = item.gas; gasPriceField.value = item.gasPrice; valueField.value = item.value; var functionId = item.functionId; + isConstructorTransaction = item.executeConstructor; + functionLabel.visible = !item.executeConstructor; + functionComboBox.visible = !item.executeConstructor; + console.log(item.executeConstructor); + itemParams = item.parameters !== undefined ? item.parameters : {}; functionsModel.clear(); var functionIndex = -1; @@ -41,7 +56,18 @@ Window { functionIndex = 0; //@todo suggest unused funtion functionComboBox.currentIndex = functionIndex; - loadParameters(); + paramsModel.clear(); + if (!item.executeConstructor) + loadParameters(); + else + { + console.log("load ctro paramters"); + var parameters = codeModel.code.contract.constructor.parameters; + for (var p = 0; p < parameters.length; p++) { + var pname = parameters[p].name; + paramsModel.append({ name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value() : "" }); + } + } visible = true; valueField.focus = true; } @@ -49,7 +75,6 @@ Window { function loadParameters() { if (!paramsModel) return; - paramsModel.clear(); if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { var func = codeModel.code.contract.functions[functionComboBox.currentIndex]; var parameters = func.parameters; @@ -67,17 +92,37 @@ Window { function getItem() { - var item = { - functionId: transactionDialog.functionId, - gas: transactionDialog.gas, - gasPrice: transactionDialog.gasPrice, - value: transactionDialog.transactionValue, - parameters: {} + var item; + if (!useTransactionDefaultValue) + { + item = { + functionId: transactionDialog.functionId, + gas: transactionDialog.gas, + gasPrice: transactionDialog.gasPrice, + value: transactionDialog.transactionValue, + parameters: {}, + executeConstructor: isConstructorTransaction + }; + } + else + { + item = TransactionHelper.defaultTransaction(); + item.functionId = transactionDialog.functionId; + item.executeConstructor = isConstructorTransaction; } + + if (isConstructorTransaction) + item.functionId = qsTr("Constructor"); + for (var p = 0; p < transactionDialog.transactionParams.count; p++) { var parameter = transactionDialog.transactionParams.get(p); var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); var param = intComponent.createObject(modalTransactionDialog); + console.log(param); + console.log(JSON.stringify(param)); + console.log(item); + console.log(JSON.stringify(item)); + param.setValue(parameter.value); item.parameters[parameter.name] = param; } @@ -93,6 +138,7 @@ Window { columnSpacing: 10 Label { + id: functionLabel; text: qsTr("Function") } ComboBox { @@ -110,10 +156,12 @@ Window { } Label { + id: valueLabel text: qsTr("Value") } Rectangle { + id: valueFieldRect Layout.fillWidth: true Ether { id: valueField @@ -123,10 +171,12 @@ Window { } Label { + id: gasLabel text: qsTr("Gas") } Rectangle { + id: gasFieldRect Layout.fillWidth: true Ether { id: gasField @@ -136,10 +186,12 @@ Window { } Label { + id: gasPriceLabel text: qsTr("Gas price") } Rectangle { + id: gasPriceRect Layout.fillWidth: true Ether { id: gasPriceField diff --git a/mix/qml/js/QEtherHelper.js b/mix/qml/js/QEtherHelper.js new file mode 100644 index 000000000..9761b2f45 --- /dev/null +++ b/mix/qml/js/QEtherHelper.js @@ -0,0 +1,8 @@ +function createEther(_value, _unit, _parent) +{ + var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml"); + var ether = etherComponent.createObject(); + ether.setValue(_value); + ether.setUnit(_unit); + return ether; +} diff --git a/mix/qml/js/TransactionHelper.js b/mix/qml/js/TransactionHelper.js new file mode 100644 index 000000000..f404685cf --- /dev/null +++ b/mix/qml/js/TransactionHelper.js @@ -0,0 +1,13 @@ +Qt.include("QEtherHelper.js") + +function defaultTransaction() +{ + return { + value: createEther("0", QEther.Wei), + functionId: "", + gas: createEther("125000", QEther.Wei), + gasPrice: createEther("100000", QEther.Wei), + executeConstructor: false, + parameters: {} + }; +} diff --git a/mix/qml/main.qml b/mix/qml/main.qml index e234d6344..fb0977904 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -5,6 +5,9 @@ import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import CodeEditorExtensionManager 1.0 +import org.ethereum.qml.QEther 1.0 +import "js/QEtherHelper.js" as QEtherHelper +import "js/TransactionHelper.js" as TransactionHelper ApplicationWindow { id: mainApplication @@ -75,12 +78,38 @@ ApplicationWindow { text: "&Run" shortcut: "F5" onTriggered: { - mainContent.ensureRightView(); - clientModel.debugDeployment(); + + if (codeModel.code.contract.constructor.parameters.length === 0) + { + mainContent.ensureRightView(); + clientModel.debugDeployment(); + } + else + { + var item = TransactionHelper.defaultTransaction(); + item.executeConstructor = true; + transactionDialog.open(0, item); + } } enabled: codeModel.hasContract && !clientModel.running; } + TransactionDialog { + id: transactionDialog + onAccepted: { + mainContent.ensureRightView(); + var item = transactionDialog.getItem(); + var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); + var state = { + title: "", + balance: ether, + transactions: [item] + }; + clientModel.debugState(state); + } + useTransactionDefaultValue: true + } + Action { id: debugResetStateAction text: "Reset &State" From 36405af0cc235f11eb79ade947ea21ce9c5e949a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 22 Jan 2015 22:32:50 +0100 Subject: [PATCH 2/6] refactoring --- mix/ClientModel.cpp | 1 - mix/qml/main.qml | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index e91985f3f..f1e026c18 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -218,4 +218,3 @@ ExecutionResult ClientModel::callContract(Address const& _contract, bytes const& r.contractAddress = _contract; return r; } - diff --git a/mix/qml/main.qml b/mix/qml/main.qml index fb0977904..722417801 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -78,34 +78,37 @@ ApplicationWindow { text: "&Run" shortcut: "F5" onTriggered: { - + var item = TransactionHelper.defaultTransaction(); + item.executeConstructor = true; if (codeModel.code.contract.constructor.parameters.length === 0) { mainContent.ensureRightView(); - clientModel.debugDeployment(); + startF5Debugging(item); } else - { - var item = TransactionHelper.defaultTransaction(); - item.executeConstructor = true; transactionDialog.open(0, item); - } } enabled: codeModel.hasContract && !clientModel.running; } + function startF5Debugging(transaction) + { + var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); + var state = { + title: "", + balance: ether, + transactions: [transaction] + }; + clientModel.debugState(state); + } + TransactionDialog { id: transactionDialog onAccepted: { mainContent.ensureRightView(); var item = transactionDialog.getItem(); - var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); - var state = { - title: "", - balance: ether, - transactions: [item] - }; - clientModel.debugState(state); + item.executeConstructor = true; + startF5Debugging(item); } useTransactionDefaultValue: true } From 78e49abad32a6d489cbb0d9ebb40ff3dede4a19f Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 23 Jan 2015 14:42:10 +0100 Subject: [PATCH 3/6] - Changes on TransactionDialog.qml Layout - Move startF5Debugging => MainContent.qml --- mix/qml/Debugger.qml | 6 +- mix/qml/MainContent.qml | 38 +++++++ mix/qml/StatusPane.qml | 5 +- mix/qml/TransactionDialog.qml | 184 ++++++++++++++++++---------------- mix/qml/main.qml | 38 +------ 5 files changed, 148 insertions(+), 123 deletions(-) diff --git a/mix/qml/Debugger.qml b/mix/qml/Debugger.qml index 47975db83..3d0fba349 100644 --- a/mix/qml/Debugger.qml +++ b/mix/qml/Debugger.qml @@ -114,6 +114,7 @@ Rectangle { contentWidth: parent.width Rectangle { + color: "transparent" anchors.fill: parent ColumnLayout { @@ -317,7 +318,7 @@ Rectangle { Rectangle { Layout.fillWidth: true height: parent.height //- 2 * stateListContainer.border.width - + color: "transparent" ColumnLayout { width: parent.width @@ -431,6 +432,7 @@ Rectangle { Rectangle { id: storageRect + color: "transparent" width: parent.width Layout.minimumHeight: 25 Layout.maximumHeight: 223 @@ -506,6 +508,7 @@ Rectangle { Rectangle { id: memoryRect; + color: "transparent" height: 25 width: parent.width Layout.minimumHeight: 25 @@ -527,6 +530,7 @@ Rectangle { Rectangle { id: callDataRect + color: "transparent" height: 25 width: parent.width Layout.minimumHeight: 25 diff --git a/mix/qml/MainContent.qml b/mix/qml/MainContent.qml index 81771aa35..b29e2f4ea 100644 --- a/mix/qml/MainContent.qml +++ b/mix/qml/MainContent.qml @@ -4,6 +4,9 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls.Styles 1.1 import CodeEditorExtensionManager 1.0 import Qt.labs.settings 1.0 +import org.ethereum.qml.QEther 1.0 +import "js/QEtherHelper.js" as QEtherHelper +import "js/TransactionHelper.js" as TransactionHelper Rectangle { @@ -26,6 +29,41 @@ Rectangle { contentView.width = parent.width - projectList.width; } + function startQuickDebugging() + { + var item = TransactionHelper.defaultTransaction(); + item.executeConstructor = true; + if (codeModel.code.contract.constructor.parameters.length === 0) + { + ensureRightView(); + startF5Debugging(item); + } + else + transactionDialog.open(0, item); + } + + function startF5Debugging(transaction) + { + var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); + var state = { + title: "", + balance: ether, + transactions: [transaction] + }; + clientModel.debugState(state); + } + + TransactionDialog { + id: transactionDialog + onAccepted: { + ensureRightView(); + var item = transactionDialog.getItem(); + item.executeConstructor = true; + startF5Debugging(item); + } + useTransactionDefaultValue: true + } + function toggleRightView() { if (!rightView.visible) diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index c6c531a80..5e1ec7c75 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -113,9 +113,10 @@ Rectangle { Action { id: debugRunActionIcon onTriggered: { - mainContent.toggleRightView(); if (mainContent.rightViewVisible()) - clientModel.debugDeployment(); + mainContent.hideRightView() + else + mainContent.startQuickDebugging(); } enabled: false } diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 1ae36ebdb..f18db08a5 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -25,12 +25,10 @@ Window { signal accepted; function open(index, item) { - valueLabel.visible = !useTransactionDefaultValue; - valueField.visible = !useTransactionDefaultValue; - gasLabel.visible = !useTransactionDefaultValue; - gasFieldRect.visible = !useTransactionDefaultValue; - gasPriceLabel.visible = !useTransactionDefaultValue; - gasPriceRect.visible = !useTransactionDefaultValue; + rowFunction.visible = !useTransactionDefaultValue; + rowValue.visible = !useTransactionDefaultValue; + rowGas.visible = !useTransactionDefaultValue; + rowGasPrice.visible = !useTransactionDefaultValue; transactionIndex = index; gasField.value = item.gas; @@ -38,9 +36,7 @@ Window { valueField.value = item.value; var functionId = item.functionId; isConstructorTransaction = item.executeConstructor; - functionLabel.visible = !item.executeConstructor; - functionComboBox.visible = !item.executeConstructor; - console.log(item.executeConstructor); + rowFunction.visible = !item.executeConstructor; itemParams = item.parameters !== undefined ? item.parameters : {}; functionsModel.clear(); @@ -117,10 +113,6 @@ Window { var parameter = transactionDialog.transactionParams.get(p); var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); var param = intComponent.createObject(modalTransactionDialog); - console.log(param); - console.log(JSON.stringify(param)); - console.log(item); - console.log(JSON.stringify(item)); param.setValue(parameter.value); item.parameters[parameter.name] = param; @@ -128,102 +120,126 @@ Window { return item; } - GridLayout { + ColumnLayout { id: dialogContent - columns: 2 - anchors.fill: parent + width: parent.width + anchors.left: parent.left + anchors.right: parent.right anchors.margins: 10 - rowSpacing: 10 - columnSpacing: 10 - - Label { - id: functionLabel; - text: qsTr("Function") - } - ComboBox { - id: functionComboBox + spacing: 30 + RowLayout + { + id: rowFunction Layout.fillWidth: true - currentIndex: -1 - textRole: "text" - editable: false - model: ListModel { - id: functionsModel + height: 150 + Label { + Layout.preferredWidth: 75 + text: qsTr("Function") } - onCurrentIndexChanged: { - loadParameters(); + ComboBox { + id: functionComboBox + Layout.fillWidth: true + currentIndex: -1 + textRole: "text" + editable: false + model: ListModel { + id: functionsModel + } + onCurrentIndexChanged: { + loadParameters(); + } } } - Label { - id: valueLabel - text: qsTr("Value") - } - Rectangle + + RowLayout { - id: valueFieldRect + id: rowValue Layout.fillWidth: true - Ether { - id: valueField - edit: true - displayFormattedValue: true + Label { + Layout.preferredWidth: 75 + text: qsTr("Value") + } + Rectangle + { + Layout.fillWidth: true + Ether { + id: valueField + edit: true + displayFormattedValue: true + } } } - Label { - id: gasLabel - text: qsTr("Gas") - } - Rectangle + + RowLayout { - id: gasFieldRect + id: rowGas Layout.fillWidth: true - Ether { - id: gasField - edit: true - displayFormattedValue: true + Label { + Layout.preferredWidth: 75 + text: qsTr("Gas") + } + Rectangle + { + Layout.fillWidth: true + Ether { + id: gasField + edit: true + displayFormattedValue: true + } } } - Label { - id: gasPriceLabel - text: qsTr("Gas Price") - } - Rectangle + RowLayout { - id: gasPriceRect + id: rowGasPrice Layout.fillWidth: true - Ether { - id: gasPriceField - edit: true - displayFormattedValue: true + Label { + Layout.preferredWidth: 75 + text: qsTr("Gas Price") + } + Rectangle + { + Layout.fillWidth: true + Ether { + id: gasPriceField + edit: true + displayFormattedValue: true + } } } - Label { - text: qsTr("Parameters") - } - TableView { - model: paramsModel + RowLayout + { Layout.fillWidth: true - - TableViewColumn { - role: "name" - title: "Name" - width: 120 - } - TableViewColumn { - role: "type" - title: "Type" - width: 120 - } - TableViewColumn { - role: "value" - title: "Value" - width: 120 + Label { + text: qsTr("Parameters") + Layout.preferredWidth: 75 } + TableView { + model: paramsModel + Layout.fillWidth: true + + TableViewColumn { + role: "name" + title: "Name" + width: 120 + } + TableViewColumn { + role: "type" + title: "Type" + width: 120 + } + TableViewColumn { + role: "value" + title: "Value" + width: 120 + } - itemDelegate: { - return editableDelegate; + itemDelegate: { + return editableDelegate; + } } } } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 454f1e8fd..231dacf90 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -6,8 +6,6 @@ import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import CodeEditorExtensionManager 1.0 import org.ethereum.qml.QEther 1.0 -import "js/QEtherHelper.js" as QEtherHelper -import "js/TransactionHelper.js" as TransactionHelper ApplicationWindow { id: mainApplication @@ -77,40 +75,8 @@ ApplicationWindow { id: debugRunAction text: "&Run" shortcut: "F5" - onTriggered: { - var item = TransactionHelper.defaultTransaction(); - item.executeConstructor = true; - if (codeModel.code.contract.constructor.parameters.length === 0) - { - mainContent.ensureRightView(); - startF5Debugging(item); - } - else - transactionDialog.open(0, item); - } - enabled: codeModel.hasContract && !clientModel.running; - } - - function startF5Debugging(transaction) - { - var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); - var state = { - title: "", - balance: ether, - transactions: [transaction] - }; - clientModel.debugState(state); - } - - TransactionDialog { - id: transactionDialog - onAccepted: { - mainContent.ensureRightView(); - var item = transactionDialog.getItem(); - item.executeConstructor = true; - startF5Debugging(item); - } - useTransactionDefaultValue: true + onTriggered: mainContent.startQuickDebugging() + enabled: codeModel.hasContract && !clientModel.running } Action { From 3c859f2c0bc8c0919061d26a4d05c8c360104dfc Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 23 Jan 2015 16:24:07 +0100 Subject: [PATCH 4/6] - fix function/property name collision => rightViewVisible --- mix/qml/MainContent.qml | 9 +++++---- mix/qml/StatusPane.qml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mix/qml/MainContent.qml b/mix/qml/MainContent.qml index 7c9d6bf66..430c1176f 100644 --- a/mix/qml/MainContent.qml +++ b/mix/qml/MainContent.qml @@ -80,6 +80,11 @@ Rectangle { rightView.show(); } + function rightViewIsVisible() + { + return rightView.visible; + } + function hideRightView() { if (rightView.visible) rightView.hide(); @@ -89,10 +94,6 @@ Rectangle { webPreview.visible = !webPreview.visible; } - function rightViewVisible() { - return rightView.visible; - } - CodeEditorExtensionManager { headerView: headerPaneTabs; rightView: rightPaneTabs; diff --git a/mix/qml/StatusPane.qml b/mix/qml/StatusPane.qml index 5e1ec7c75..07da269ec 100644 --- a/mix/qml/StatusPane.qml +++ b/mix/qml/StatusPane.qml @@ -113,7 +113,7 @@ Rectangle { Action { id: debugRunActionIcon onTriggered: { - if (mainContent.rightViewVisible()) + if (mainContent.rightViewIsVisible()) mainContent.hideRightView() else mainContent.startQuickDebugging(); From 30736bee190b02461ceb949dd924e944b51d2480 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sat, 24 Jan 2015 14:11:58 +0100 Subject: [PATCH 5/6] - Coding Standards --- mix/ClientModel.cpp | 4 ++-- mix/ClientModel.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index daa18e003..1bebc0751 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -218,11 +218,11 @@ void ClientModel::showDebugError(QString const& _error) m_context->displayMessageDialog(tr("Debugger"), _error); } -ExecutionResult ClientModel::deployContract(bytes const& _code, TransactionSettings const& ctrTransaction) +ExecutionResult ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) { Address newAddress; if (!ctrTransaction.isEmpty()) - newAddress = m_client->transact(m_client->userAccount().secret(), ctrTransaction.value, _code, ctrTransaction.gas, ctrTransaction.gasPrice); + newAddress = m_client->transact(m_client->userAccount().secret(), _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice); else { u256 gasPrice = 10000000000000; diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 4abeefb6e..85ea648c9 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -121,7 +121,7 @@ signals: private: QString contractAddress() const; - void executeSequence(std::vector const& _sequence, u256 _balance, TransactionSettings const& ctrTransaction = TransactionSettings()); + void executeSequence(std::vector const& _sequence, u256 _balance, TransactionSettings const& _ctrTransaction = TransactionSettings()); ExecutionResult deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings()); ExecutionResult callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr); From 1f6697c021cf073373ba0bd69a5042aa666b89c7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sat, 24 Jan 2015 14:21:12 +0100 Subject: [PATCH 6/6] - Coding Standards --- mix/ClientModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 1bebc0751..7972d294c 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -221,7 +221,7 @@ void ClientModel::showDebugError(QString const& _error) ExecutionResult ClientModel::deployContract(bytes const& _code, TransactionSettings const& _ctrTransaction) { Address newAddress; - if (!ctrTransaction.isEmpty()) + if (!_ctrTransaction.isEmpty()) newAddress = m_client->transact(m_client->userAccount().secret(), _ctrTransaction.value, _code, _ctrTransaction.gas, _ctrTransaction.gasPrice); else {