Browse Source

- misc fixes.

cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
9c777a4d3c
  1. 2
      mix/AppContext.cpp
  2. 6
      mix/ClientModel.cpp
  3. 19
      mix/DebuggingStateWrapper.cpp
  4. 15
      mix/DebuggingStateWrapper.h
  5. 22
      mix/MixClient.cpp
  6. 22
      mix/MixClient.h
  7. 11
      mix/QBigInt.h
  8. 26
      mix/QEther.cpp
  9. 26
      mix/QEther.h
  10. 1
      mix/qml.qrc
  11. 13
      mix/qml/BigIntValue.qml
  12. 73
      mix/qml/Ether.qml
  13. 7
      mix/qml/EtherValue.qml
  14. 13
      mix/qml/StateDialog.qml
  15. 4
      mix/qml/StateList.qml
  16. 20
      mix/qml/TransactionDialog.qml
  17. 6
      mix/qml/js/Debugger.js

2
mix/AppContext.cpp

@ -50,9 +50,9 @@ AppContext::AppContext(QQmlApplicationEngine* _engine)
qmlRegisterType<FileIo>("org.ethereum.qml", 1, 0, "FileIo");
qmlRegisterSingletonType(QUrl("qrc:/qml/ProjectModel.qml"), "org.ethereum.qml.ProjectModel", 1, 0, "ProjectModel");
qmlRegisterType<QEther>("org.ethereum.qml.QEther", 1, 0, "QEther");
qmlRegisterType<QBigInt>("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()

6
mix/ClientModel.cpp

@ -72,9 +72,9 @@ void ClientModel::debugState(QVariantMap _state)
QVariantMap transaction = t.toMap();
QString functionId = transaction.value("functionId").toString();
u256 gas = (qvariant_cast<QEther*>(_state.value("gas")))->toU256Wei();
u256 value = (qvariant_cast<QEther*>(_state.value("value")))->toU256Wei();
u256 gasPrice = (qvariant_cast<QEther*>(_state.value("gasPrice")))->toU256Wei();
u256 gas = (qvariant_cast<QEther*>(transaction.value("gas")))->toU256Wei();
u256 value = (qvariant_cast<QEther*>(transaction.value("value")))->toU256Wei();
u256 gasPrice = (qvariant_cast<QEther*>(transaction.value("gasPrice")))->toU256Wei();
QVariantMap params = transaction.value("parameters").toMap();
TransactionSettings transactionSettings(functionId, value, gas, gasPrice);

19
mix/DebuggingStateWrapper.cpp

@ -29,6 +29,7 @@
#include <libevmcore/Instruction.h>
#include <libdevcore/Common.h>
#include "DebuggingStateWrapper.h"
#include "QBigInt.h"
using namespace dev;
using namespace dev::eth;
using namespace dev::mix;
@ -66,25 +67,19 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
return std::make_tuple(codeStr, QPointer<QQMLMap>(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, this);
}
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, this);
}
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, this);
}
QStringList DebuggingStateWrapper::debugStack()

15
mix/DebuggingStateWrapper.h

@ -29,6 +29,7 @@
#include <libethereum/Executive.h>
#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.

22
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 <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file MixClient.cpp
* @author Yann yann@ethdev.com

22
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 <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file MixClient.h
* @author Yann yann@ethdev.com

11
mix/QBigInt.h

@ -17,7 +17,7 @@
/** @file QBigInt.h
* @author Yann yann@ethdev.com
* @date 2015
* Represent a big integer (u256, bigint, ...) to be used in QML.
* Represent a big integer (u256, bigint) to be used in QML.
*/
#pragma once
@ -66,16 +66,25 @@ class QBigInt: public QObject
Q_OBJECT
public:
QBigInt(QObject* _parent = 0): QObject(_parent), m_internalValue(dev::u256(0)) {}
QBigInt(dev::u256 const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) {}
QBigInt(dev::bigint const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) {}
QBigInt(BigIntVariant const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value){}
~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:

