diff --git a/mix/AssemblyDebuggerControl.cpp b/mix/AssemblyDebuggerControl.cpp index 43a36287d..bf937a11f 100644 --- a/mix/AssemblyDebuggerControl.cpp +++ b/mix/AssemblyDebuggerControl.cpp @@ -17,6 +17,7 @@ * display opcode debugging. */ +#include #include #include #include @@ -28,7 +29,6 @@ #include "AssemblyDebuggerControl.h" #include "AppContext.h" #include "DebuggingStateWrapper.h" -#include "TransactionListModel.h" #include "QContractDefinition.h" #include "QVariableDeclaration.h" #include "ContractCallDataEncoder.h" @@ -37,6 +37,20 @@ using namespace dev::eth; using namespace dev::mix; +/// @todo Move this to QML +dev::u256 fromQString(QString const& _s) +{ + return dev::jsToU256(_s.toStdString()); +} + +/// @todo Move this to QML +QString toQString(dev::u256 _value) +{ + std::ostringstream s; + s << _value; + return QString::fromStdString(s.str()); +} + AssemblyDebuggerControl::AssemblyDebuggerControl(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::ModalDialog) { qRegisterMetaType("QVariableDefinition*"); @@ -76,8 +90,16 @@ void AssemblyDebuggerControl::debugDeployment() void AssemblyDebuggerControl::debugTransaction(QObject* _transaction) { - auto mo = _transaction->metaObject(); - auto p = mo->property(0); + QString functionId = _transaction->property("functionId").toString(); + u256 value = fromQString(_transaction->property("value").toString()); + u256 gas = fromQString(_transaction->property("gas").toString()); + u256 gasPrice = fromQString(_transaction->property("gasPrice").toString()); + QVariantMap params = _transaction->property("parameters").toMap(); + TransactionSettings transaction("", functionId, value, gas, gasPrice); + + for (auto p = params.cbegin(); p != params.cend(); ++p) + transaction.parameterValues.insert(std::make_pair(p.key(), fromQString(p.value().toString()))); + runTransaction(transaction); } void AssemblyDebuggerControl::resetState() @@ -164,8 +186,5 @@ void AssemblyDebuggerControl::updateGUI(bool _success, DebuggingStatusResult con void AssemblyDebuggerControl::runTransaction(TransactionSettings const& _tr) { - QtConcurrent::run([this, _tr]() - { - callContract(_tr, m_previousDebugResult.contractAddress); - }); + callContract(_tr, m_previousDebugResult.contractAddress); } diff --git a/mix/AssemblyDebuggerControl.h b/mix/AssemblyDebuggerControl.h index 8a906d9f4..061a3d20a 100644 --- a/mix/AssemblyDebuggerControl.h +++ b/mix/AssemblyDebuggerControl.h @@ -21,7 +21,6 @@ #include #include "Extension.h" -#include "TransactionListModel.h" #include "AssemblyDebuggerModel.h" using AssemblyDebuggerData = std::tuple, dev::mix::QQMLMap*>; diff --git a/mix/AssemblyDebuggerModel.cpp b/mix/AssemblyDebuggerModel.cpp index ef75981bd..9deaba4d8 100644 --- a/mix/AssemblyDebuggerModel.cpp +++ b/mix/AssemblyDebuggerModel.cpp @@ -25,7 +25,6 @@ #include #include "AssemblyDebuggerModel.h" #include "AppContext.h" -#include "TransactionListModel.h" #include "DebuggingStateWrapper.h" using namespace std; diff --git a/mix/AssemblyDebuggerModel.h b/mix/AssemblyDebuggerModel.h index 1b1254464..fea132415 100644 --- a/mix/AssemblyDebuggerModel.h +++ b/mix/AssemblyDebuggerModel.h @@ -26,13 +26,36 @@ #include #include #include "DebuggingStateWrapper.h" -#include "TransactionListModel.h" namespace dev { namespace mix { +/// Backend transaction config class +struct TransactionSettings +{ + TransactionSettings(): + value(0), gas(10000), gasPrice(10 * dev::eth::szabo) {} + + TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice): + title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {} + + /// User specified transaction title + QString title; + /// Contract function name + QString functionId; + /// Transaction value + u256 value; + /// Gas + u256 gas; + /// Gas price + u256 gasPrice; + /// Mapping from contract function parameter name to value + std::map parameterValues; +}; + + /** * @brief Long-life object for managing all executions. */ diff --git a/mix/CodeEditorExtensionManager.cpp b/mix/CodeEditorExtensionManager.cpp index 4a93352b1..8001f0bdc 100644 --- a/mix/CodeEditorExtensionManager.cpp +++ b/mix/CodeEditorExtensionManager.cpp @@ -67,7 +67,6 @@ void CodeEditorExtensionManager::initExtensions() initExtension(std::make_shared(m_appContext)); std::shared_ptr debug = std::make_shared(m_appContext); std::shared_ptr tr = std::make_shared(m_appContext); - QObject::connect(tr->model(), &TransactionListModel::transactionStarted, debug.get(), &AssemblyDebuggerControl::runTransaction); QObject::connect(m_doc, &QTextDocument::contentsChanged, [=]() { m_appContext->codeModel()->registerCodeChange(m_doc->toPlainText()); }); initExtension(debug); diff --git a/mix/ProjectFile.cpp b/mix/ProjectFile.cpp deleted file mode 100644 index 0b847345b..000000000 --- a/mix/ProjectFile.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file ProjectFile.cpp - * @author Arkadiy Paronyan arkadiy@ethdev.com - * @date 2014 - * Ethereum IDE client. - */ - -#include -#include "ProjectFile.h" - -namespace dev -{ -namespace mix -{ - -void ProjectFile::saveProject() -{ -} - -} -} diff --git a/mix/ProjectFile.h b/mix/ProjectFile.h deleted file mode 100644 index 7ae1fb84d..000000000 --- a/mix/ProjectFile.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file ProjectFile.h - * @author Arkadiy Paronyan arkadiy@ethdev.com - * @date 2014 - * Ethereum IDE client. - */ - -#pragma once - -#include -#include "TransactionListModel.h" - -namespace dev -{ - -namespace mix -{ - -/// Background code compiler -class ProjectFile : public QObject -{ - Q_OBJECT - -public: - ProjectFile(); - - void loadProject(); - -signals: - void projectLoaded(); - -public slots: - void saveProject(); - -private: - QString defaultProjectPath() const; - TransactionListModel* transactionModel(); -}; - -} - -} diff --git a/mix/TransactionListModel.cpp b/mix/TransactionListModel.cpp deleted file mode 100644 index f6ecc9846..000000000 --- a/mix/TransactionListModel.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file TransactionListModel.cpp - * @author Arkadiy Paronyan arkadiy@ethdev.com - * @date 2014 - * Ethereum IDE client. - */ - -#include -#include -#include -#include -#include -#include "TransactionListModel.h" -#include "QContractDefinition.h" -#include "QFunctionDefinition.h" -#include "QVariableDeclaration.h" -#include "AppContext.h" -#include "CodeModel.h" - -namespace dev -{ -namespace mix -{ - -/// @todo Move this to QML -u256 fromQString(QString const& _s) -{ - return dev::jsToU256(_s.toStdString()); -} - -/// @todo Move this to QML -QString toQString(u256 _value) -{ - std::ostringstream s; - s << _value; - return QString::fromStdString(s.str()); -} - -TransactionListItem::TransactionListItem(int _index, TransactionSettings const& _t, QObject* _parent): - QObject(_parent), m_index(_index), m_title(_t.title), m_functionId(_t.functionId), m_value(toQString(_t.value)), - m_gas(toQString(_t.gas)), m_gasPrice(toQString(_t.gasPrice)) -{} - -TransactionListModel::TransactionListModel(QObject* _parent, AppContext* _appContext): - QAbstractListModel(_parent), m_appContext(_appContext) -{ - qRegisterMetaType("TransactionListItem*"); -} - -QHash TransactionListModel::roleNames() const -{ - QHash roles; - roles[TitleRole] = "title"; - roles[IdRole] = "transactionIndex"; - return roles; -} - -int TransactionListModel::rowCount(QModelIndex const& _parent) const -{ - Q_UNUSED(_parent); - return m_transactions.size(); -} - -QVariant TransactionListModel::data(QModelIndex const& _index, int _role) const -{ - if (_index.row() < 0 || _index.row() >= (int)m_transactions.size()) - return QVariant(); - auto const& transaction = m_transactions.at(_index.row()); - switch (_role) - { - case TitleRole: - return QVariant(transaction.title); - case IdRole: - return QVariant(_index.row()); - default: - return QVariant(); - } -} - -///@todo: get parameters from code model -QList buildParameters(CodeModel* _codeModel, TransactionSettings const& _transaction, QString const& _functionId) -{ - QList params; - QContractDefinition const* contract = _codeModel->code()->contract(); - auto functions = contract->functionsList(); - for (auto f : functions) - { - if (f->name() != _functionId) - continue; - - auto parameters = f->parametersList(); - for (auto p : parameters) - { - QString paramValue; - if (f->name() == _transaction.functionId) - { - auto paramValueIter = _transaction.parameterValues.find(p->name()); - if (paramValueIter != _transaction.parameterValues.cend()) - paramValue = toQString(paramValueIter->second); - } - - TransactionParameterItem* item = new TransactionParameterItem(p->name(), p->type(), paramValue); - QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); - params.append(item); - } - } - return params; -} - -///@todo: get fnctions from code model -QList TransactionListModel::getFunctions() -{ - QList functionNames; - QContractDefinition const* contract = m_appContext->codeModel()->code()->contract(); - auto functions = contract->functionsList(); - for (auto f : functions) - { - functionNames.append(f->name()); - } - return functionNames; -} - -QVariantList TransactionListModel::getParameters(int _index, QString const& _functionId) -{ - TransactionSettings const& transaction = (_index >= 0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); - auto plist = buildParameters(m_appContext->codeModel(), transaction, _functionId); - QVariantList vl; - for (QObject* p : plist) - vl.append(QVariant::fromValue(p)); - return vl; -} - -TransactionListItem* TransactionListModel::getItem(int _index) -{ - TransactionSettings const& transaction = (_index >= 0 && _index < (int)m_transactions.size()) ? m_transactions[_index] : TransactionSettings(); - TransactionListItem* item = new TransactionListItem(_index, transaction, nullptr); - QQmlEngine::setObjectOwnership(item, QQmlEngine::JavaScriptOwnership); - return item; -} - -void TransactionListModel::edit(QObject* _data) -{ - //these properties come from TransactionDialog QML object - ///@todo change the model to a qml component - int index = _data->property("transactionIndex").toInt(); - QString title = _data->property("transactionTitle").toString(); - QString gas = _data->property("gas").toString(); - QString gasPrice = _data->property("gasPrice").toString(); - QString value = _data->property("transactionValue").toString(); - QString functionId = _data->property("functionId").toString(); - QAbstractListModel* paramsModel = qvariant_cast(_data->property("transactionParams")); - TransactionSettings transaction(title, functionId, fromQString(value), fromQString(gas), fromQString(gasPrice)); - int paramCount = paramsModel->rowCount(QModelIndex()); - for (int p = 0; p < paramCount; ++p) - { - QString paramName = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole).toString(); - QString paramValue = paramsModel->data(paramsModel->index(p, 0), Qt::DisplayRole + 2).toString(); - if (!paramValue.isEmpty() && !paramName.isEmpty()) - transaction.parameterValues[paramName] = fromQString(paramValue); - } - - if (index >= 0 && index < (int)m_transactions.size()) - { - beginRemoveRows(QModelIndex(), index, index); - m_transactions.erase(m_transactions.begin() + index); - endRemoveRows(); - } - else - index = rowCount(QModelIndex()); - - beginInsertRows(QModelIndex(), index, index); - m_transactions.push_back(transaction); - emit countChanged(); - endInsertRows(); -} - -int TransactionListModel::getCount() const -{ - return rowCount(QModelIndex()); -} - -void TransactionListModel::runTransaction(int _index) -{ - TransactionSettings tr = m_transactions.at(_index); - emit transactionStarted(tr); -} - -QVariantMap TransactionListModel::save() -{ - -} - -/// Load transactions from a map -void TransactionListModel::load(QVariantMap const& _data) -{ - std::vector transactions; - - - m_transactions.swap(transactions); -} - -} -} - diff --git a/mix/TransactionListModel.h b/mix/TransactionListModel.h deleted file mode 100644 index 993767310..000000000 --- a/mix/TransactionListModel.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file TransactionListView.h - * @author Arkadiy Paronyan arkadiy@ethdev.com - * @date 2014 - * Ethereum IDE client. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace dev -{ -namespace mix -{ - -class AppContext; - -/// Backend transaction config class -struct TransactionSettings -{ - TransactionSettings(): - value(0), gas(10000), gasPrice(10 * dev::eth::szabo) {} - - TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice): - title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {} - - /// User specified transaction title - QString title; - /// Contract function name - QString functionId; - /// Transaction value - u256 value; - /// Gas - u256 gas; - /// Gas price - u256 gasPrice; - /// Mapping from contract function parameter name to value - std::map parameterValues; -}; - -/// QML transaction parameter class -class TransactionParameterItem: public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name CONSTANT) - Q_PROPERTY(QString type READ type CONSTANT) - Q_PROPERTY(QString value READ value CONSTANT) -public: - TransactionParameterItem(QString const& _name, QString const& _type, QString const& _value): - m_name(_name), m_type(_type), m_value(_value) {} - - /// Parameter name, set by contract definition - QString name() { return m_name; } - /// Parameter type, set by contract definition - QString type() { return m_type; } - /// Parameter value, set by user - QString value() { return m_value; } - -private: - QString m_name; - QString m_type; - QString m_value; -}; - -class TransactionListItem: public QObject -{ - Q_OBJECT - Q_PROPERTY(int index READ index CONSTANT) - Q_PROPERTY(QString title READ title CONSTANT) - Q_PROPERTY(QString functionId READ functionId CONSTANT) - Q_PROPERTY(QString gas READ gas CONSTANT) - Q_PROPERTY(QString gasPrice READ gasPrice CONSTANT) - Q_PROPERTY(QString value READ value CONSTANT) - -public: - TransactionListItem(int _index, TransactionSettings const& _t, QObject* _parent); - - /// User specified transaction title - QString title() { return m_title; } - /// Gas - QString gas() { return m_gas; } - /// Gas cost - QString gasPrice() { return m_gasPrice; } - /// Transaction value - QString value() { return m_value; } - /// Contract function name - QString functionId() { return m_functionId; } - /// Index of this transaction in the transactions list - int index() { return m_index; } - -private: - int m_index; - QString m_title; - QString m_functionId; - QString m_value; - QString m_gas; - QString m_gasPrice; -}; - -/// QML model for a list of transactions -class TransactionListModel: public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY(int count READ getCount() NOTIFY countChanged()) - - enum Roles - { - TitleRole = Qt::DisplayRole, - IdRole = Qt::UserRole + 1 - }; - -public: - TransactionListModel(QObject* _parent, AppContext* _appContext); - ~TransactionListModel() {} - - QHash roleNames() const override; - int rowCount(QModelIndex const& _parent) const override; - QVariant data(QModelIndex const& _index, int _role) const override; - int getCount() const; - /// Apply changes from transaction dialog. Argument is a dialog model as defined in TransactionDialog.qml - /// @todo Change that to transaction item - Q_INVOKABLE void edit(QObject* _data); - /// @returns transaction item for a give index - Q_INVOKABLE TransactionListItem* getItem(int _index); - /// @returns a list of functions for current contract - Q_INVOKABLE QList getFunctions(); - /// @returns function parameters along with parameter values if set. @see TransactionParameterItem - Q_INVOKABLE QVariantList getParameters(int _id, QString const& _functionId); - /// Launch transaction execution UI handler - Q_INVOKABLE void runTransaction(int _index); - /// Save transaction to a map for serialization into file - QVariantMap save(); - /// Load transactions from a map - void load(QVariantMap const& _data); - -signals: - /// Transaction count has changed - void countChanged(); - /// Transaction has been launched - void transactionStarted(dev::mix::TransactionSettings); - -private: - std::vector m_transactions; - AppContext* m_appContext; -}; - -} - -} - diff --git a/mix/TransactionListView.cpp b/mix/TransactionListView.cpp index 9d20d173d..a2b833209 100644 --- a/mix/TransactionListView.cpp +++ b/mix/TransactionListView.cpp @@ -26,18 +26,10 @@ #include #include #include "TransactionListView.h" -#include "TransactionListModel.h" using namespace dev::mix; TransactionListView::TransactionListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightTab) { - m_model.reset(new TransactionListModel(this, _context)); - //m_appEngine->rootContext()->setContextProperty("transactionListModel", m_model.get()); -} - -TransactionListView::~TransactionListView() -{ - //implementation is in cpp file so that all types deleted are complete } QString TransactionListView::contentUrl() const diff --git a/mix/TransactionListView.h b/mix/TransactionListView.h index e21d7ecd8..04b6154d4 100644 --- a/mix/TransactionListView.h +++ b/mix/TransactionListView.h @@ -29,8 +29,6 @@ namespace dev namespace mix { -class TransactionListModel; - /// Transactions list control /// @todo This should be moved into state as a sequence class TransactionListView: public Extension @@ -39,15 +37,9 @@ class TransactionListView: public Extension public: TransactionListView(AppContext* _context); - ~TransactionListView(); void start() const override; QString title() const override; QString contentUrl() const override; - /// @returns the underlying model - TransactionListModel* model() const { return m_model.get(); } - -private: - std::unique_ptr m_model; }; } diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 14b41bde1..f04e1a390 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -28,7 +28,7 @@ Window { property alias gasPrice : gasPriceField.text; property alias transactionValue : valueField.text; property alias functionId : functionComboBox.currentText; - property var model; + property var itemParams; signal accepted; @@ -39,6 +39,7 @@ Window { gasPrice = item.gasPrice; transactionValue = item.value; var functionId = item.functionId; + itemParams = item.parameters !== undefined ? item.parameters : {}; functionsModel.clear(); var functionIndex = -1; var functions = codeModel.code.contract.functions; @@ -58,7 +59,8 @@ Window { var func = codeModel.code.contract.functions[functionComboBox.currentIndex]; var parameters = func.parameters; for (var p = 0; p < parameters.length; p++) { - paramsModel.append({ name: parameters[p].name, type: parameters[p].type, value: parameters[p].value !== undefined ? parameters[p].value : "" }); + var pname = parameters[p].name; + paramsModel.append({ name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname] : "" }); } } } diff --git a/mix/qml/TransactionList.qml b/mix/qml/TransactionList.qml index fd85f0d7b..2ae3cecb4 100644 --- a/mix/qml/TransactionList.qml +++ b/mix/qml/TransactionList.qml @@ -70,8 +70,14 @@ Rectangle { functionId: transactionDialog.functionId, gas: transactionDialog.gas, gasPrice: transactionDialog.gasPrice, - value: transactionDialog.transactionValue + value: transactionDialog.transactionValue, + parameters: {} } + for (var p = 0; p < transactionDialog.transactionParams.count; p++) { + var parameter = transactionDialog.transactionParams.get(p); + item.parameters[parameter.name] = parameter.value; + } + console.log(item.title); if (transactionDialog.transactionIndex < transactionListModel.count) transactionListModel.set(transactionDialog.transactionIndex, item);