diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index 4c8e61510..939829243 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -31,8 +31,10 @@ #include "FileIo.h" #include "ClientModel.h" #include "AppContext.h" +#include "QEther.h" #include + using namespace dev; using namespace dev::eth; using namespace dev::mix; @@ -49,9 +51,10 @@ AppContext::AppContext(QQmlApplicationEngine* _engine) m_applicationEngine->rootContext()->setContextProperty("appContext", this); qmlRegisterType("org.ethereum.qml", 1, 0, "FileIo"); qmlRegisterSingletonType(QUrl("qrc:/qml/ProjectModel.qml"), "org.ethereum.qml.ProjectModel", 1, 0, "ProjectModel"); + qmlRegisterType("org.ethereum.qml.QEther", 1, 0, "QEther"); + qmlRegisterType("org.ethereum.qml.QBigInt", 1, 0, "QBigInt"); m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get()); m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); - } AppContext::~AppContext() diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 14fcf9bfa..eb61c8554 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -32,28 +32,17 @@ #include "ContractCallDataEncoder.h" #include "CodeModel.h" #include "ClientModel.h" +#include "QEther.h" using namespace dev; 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()); -} - ClientModel::ClientModel(AppContext* _context): m_context(_context), m_running(false) { + qRegisterMetaType("QBigInt*"); + qRegisterMetaType("QEther*"); qRegisterMetaType("QVariableDefinition*"); qRegisterMetaType("QVariableDefinitionList*"); qRegisterMetaType>("QList"); @@ -74,7 +63,7 @@ void ClientModel::debugDeployment() void ClientModel::debugState(QVariantMap _state) { - u256 balance = fromQString(_state.value("balance").toString()); + u256 balance = (qvariant_cast(_state.value("balance")))->toU256Wei(); QVariantList transactions = _state.value("transactions").toList(); std::vector transactionSequence; @@ -84,14 +73,14 @@ void ClientModel::debugState(QVariantMap _state) QVariantMap transaction = t.toMap(); QString functionId = transaction.value("functionId").toString(); - u256 value = fromQString(transaction.value("value").toString()); - u256 gas = fromQString(transaction.value("gas").toString()); - u256 gasPrice = fromQString(transaction.value("gasPrice").toString()); + u256 gas = (qvariant_cast(transaction.value("gas")))->toU256Wei(); + u256 value = (qvariant_cast(transaction.value("value")))->toU256Wei(); + u256 gasPrice = (qvariant_cast(transaction.value("gasPrice")))->toU256Wei(); QVariantMap params = transaction.value("parameters").toMap(); TransactionSettings transactionSettings(functionId, value, gas, gasPrice); for (auto p = params.cbegin(); p != params.cend(); ++p) - transactionSettings.parameterValues.insert(std::make_pair(p.key(), fromQString(p.value().toString()))); + transactionSettings.parameterValues.insert(std::make_pair(p.key(), (qvariant_cast(p.value()))->toU256Wei())); transactionSequence.push_back(transactionSettings); } diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 509a5995b..0e7f9c092 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + 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 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. + 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 . + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . */ /** @file ClientModel.h * @author Yann yann@ethdev.com diff --git a/mix/DebuggingStateWrapper.cpp b/mix/DebuggingStateWrapper.cpp index 85179e84b..69f5c2ee5 100644 --- a/mix/DebuggingStateWrapper.cpp +++ b/mix/DebuggingStateWrapper.cpp @@ -23,12 +23,14 @@ #include #include #include +#include #include #include #include #include #include #include "DebuggingStateWrapper.h" +#include "QBigInt.h" using namespace dev; using namespace dev::eth; using namespace dev::mix; @@ -66,25 +68,19 @@ std::tuple, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod return std::make_tuple(codeStr, QPointer(new QQMLMap(codeMapping))); } -QString DebuggingStateWrapper::gasCost() +QBigInt* DebuggingStateWrapper::gasCost() { - std::ostringstream ss; - ss << std::dec << m_state.gasCost; - return QString::fromStdString(ss.str()); + return new QBigInt(m_state.gasCost); } -QString DebuggingStateWrapper::gas() +QBigInt* DebuggingStateWrapper::gas() { - std::ostringstream ss; - ss << std::dec << m_state.gas; - return QString::fromStdString(ss.str()); + return new QBigInt(m_state.gas); } -QString DebuggingStateWrapper::newMemSize() +QBigInt* DebuggingStateWrapper::newMemSize() { - std::ostringstream ss; - ss << std::dec << m_state.newMemSize; - return QString::fromStdString(ss.str()); + return new QBigInt(m_state.newMemSize); } QStringList DebuggingStateWrapper::debugStack() diff --git a/mix/DebuggingStateWrapper.h b/mix/DebuggingStateWrapper.h index 010db9af7..0541f0afa 100644 --- a/mix/DebuggingStateWrapper.h +++ b/mix/DebuggingStateWrapper.h @@ -29,6 +29,7 @@ #include #include "QVariableDefinition.h" #include "MixClient.h" +#include "QBigInt.h" namespace dev { @@ -81,8 +82,8 @@ class DebuggingStateWrapper: public QObject Q_OBJECT Q_PROPERTY(int step READ step CONSTANT) Q_PROPERTY(int curPC READ curPC CONSTANT) - Q_PROPERTY(QString gasCost READ gasCost CONSTANT) - Q_PROPERTY(QString gas READ gas CONSTANT) + Q_PROPERTY(QBigInt* gasCost READ gasCost CONSTANT) + Q_PROPERTY(QBigInt* gas READ gas CONSTANT) Q_PROPERTY(QString instruction READ instruction CONSTANT) Q_PROPERTY(QStringList debugStack READ debugStack CONSTANT) Q_PROPERTY(QStringList debugStorage READ debugStorage CONSTANT) @@ -90,7 +91,7 @@ class DebuggingStateWrapper: public QObject Q_PROPERTY(QVariantList debugCallData READ debugCallData CONSTANT) Q_PROPERTY(QString headerInfo READ headerInfo CONSTANT) Q_PROPERTY(QString endOfDebug READ endOfDebug CONSTANT) - Q_PROPERTY(QString newMemSize READ newMemSize CONSTANT) + Q_PROPERTY(QBigInt* newMemSize READ newMemSize CONSTANT) Q_PROPERTY(QStringList levels READ levels CONSTANT) public: @@ -99,12 +100,10 @@ public: int step() { return (int)m_state.steps; } /// Get the proccessed code index. int curPC() { return (int)m_state.curPC; } - /// Get gas left. - QString gasLeft(); /// Get gas cost. - QString gasCost(); + QBigInt* gasCost(); /// Get gas used. - QString gas(); + QBigInt* gas(); /// Get stack. QStringList debugStack(); /// Get storage. @@ -118,7 +117,7 @@ public: /// get end of debug information. QString endOfDebug(); /// Get the new memory size. - QString newMemSize(); + QBigInt* newMemSize(); /// Get current instruction QString instruction(); /// Get all previous steps. diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index db272a3d0..dde6b7b89 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + 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 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. + 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 . + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . */ /** @file MixClient.cpp * @author Yann yann@ethdev.com diff --git a/mix/MixClient.h b/mix/MixClient.h index b7ba7fbf3..c22d845d7 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + 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 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. + 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 . + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . */ /** @file MixClient.h * @author Yann yann@ethdev.com diff --git a/mix/QBigInt.cpp b/mix/QBigInt.cpp new file mode 100644 index 000000000..191d20459 --- /dev/null +++ b/mix/QBigInt.cpp @@ -0,0 +1,59 @@ +/* + 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 QBigInt.cpp + * @author Yann yann@ethdev.com + * @date 2015 + */ + +#include +#include +#include +#include "QBigInt.h" + +using namespace dev; +using namespace dev::mix; + +QString QBigInt::value() const +{ + std::ostringstream s; + s << m_internalValue; + return QString::fromStdString(s.str()); +} + +QBigInt* QBigInt::subtract(QBigInt* const& _value) const +{ + BigIntVariant toSubtract = _value->internalValue(); + return new QBigInt(boost::apply_visitor(mix::subtract(), m_internalValue, toSubtract)); +} + +QBigInt* QBigInt::add(QBigInt* const& _value) const +{ + BigIntVariant toAdd = _value->internalValue(); + return new QBigInt(boost::apply_visitor(mix::add(), m_internalValue, toAdd)); +} + +QBigInt* QBigInt::multiply(QBigInt* const& _value) const +{ + BigIntVariant toMultiply = _value->internalValue(); + return new QBigInt(boost::apply_visitor(mix::multiply(), m_internalValue, toMultiply)); +} + +QBigInt* QBigInt::divide(QBigInt* const& _value) const +{ + BigIntVariant toDivide = _value->internalValue(); + return new QBigInt(boost::apply_visitor(mix::divide(), m_internalValue, toDivide)); +} diff --git a/mix/QBigInt.h b/mix/QBigInt.h new file mode 100644 index 000000000..842b86c7d --- /dev/null +++ b/mix/QBigInt.h @@ -0,0 +1,102 @@ +/* + 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 QBigInt.h + * @author Yann yann@ethdev.com + * @date 2015 + * Represent a big integer (u256, bigint) to be used in QML. + */ + +#pragma once + +#include "boost/variant.hpp" +#include "boost/variant/multivisitors.hpp" +#include +#include +#include +#include + +using namespace dev; + +namespace dev +{ +namespace mix +{ + +using BigIntVariant = boost::variant; + +struct add: public boost::static_visitor +{ + template + BigIntVariant operator()(T1 const& _value, T2 const& _otherValue) const { return _value + _otherValue; } +}; + +struct subtract: public boost::static_visitor +{ + template + BigIntVariant operator()(T1 const& _value, T2 const& _otherValue) const { return _value - _otherValue; } +}; + +struct multiply: public boost::static_visitor +{ + template + BigIntVariant operator()(T1 const& _value, T2 const& _otherValue) const { return _value * _otherValue; } +}; + +struct divide: public boost::static_visitor +{ + template + BigIntVariant operator()(T1 const& _value, T2 const& _otherValue) const { return _value / _otherValue; } +}; + +/* + * Represent big integer like big int and u256 in QML. + * The ownership is set by default to Javascript. + */ +class QBigInt: public QObject +{ + Q_OBJECT + +public: + QBigInt(QObject* _parent = 0): QObject(_parent), m_internalValue(dev::u256(0)) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } + QBigInt(dev::u256 const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } + QBigInt(dev::bigint const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } + QBigInt(BigIntVariant const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value){ QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } + ~QBigInt() {} + + /// @returns the current used big integer. + BigIntVariant internalValue() { return m_internalValue; } + /// @returns a string representation of the big integer used. Invokable from QML. + Q_INVOKABLE QString value() const; + /// Set the value of the BigInteger used. Will use u256 type. Invokable from QML. + Q_INVOKABLE void setValue(QString const& _value) { m_internalValue = dev::jsToU256(_value.toStdString()); } + /// Subtract by @a _value. Invokable from QML. + Q_INVOKABLE QBigInt* subtract(QBigInt* const& _value) const; + /// Add @a _value to the current big integer. Invokable from QML. + Q_INVOKABLE QBigInt* add(QBigInt* const& _value) const; + /// Multiply by @a _value. Invokable from QML. + Q_INVOKABLE QBigInt* multiply(QBigInt* const& _value) const; + /// divide by @a _value. Invokable from QML. + Q_INVOKABLE QBigInt* divide(QBigInt* const& _value) const; + +protected: + BigIntVariant m_internalValue; +}; + +} +} + + diff --git a/mix/QEther.cpp b/mix/QEther.cpp new file mode 100644 index 000000000..46562d440 --- /dev/null +++ b/mix/QEther.cpp @@ -0,0 +1,55 @@ +/* + 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 QEther.cpp + * @author Yann yann@ethdev.com + * @date 2014 + */ + +#include +#include "QEther.h" + +using namespace dev::mix; + +QString QEther::format() const +{ + return QString::fromStdString(dev::eth::formatBalance(boost::get(toWei()->internalValue()))); +} + +QBigInt* QEther::toWei() const +{ + QMetaEnum units = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("EtherUnit")); + const char* key = units.valueToKey(m_currentUnit); + for (std::pair rawUnit: dev::eth::units()) + { + if (rawUnit.second == QString(key).toLower().toStdString()) + return multiply(new QBigInt(rawUnit.first)); + } + return new QBigInt(dev::u256(0)); +} + +void QEther::setUnit(QString const& _unit) +{ + QMetaEnum units = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("EtherUnit")); + for (int k = 0; k < units.keyCount(); k++) + { + if (QString(units.key(k)).toLower() == _unit) + { + m_currentUnit = static_cast(units.keysToValue(units.key(k))); + return; + } + } +} diff --git a/mix/QEther.h b/mix/QEther.h new file mode 100644 index 000000000..794ba2ba1 --- /dev/null +++ b/mix/QEther.h @@ -0,0 +1,92 @@ +/* + 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 QEther.h + * @author Yann yann@ethdev.com + * @date 2014 + * Represent an amount of Ether in QML (mapped to u256 in c++). + */ + +#pragma once + +#include +#include +#include "QBigInt.h" + +namespace dev +{ +namespace mix +{ + +class QEther: public QBigInt +{ + Q_OBJECT + Q_ENUMS(EtherUnit) + Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(EtherUnit unit READ unit WRITE setUnit NOTIFY unitChanged) + +public: + enum EtherUnit + { + Uether, + Vether, + Dether, + Nether, + Yether, + Zether, + Eether, + Pether, + Tether, + Gether, + Mether, + Grand, + Ether, + Finney, + Szabo, + Gwei, + Mwei, + Kwei, + Wei + }; + + QEther(QObject* _parent = 0): QBigInt(dev::u256(0), _parent), m_currentUnit(EtherUnit::Wei) {} + QEther(dev::u256 _value, EtherUnit _unit, QObject* _parent = 0): QBigInt(_value, _parent), m_currentUnit(_unit) {} + ~QEther() {} + + /// @returns user-friendly string representation of the amount of ether. Invokable from QML. + Q_INVOKABLE QString format() const; + /// @returns the current amount of Ether in Wei. Invokable from QML. + Q_INVOKABLE QBigInt* toWei() const; + /// @returns the current unit used. Invokable from QML. + Q_INVOKABLE EtherUnit unit() const { return m_currentUnit; } + /// Set the unit to be used. Invokable from QML. + Q_INVOKABLE void setUnit(EtherUnit const& _unit) { m_currentUnit = _unit; } + /// Set the unit to be used. Invokable from QML. + Q_INVOKABLE void setUnit(QString const& _unit); + /// @returns the u256 value of the current amount of Ether in Wei. + dev::u256 toU256Wei() { return boost::get(toWei()->internalValue()); } + +private: + EtherUnit m_currentUnit; + +signals: + void valueChanged(); + void unitChanged(); +}; + +} +} + diff --git a/mix/qml.qrc b/mix/qml.qrc index 344fcaa22..169d1ebcb 100644 --- a/mix/qml.qrc +++ b/mix/qml.qrc @@ -40,5 +40,8 @@ qml/CodeEditorView.qml qml/js/ProjectModel.js qml/WebPreview.qml + qml/Ether.qml + qml/EtherValue.qml + qml/BigIntValue.qml diff --git a/mix/qml/BigIntValue.qml b/mix/qml/BigIntValue.qml new file mode 100644 index 000000000..5e3262516 --- /dev/null +++ b/mix/qml/BigIntValue.qml @@ -0,0 +1,13 @@ +/* + * Used to instanciate a QEther obj using Qt.createComponent function. +*/ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 +import org.ethereum.qml.QBigInt 1.0 + +QBigInt +{ + id: bigInt +} diff --git a/mix/qml/Ether.qml b/mix/qml/Ether.qml new file mode 100644 index 000000000..9eb9b63e0 --- /dev/null +++ b/mix/qml/Ether.qml @@ -0,0 +1,115 @@ +/* + * Display a row containing : + * - The amount of Ether. + * - The unit used. + * - User-friendly string representation of the amout of Ether (if displayFormattedValue == true). + * 'value' has to be a QEther obj. +*/ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 + +Rectangle { + id: etherEdition + property bool displayFormattedValue; + property bool edit; + property variant value; + onValueChanged: update() + Component.onCompleted: update() + + function update() + { + if (value !== undefined) + { + etherValueEdit.text = value.value; + selectUnit(value.unit); + } + } + + function selectUnit(unit) + { + units.currentIndex = unit; + } + + RowLayout + { + anchors.fill: parent; + id: row + width: 200 + height: parent.height + Rectangle + { + width : 200 + color: edit ? "blue" : "white" + TextField + { + onTextChanged: + { + if (value !== undefined) + { + value.setValue(text) + formattedValue.text = value.format(); + } + } + width: parent.width + readOnly: !edit + visible: edit + id: etherValueEdit; + } + } + + Rectangle + { + Layout.fillWidth: true + id: unitContainer + width: 20 + anchors.verticalCenter: parent.verticalCenter + ComboBox + { + id: units + onCurrentTextChanged: + { + if (value !== undefined) + { + value.setUnit(currentText); + formattedValue.text = value.format(); + } + } + model: ListModel { + id: unitsModel + ListElement { text: "Uether"; } + ListElement { text: "Vether"; } + ListElement { text: "Dether"; } + ListElement { text: "Nether"; } + ListElement { text: "Yether"; } + ListElement { text: "Zether"; } + ListElement { text: "Eether"; } + ListElement { text: "Pether"; } + ListElement { text: "Tether"; } + ListElement { text: "Gether"; } + ListElement { text: "Mether"; } + ListElement { text: "grand"; } + ListElement { text: "ether"; } + ListElement { text: "finney"; } + ListElement { text: "szabo"; } + ListElement { text: "Gwei"; } + ListElement { text: "Mwei"; } + ListElement { text: "Kwei"; } + ListElement { text: "wei"; } + } + } + Rectangle + { + anchors.verticalCenter: parent.verticalCenter + anchors.left: units.right + visible: displayFormattedValue + width: 20 + Text + { + id: formattedValue + } + } + } + } +} diff --git a/mix/qml/EtherValue.qml b/mix/qml/EtherValue.qml new file mode 100644 index 000000000..1217aade5 --- /dev/null +++ b/mix/qml/EtherValue.qml @@ -0,0 +1,15 @@ +/* + * Used to instanciate a QEther obj using Qt.createComponent function. +*/ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 +import org.ethereum.qml.QEther 1.0 + +QEther +{ + id: basicEther + value: "100000000000" + unit: QEther.Wei +} diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index cde7cb3ef..55a4df14f 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -2,8 +2,10 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.0 +import org.ethereum.qml.QEther 1.0 Window { + id: modalStateDialog modality: Qt.WindowModal width:640 @@ -12,7 +14,7 @@ Window { visible: false property alias stateTitle: titleField.text - property alias stateBalance: balanceField.text + property alias stateBalance: balanceField.value property int stateIndex property var stateTransactions: [] signal accepted @@ -20,7 +22,7 @@ Window { function open(index, item) { stateIndex = index; stateTitle = item.title; - stateBalance = item.balance; + balanceField.value = item.balance; transactionsModel.clear(); stateTransactions = []; var transactions = item.transactions; @@ -66,8 +68,10 @@ Window { Label { text: qsTr("Balance") } - TextField { + Ether { id: balanceField + edit: true + displayFormattedValue: true Layout.fillWidth: true } @@ -114,16 +118,25 @@ 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: "0", + value: ether("0", QEther.Wei), functionId: "", - gas: "125000", - gasPrice: "100000" + gas: ether("125000", QEther.Wei), + gasPrice: ether("100000", QEther.Wei) }; transactionDialog.open(transactionsModel.count, item); diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index 519e533d5..9cd53edbe 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.ProjectModel 1.0 +import org.ethereum.qml.QEther 1.0 Rectangle { color: "#ededed" @@ -67,9 +68,13 @@ 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 item = { title: "", - balance: "100000000000000000000000000", + balance: ether, transactions: [] }; stateDialog.open(stateListModel.count, item); diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 3a32e2af5..22995d66b 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -2,8 +2,10 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.0 +import org.ethereum.qml.QEther 1.0 Window { + id: modalTransactionDialog modality: Qt.WindowModal width:640 height:480 @@ -11,9 +13,9 @@ Window { property int transactionIndex property alias transactionParams: paramsModel; - property alias gas: gasField.text; - property alias gasPrice: gasPriceField.text; - property alias transactionValue: valueField.text; + property alias gas: gasField.value; + property alias gasPrice: gasPriceField.value; + property alias transactionValue: valueField.value; property alias functionId: functionComboBox.currentText; property var itemParams; @@ -21,9 +23,9 @@ Window { function open(index, item) { transactionIndex = index; - gas = item.gas; - gasPrice = item.gasPrice; - transactionValue = item.value; + gasField.value = item.gas; + gasPriceField.value = item.gasPrice; + valueField.value = item.value; var functionId = item.functionId; itemParams = item.parameters !== undefined ? item.parameters : {}; functionsModel.clear(); @@ -53,7 +55,7 @@ Window { var parameters = func.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] : "" }); + paramsModel.append({ name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value() : "" }); } } } @@ -74,7 +76,10 @@ Window { } for (var p = 0; p < transactionDialog.transactionParams.count; p++) { var parameter = transactionDialog.transactionParams.get(p); - item.parameters[parameter.name] = parameter.value; + var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); + var param = intComponent.createObject(modalTransactionDialog); + param.setValue(parameter.value); + item.parameters[parameter.name] = param; } return item; } @@ -107,25 +112,40 @@ Window { Label { text: qsTr("Value") } - TextField { - id: valueField + Rectangle + { Layout.fillWidth: true + Ether { + id: valueField + edit: true + displayFormattedValue: true + } } Label { text: qsTr("Gas") } - TextField { - id: gasField + Rectangle + { Layout.fillWidth: true + Ether { + id: gasField + edit: true + displayFormattedValue: true + } } Label { text: qsTr("Gas price") } - TextField { - id: gasPriceField + Rectangle + { Layout.fillWidth: true + Ether { + id: gasPriceField + edit: true + displayFormattedValue: true + } } Label { diff --git a/mix/qml/js/Debugger.js b/mix/qml/js/Debugger.js index 43b15f27e..da3928105 100644 --- a/mix/qml/js/Debugger.js +++ b/mix/qml/js/Debugger.js @@ -65,9 +65,9 @@ function highlightSelection(index) function completeCtxInformation(state) { currentStep.update(state.step); - mem.update(state.newMemSize + " " + qsTr("words")); - stepCost.update(state.gasCost); - gasSpent.update(debugStates[0].gas - state.gas); + mem.update(state.newMemSize.value() + " " + qsTr("words")); + stepCost.update(state.gasCost.value()); + gasSpent.update(debugStates[0].gas.subtract(state.gas).value()); stack.listModel = state.debugStack; storage.listModel = state.debugStorage;