26
mix/QEther.cpp

@ -29,27 +29,27 @@ QString QEther::format() const
return QString::fromStdString(dev::eth::formatBalance(boost::get<dev::u256>(toWei()->internalValue())));
}
QString QEther::unit() const
QBigInt* QEther::toWei() const
{
QMetaEnum units = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("EtherUnit"));
const char* key = units.valueToKey(m_currentUnit);
return QString(key);
for (std::pair<dev::u256, std::string> 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"));
m_currentUnit = static_cast<EtherUnit>(units.keysToValue(_unit.toStdString().c_str()));
}
QBigInt* QEther::toWei() const
{
QMetaEnum units = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("EtherUnit"));
const char* key = units.valueToKey(m_currentUnit);
for (std::pair<dev::u256, std::string> rawUnit: dev::eth::units())
for (int k = 0; k < units.keyCount(); k++)
{
if (rawUnit.second == QString(key).toStdString())
return multiply(new QBigInt(rawUnit.first));
if (QString(units.key(k)).toLower() == _unit)
{
m_currentUnit = static_cast<EtherUnit>(units.keysToValue(units.key(k)));
return;
}
}
return new QBigInt(dev::u256(0));
}

26
mix/QEther.h

@ -17,7 +17,7 @@
/** @file QEther.h
* @author Yann yann@ethdev.com
* @date 2014
* Represent an Ether value in QML (mapped to u256 in c++).
* Represent an amount of Ether in QML (mapped to u256 in c++).
*/
#pragma once
@ -36,7 +36,7 @@ class QEther: public QBigInt
Q_OBJECT
Q_ENUMS(EtherUnit)
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(EtherUnit unit READ unit WRITE setUnit NOTIFY unitChanged)
public:
enum EtherUnit
@ -52,25 +52,31 @@ public:
Tether,
Gether,
Mether,
grand,
ether,
finney,
szabo,
Grand,
Ether,
Finney,
Szabo,
Gwei,
Mwei,
Kwei,
wei
Wei
};
QEther(QObject* _parent = 0): QBigInt(dev::u256(0), _parent), m_currentUnit(EtherUnit::ether) {}
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;
Q_INVOKABLE void setValue(QString const& _value) { m_internalValue = dev::jsToU256(_value.toStdString()); }
Q_INVOKABLE QString unit() 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<dev::u256>(toWei()->internalValue()); }
private:

1
mix/qml.qrc

@ -42,5 +42,6 @@
<file>qml/WebPreview.qml</file>
<file>qml/Ether.qml</file>
<file>qml/EtherValue.qml</file>
<file>qml/BigIntValue.qml</file>
</qresource>
</RCC>

13
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
}

73
mix/qml/Ether.qml

@ -1,3 +1,10 @@
/*
* 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
@ -13,20 +20,16 @@ Rectangle {
function update()
{
etherValueEdit.text = value.value;
selectUnit(value.unit);
if (value !== undefined)
{
etherValueEdit.text = value.value;
selectUnit(value.unit);
}
}
function selectUnit(unit)
{
for(var i = 0; i < unitsModel.count; ++i)
{
if (unitsModel.get(i).text === unit)
{
units.currentIndex = i;
return;
}
}
units.currentIndex = unit;
}
RowLayout
@ -43,8 +46,11 @@ Rectangle {
{
onTextChanged:
{
value.setValue(text)
formattedValue.text = value.format();
if (value !== undefined)
{
value.setValue(text)
formattedValue.text = value.format();
}
}
width: parent.width
readOnly: !edit
@ -64,30 +70,33 @@ Rectangle {
id: units
onCurrentTextChanged:
{
value.setUnit(currentText);
formattedValue.text = value.format();
if (value !== undefined)
{
value.setUnit(currentText);
formattedValue.text = value.format();
}
}
model: ListModel {
id: unitsModel
ListElement { text: "wei"; }
ListElement { text: "Kwei"; }
ListElement { text: "Mwei"; }
ListElement { text: "Gwei"; }
ListElement { text: "szabo"; }
ListElement { text: "finney"; }
ListElement { text: "ether"; }
ListElement { text: "grand"; }
ListElement { text: "Mether"; }
ListElement { text: "Gether"; }
ListElement { text: "Tether"; }
ListElement { text: "Pether"; }
ListElement { text: "Eether"; }
ListElement { text: "Zether"; }
ListElement { text: "Yether"; }
ListElement { text: "Nether"; }
ListElement { text: "Dether"; }
ListElement { text: "Vether"; }
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

7
mix/qml/EtherValue.qml

@ -1,3 +1,6 @@
/*
* Used to instanciate a QEther obj using Qt.createComponent function.
*/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
@ -7,6 +10,6 @@ import org.ethereum.qml.QEther 1.0
QEther
{
id: basicEther
value: "1000000"
unit: "ether"
value: "100000000000"
unit: QEther.Wei
}

13
mix/qml/StateDialog.qml

@ -5,6 +5,7 @@ import QtQuick.Window 2.0
import org.ethereum.qml.QEther 1.0
Window {
id: modalStateDialog
modality: Qt.WindowModal
width:640
@ -72,10 +73,6 @@ Window {
edit: true
displayFormattedValue: true
Layout.fillWidth: true
value: QEther {
value: "100000"
unit: "ether"
}
}
Label {
@ -124,7 +121,7 @@ Window {
function ether(_value, _unit)
{
var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml");
var ether = etherComponent.createObject(transactionsModel);
var ether = etherComponent.createObject(modalStateDialog);
ether.setValue(_value);
ether.setUnit(_unit);
return ether;
@ -136,10 +133,10 @@ Window {
// 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", "ether"),
value: ether("0", QEther.Wei),
functionId: "",
gas: ether("125000", "ether"),
gasPrice: ether("100000", "ether")
gas: ether("125000", QEther.Wei),
gasPrice: ether("100000", QEther.Wei)
};
transactionDialog.open(transactionsModel.count, item);

4
mix/qml/StateList.qml

@ -69,9 +69,9 @@ Rectangle {
function addState() {
var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml");
var ether = etherComponent.createObject(stateListModel);
var ether = etherComponent.createObject(stateListContainer);
ether.setValue("100000000000000000000000000");
ether.setUnit("ether");
ether.setUnit(QEther.Wei);
var item = {
title: "",
balance: ether,

20
mix/qml/TransactionDialog.qml

@ -5,6 +5,7 @@ import QtQuick.Window 2.0
import org.ethereum.qml.QEther 1.0
Window {
id: modalTransactionDialog
modality: Qt.WindowModal
width:640
height:480
@ -75,10 +76,9 @@ Window {
}
for (var p = 0; p < transactionDialog.transactionParams.count; p++) {
var parameter = transactionDialog.transactionParams.get(p);
var etherComponent = Qt.createComponent("qrc:/qml/EtherValue.qml");
var param = etherComponent.createObject(stateListModel);
ether.setValue(parameter.value);
ether.setUnit("ether");
var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml");
var param = intComponent.createObject(modalTransactionDialog);
param.setValue(parameter.value);
item.parameters[parameter.name] = param;
}
return item;
@ -119,10 +119,6 @@ Window {
id: valueField
edit: true
displayFormattedValue: true
value: QEther {
value: "100000"
unit: "ether"
}
}
}
@ -136,10 +132,6 @@ Window {
id: gasField
edit: true
displayFormattedValue: true
value: QEther {
value: "100000"
unit: "ether"
}
}
}
@ -153,10 +145,6 @@ Window {
id: gasPriceField
edit: true
displayFormattedValue: true
value: QEther {
value: "100000"
unit: "ether"
}
}
}

6
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;

Loading…
Cancel
Save