Browse Source

Manage solidity types:

- uint<N>, uint
	- int<N>, int
	- hash<N>, hash, address
	- bool
	- string<N>
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
b271a9df51
  1. 19
      libdevcore/CommonJS.cpp
  2. 4
      libdevcore/CommonJS.h
  3. 1
      mix/AppContext.cpp
  4. 12
      mix/ClientModel.cpp
  5. 25
      mix/CodeHighlighter.cpp
  6. 89
      mix/ContractCallDataEncoder.cpp
  7. 18
      mix/ContractCallDataEncoder.h
  8. 2
      mix/QBigInt.h
  9. 2
      mix/QFunctionDefinition.cpp
  10. 8
      mix/QVariableDeclaration.h
  11. 105
      mix/QVariableDefinition.cpp
  12. 10
      mix/QVariableDefinition.h
  13. 8
      mix/qml.qrc
  14. 30
      mix/qml/QBoolTypeView.qml
  15. 22
      mix/qml/QHashTypeView.qml
  16. 25
      mix/qml/QIntTypeView.qml
  17. 15
      mix/qml/QRealTypeView.qml
  18. 8
      mix/qml/QStringType.qml
  19. 25
      mix/qml/QStringTypeView.qml
  20. 1
      mix/qml/StateList.qml
  21. 136
      mix/qml/TransactionDialog.qml

19
libdevcore/CommonJS.cpp

@ -45,6 +45,13 @@ bytes padded(bytes _b, unsigned _l)
return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l)));
}
bytes paddedRight(bytes _b, unsigned _l)
{
while (_b.size() < _l)
_b.insert(_b.end(), 0);
return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l)));
}
bytes unpadded(bytes _b)
{
auto p = asString(_b).find_last_not_of((char)0);
@ -52,6 +59,18 @@ bytes unpadded(bytes _b)
return _b;
}
std::string unpadRight(std::string _b)
{
while (true)
{
auto p = _b.find_last_of("0");
if (p == _b.size() - 1)
_b = _b.substr(0, _b.size() - 1);
else
return _b;
}
}
std::string unpadLeft(std::string _b)
{
auto p = _b.find_first_not_of('0');

4
libdevcore/CommonJS.h

@ -50,6 +50,10 @@ inline std::string toJS(dev::bytes const& _n)
bytes jsToBytes(std::string const& _s);
/// Add '0' on the head of _b until _l.
bytes padded(bytes _b, unsigned _l);
/// Add '0' on the queue of _b until _l.
bytes paddedRight(bytes _b, unsigned _l);
/// Remove all trailing '0'
std::string unpadRight(std::string _b);
/// Removing all trailing '0'. Returns empty array if input contains only '0' char.
bytes unpadded(bytes _s);
/// Remove all '0' on the head of _s. Returns 0 if _s contains only '0'.

1
mix/AppContext.cpp

@ -66,6 +66,7 @@ void AppContext::load()
qmlRegisterType<QRealType>("org.ethereum.qml.QRealType", 1, 0, "QRealType");
qmlRegisterType<QStringType>("org.ethereum.qml.QStringType", 1, 0, "QStringType");
qmlRegisterType<QHashType>("org.ethereum.qml.QHashType", 1, 0, "QHashType");
qmlRegisterType<QBoolType>("org.ethereum.qml.QBoolType", 1, 0, "QBoolType");
QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml"));
QObject* projectModel = projectModelComponent.create();
if (projectModelComponent.isError())

12
mix/ClientModel.cpp

@ -119,12 +119,11 @@ void ClientModel::debugState(QVariantMap _state)
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);
for (auto p = params.cbegin(); p != params.cend(); ++p)
QVariantList qParams = transaction.value("qType").toList();
for (QVariant const& variant: qParams)
{
QVariableDefinition* param = qvariant_cast<QVariableDefinition*>(p.value());
QVariableDefinition* param = qvariant_cast<QVariableDefinition*>(variant);
transactionSettings.parameterValues.push_back(param);
}
@ -173,7 +172,12 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
c.encode(f);
for (int p = 0; p < t.parameterValues.size(); p++)
{
qDebug() << " encode input parameters : " + t.parameterValues.at(p)->declaration()->type();
qDebug() << t.parameterValues.at(p)->declaration()->type();
qDebug() << t.parameterValues.at(p)->value();
c.push(t.parameterValues.at(p)->encodeValue());
}
transactonData.emplace_back(c.encodedData());
}

25
mix/CodeHighlighter.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 CodeHighlighter.cpp
* @author Arkadiy Paronyan arkadiy@ethdev.com
@ -102,7 +102,8 @@ void CodeHighlighter::processAST(dev::solidity::ASTNode const& _ast)
void CodeHighlighter::processError(dev::Exception const& _exception)
{
Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location));
if (location)
m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location));
}
void CodeHighlighter::processComments(std::string const& _source)

89
mix/ContractCallDataEncoder.cpp

@ -35,6 +35,7 @@ using namespace dev::mix;
bytes ContractCallDataEncoder::encodedData()
{
qDebug() << " encoded data " << QString::fromStdString(toJS(m_encodedData));
return m_encodedData;
}
@ -62,96 +63,16 @@ QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QVariableDecla
def = new QIntType(dec, QString());
else if (dec->type().contains("real"))
def = new QRealType(dec, QString());
else if (dec->type().contains("bool"))
def = new QBoolType(dec, QString());
else if (dec->type().contains("string") || dec->type().contains("text"))
def = new QStringType(dec, QString());
else if (dec->type().contains("hash") || dec->type().contains("address"))
def = new QHashType(dec, QString());
def->decodeValue(returnValue);
r.push_back(def);
returnValue = returnValue.substr(def->length(), returnValue.length() - 1);
/*QStringList tLength = typeLength(dec->type());
QRegExp intTest("(uint|int|hash|address)");
QRegExp stringTest("(string|text)");
QRegExp realTest("(real|ureal)");
if (intTest.indexIn(dec->type()) != -1)
{
std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2);
QString value = resolveNumber(QString::fromStdString(rawParam));
r.append(new QVariableDefinition(dec, value));
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
else if (dec->type() == "bool")
{
std::string rawParam = returnValue.substr(0, 2);
std::string unpadded = unpadLeft(rawParam);
r.append(new QVariableDefinition(dec, QString::fromStdString(unpadded)));
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
else if (stringTest.indexIn(dec->type()) != -1)
{
if (tLength.length() == 0)
{
QString strLength = QString::fromStdString(returnValue.substr(0, 2));
returnValue = returnValue.substr(2, returnValue.length() - 1);
QString strValue = QString::fromStdString(returnValue.substr(0, strLength.toInt()));
r.append(new QVariableDefinition(dec, strValue));
returnValue = returnValue.substr(strValue.length(), returnValue.length() - 1);
}
else
{
std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2);
r.append(new QVariableDefinition(dec, QString::fromStdString(rawParam)));
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
}
else if (realTest.indexIn(dec->type()) != -1)
{
QString value;
for (QString str: tLength)
{
std::string rawParam = returnValue.substr(0, (str.toInt() / 8) * 2);
QString value = resolveNumber(QString::fromStdString(rawParam));
value += value + "x";
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
r.append(new QVariableDefinition(dec, value));
}*/
returnValue = returnValue.substr(32 * 2, returnValue.length() - 1);
qDebug() << "decoded return value : " << dec->type() << " " << def->value();
}
return r;
}
QString ContractCallDataEncoder::resolveNumber(QString const& _rawParam)
{
std::string unPadded = unpadLeft(_rawParam.toStdString());
int x = std::stol(unPadded, nullptr, 16);
std::stringstream ss;
ss << std::dec << x;
return QString::fromStdString(ss.str());
}
QString ContractCallDataEncoder::convertToReadable(std::string _v, QVariableDeclaration* _dec)
{
if (_dec->type().indexOf("int") != -1)
return convertToInt(_v);
else if (_dec->type().indexOf("bool") != -1)
return convertToBool(_v);
else
return QString::fromStdString(_v);
}
QString ContractCallDataEncoder::convertToBool(std::string _v)
{
return _v == "1" ? "true" : "false";
}
QString ContractCallDataEncoder::convertToInt(std::string _v)
{
//TO DO to be improve to manage all int, uint size (128, 256, ...) in ethereum QML types task #612.
int x = std::stol(_v, nullptr, 16);
std::stringstream ss;
ss << std::dec << x;
return QString::fromStdString(ss.str());
}

18
mix/ContractCallDataEncoder.h

@ -41,33 +41,17 @@ class ContractCallDataEncoder
{
public:
ContractCallDataEncoder() {}
/// Encode variable in order to be sent as parameter.
void encode(QVariableDeclaration const* _dec, QString _baseType, QStringList _length, QString _value);
/// Encode variable in order to be sent as parameter.
void encode(QVariableDeclaration const* _dec, QString _value);
/// Encode variable in order to be sent as parameter.
void encode(QVariableDeclaration const* _dec, bool _value);
/// Encode hash of the function to call.
void encode(QFunctionDefinition const* _function);
/// Decode variable in order to be sent to QML view.
QList<QVariableDefinition*> decode(QList<QVariableDeclaration*> _dec, bytes _value);
/// Get all encoded data encoded by encode function.
bytes encodedData();
/// Encode the given list of parameters (@a _p)
void encode(QVariableDefinition const* _dec);
/// Push the given @ _b to the current stored bytes.
/// Push the given @ _b to the current param context.
void push(bytes _b);
private:
//int padding(QString _type);
bytes m_encodedData;
static bytes encodeNumber(QString _value, QString _length);
static QString convertToReadable(std::string _v, QVariableDeclaration* _dec);
static QString convertToBool(std::string _v);
static QString convertToInt(std::string _v);
static int integerPadding(int _bitValue);
static QString formatBool(bool _value);
static QString resolveNumber(QString const& _rawParams);
};
}

2
mix/QBigInt.h

@ -28,7 +28,6 @@
#include <QQmlEngine>
#include <libdevcore/CommonJS.h>
#include <libdevcore/Common.h>
#include "QVariableDefinition.h"
using namespace dev;
@ -76,6 +75,7 @@ public:
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(QString const& _value, QObject* _parent = 0): QObject(_parent) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); setValue(_value); }
~QBigInt() {}
/// @returns the current used big integer.

2
mix/QFunctionDefinition.cpp

@ -33,8 +33,6 @@ QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionDefinition const
for (unsigned i = 0; i < parameters.size(); i++)
m_parameters.append(new QVariableDeclaration(parameters.at(i).get()));
std::vector<std::shared_ptr<VariableDeclaration>> returnParameters = _f->getReturnParameters();
for (unsigned i = 0; i < returnParameters.size(); i++)
m_returnParameters.append(new QVariableDeclaration(returnParameters.at(i).get()));

8
mix/QVariableDeclaration.h

@ -19,6 +19,7 @@
* @date 2014
*/
#include <QDebug>
#include <QStringList>
#include <libsolidity/AST.h>
#include "QBasicNodeDefinition.h"
@ -39,13 +40,6 @@ public:
QVariableDeclaration() {}
QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {}
Q_INVOKABLE QString type() const { return m_type; }
QStringList typeLength()
{
QRegExp rules("\\d");
int pos = 0;
while ((pos = rules.indexIn(m_type, pos)) != -1) {}
return rules.capturedTexts();
}
private:
QString m_type;

105
mix/QVariableDefinition.cpp

@ -19,6 +19,7 @@
* @date 2014
*/
#include <libdevcore/CommonData.h>
#include <libdevcore/CommonJS.h>
#include "QVariableDefinition.h"
@ -60,23 +61,25 @@ QVariableDefinition* QVariableDefinitionList::val(int _idx)
*/
dev::bytes QIntType::encodeValue()
{
dev::bigint i(value().toStdString());
if (i < 0)
i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1;
std::ostringstream s;
s << std::hex << "0x" << value().toStdString();
return padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8);
}
int QIntType::length()
{
return (declaration()->typeLength().first().toInt() / 8) * 2;
s << std::hex << "0x" << i;
qDebug() << " int input " << QString::fromStdString(toJS(padded(jsToBytes(s.str()), 32)));
return padded(jsToBytes(s.str()), 32);
}
void QIntType::decodeValue(std::string const& _rawValue)
{
std::string unPadded = unpadLeft(_rawValue);
int x = std::stol(unPadded, nullptr, 16);
std::stringstream ss;
ss << std::dec << x;
setValue(QString::fromStdString(ss.str()));
std::string rawParam = _rawValue.substr(0, 32 * 2);
dev::bigint bigint = dev::bigint("0x" + rawParam);
if (((bigint >> 32) & 1) == 1)
bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1;
std::ostringstream s;
s << std::dec << bigint;
qDebug() << " int output " << QString::fromStdString(s.str());
setValue(QString::fromStdString(s.str()));
}
/*
@ -84,17 +87,14 @@ void QIntType::decodeValue(std::string const& _rawValue)
*/
dev::bytes QHashType::encodeValue()
{
return bytes();
}
int QHashType::length()
{
return (declaration()->typeLength().first().toInt() / 8) * 2;
return padded(asBytes(value().toStdString()), 32);
}
void QHashType::decodeValue(std::string const& _rawValue)
{
Q_UNUSED(_rawValue);
std::string rawParam = _rawValue.substr(0, 32 * 2);
std::string unPadded = unpadLeft(rawParam);
setValue(QString::fromStdString(unPadded));
}
/*
@ -102,34 +102,12 @@ void QHashType::decodeValue(std::string const& _rawValue)
*/
dev::bytes QRealType::encodeValue()
{
std::ostringstream s;
s << std::hex << "0x" << value().split("x").first().toStdString();
bytes first = padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8);
s << std::hex << "0x" << value().split("x").last().toStdString();
bytes second = padded(jsToBytes(s.str()), declaration()->typeLength().last().toInt() / 8);
first.insert(first.end(), second.begin(), second.end());
return first;
}
int QRealType::length()
{
return (declaration()->typeLength().first().toInt() / 8) * 2 + (declaration()->typeLength().last().toInt() / 8) * 2;
return bytes();
}
void QRealType::decodeValue(std::string const& _rawValue)
{
QString value;
for (QString str: declaration()->typeLength())
{
std::string rawParam = _rawValue.substr(0, (str.toInt() / 8) * 2);
std::string unPadded = unpadLeft(rawParam);
int x = std::stol(unPadded, nullptr, 16);
std::stringstream ss;
ss << std::dec << x;
value += QString::fromStdString(ss.str()) + "x";
}
setValue(value);
Q_UNUSED(_rawValue);
}
/*
@ -137,30 +115,24 @@ void QRealType::decodeValue(std::string const& _rawValue)
*/
dev::bytes QStringType::encodeValue()
{
return padded(jsToBytes(value().toStdString()), declaration()->typeLength().first().toInt() / 8);
}
int QStringType::length()
{
if (declaration()->typeLength().length() == 0)
return value().length() + 2;
else
return (declaration()->typeLength().first().toInt() / 8) * 2;
qDebug() << QString::fromStdString(toJS(paddedRight(asBytes(value().toStdString()), 32)));
return paddedRight(asBytes(value().toStdString()), 32);
}
void QStringType::decodeValue(std::string const& _rawValue)
{
if (declaration()->typeLength().first().length() == 0)
std::string rawParam = _rawValue.substr(0, 32 * 2);
rawParam = unpadRight(rawParam);
std::string res;
res.reserve(rawParam.size() / 2);
for (unsigned int i = 0; i < rawParam.size(); i += 2)
{
std::string strLength = _rawValue.substr(0, 2);
std::string strValue = _rawValue.substr(2, std::stoi(strLength));
setValue(QString::fromStdString(strValue));
}
else
{
std::string rawParam = _rawValue.substr(0, (declaration()->typeLength().first().toInt() / 8) * 2);
setValue(QString::fromStdString(rawParam));
std::istringstream iss(rawParam.substr(i, 2));
int temp;
iss >> std::hex >> temp;
res += static_cast<char>(temp);
}
setValue(QString::fromStdString(res));
}
/*
@ -168,18 +140,13 @@ void QStringType::decodeValue(std::string const& _rawValue)
*/
dev::bytes QBoolType::encodeValue()
{
return padded(jsToBytes(value().toStdString()), 1);
}
int QBoolType::length()
{
return 1;
qDebug() << QString::fromStdString(toJS(padded(jsToBytes(value().toStdString()), 32)));
return padded(jsToBytes(value().toStdString()), 32);
}
void QBoolType::decodeValue(std::string const& _rawValue)
{
std::string rawParam = _rawValue.substr(0, 2);
std::string rawParam = _rawValue.substr(0, 32 * 2);
std::string unpadded = unpadLeft(rawParam);
setValue(QString::fromStdString(unpadded));
}

10
mix/QVariableDefinition.h

@ -22,6 +22,7 @@
#pragma once
#include <QAbstractListModel>
#include "QBigInt.h"
#include "QVariableDeclaration.h"
namespace dev
@ -48,7 +49,6 @@ public:
Q_INVOKABLE void setDeclaration(QVariableDeclaration* _dec) { m_dec = _dec; }
virtual bytes encodeValue() = 0;
virtual void decodeValue(std::string const& _rawValue) = 0;
virtual int length() = 0;
private:
QString m_value;
@ -82,7 +82,7 @@ public:
QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
int length() override;
QBigInt* toBigInt() { return new QBigInt(value()); }
};
class QRealType: public QVariableDefinition
@ -94,7 +94,6 @@ public:
QRealType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
int length() override;
};
class QStringType: public QVariableDefinition
@ -106,7 +105,6 @@ public:
QStringType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
int length() override;
};
class QHashType: public QVariableDefinition
@ -118,7 +116,6 @@ public:
QHashType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
int length() override;
};
class QBoolType: public QVariableDefinition
@ -130,13 +127,12 @@ public:
QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
int length() override;
bool toBool() { return value() != "0"; }
};
}
}
//Q_DECLARE_METATYPE(dev::mix::QVariableDefinition*)
Q_DECLARE_METATYPE(dev::mix::QIntType*)
Q_DECLARE_METATYPE(dev::mix::QStringType*)
Q_DECLARE_METATYPE(dev::mix::QHashType*)

8
mix/qml.qrc

@ -41,7 +41,7 @@
<file>qml/Ether.qml</file>
<file>qml/EtherValue.qml</file>
<file>qml/BigIntValue.qml</file>
<file>qml/QVariableDefinition.qml</file>
<file>qml/QVariableDefinition.qml</file>
<file>qml/QBoolType.qml</file>
<file>qml/QHashType.qml</file>
<file>qml/QIntType.qml</file>
@ -49,5 +49,11 @@
<file>qml/js/QEtherHelper.js</file>
<file>qml/js/TransactionHelper.js</file>
<file>qml/Splitter.qml</file>
<file>qml/QStringType.qml</file>
<file>qml/QBoolTypeView.qml</file>
<file>qml/QIntTypeView.qml</file>
<file>qml/QRealTypeView.qml</file>
<file>qml/QStringTypeView.qml</file>
<file>qml/QHashTypeView.qml</file>
</qresource>
</RCC>

30
mix/qml/QBoolTypeView.qml

@ -0,0 +1,30 @@
import QtQuick 2.0
import QtQuick.Controls 1.3
Item
{
id: editRoot
property string text
Rectangle {
anchors.fill: parent
ComboBox
{
id: boolCombo
anchors.fill: parent
onCurrentIndexChanged:
{
text = coolComboModel.get(currentIndex).value;
editRoot.textChanged();
}
model: ListModel
{
id: coolComboModel
ListElement { text: qsTr("True"); value: "1" }
ListElement { text: qsTr("False"); value: "0" }
}
}
}
}

22
mix/qml/QHashTypeView.qml

@ -0,0 +1,22 @@
import QtQuick 2.0
Item
{
property alias text: textinput.text
id: editRoot
Rectangle {
anchors.fill: parent
TextInput {
id: textinput
text: text
anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: textinput.forceActiveFocus()
}
}
}
}

25
mix/qml/QIntTypeView.qml

@ -0,0 +1,25 @@
import QtQuick 2.0
Item
{
property alias text: textinput.text
id: editRoot
Rectangle {
anchors.fill: parent
TextInput {
id: textinput
text: text
anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: textinput.forceActiveFocus()
}
}
}
}

15
mix/qml/QRealTypeView.qml

@ -0,0 +1,15 @@
import QtQuick 2.0
Component
{
Rectangle {
anchors.fill: parent
Text{
anchors.fill: parent
text: qsTr("Real")
}
}
}

8
mix/qml/QStringType.qml

@ -0,0 +1,8 @@
import QtQuick 2.0
import org.ethereum.qml.QStringType 1.0
QStringType
{
property string view: "qrc:/qml/QStringTypeView.qml"
}

25
mix/qml/QStringTypeView.qml

@ -0,0 +1,25 @@
import QtQuick 2.0
Item
{
property alias text: textinput.text
id: editRoot
Rectangle {
anchors.fill: parent
TextInput {
id: textinput
text: text
anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: textinput.forceActiveFocus()
}
}
}
}

1
mix/qml/StateList.qml

@ -59,7 +59,6 @@ Rectangle {
stateList.push(item);
stateListModel.append(item);
}
stateListModel.save();
}
}

136
mix/qml/TransactionDialog.qml

@ -21,10 +21,12 @@ Window {
property var itemParams;
property bool isConstructorTransaction;
property bool useTransactionDefaultValue: false
property var qType;
signal accepted;
function open(index, item) {
qType = [];
rowFunction.visible = !useTransactionDefaultValue;
rowValue.visible = !useTransactionDefaultValue;
rowGas.visible = !useTransactionDefaultValue;
@ -39,8 +41,8 @@ Window {
rowFunction.visible = !item.executeConstructor;
itemParams = item.parameters !== undefined ? item.parameters : {};
console.log("opening ...");
console.log(JSON.stringify(itemParams));
console.log("save parameters : ");
console.log(JSON.stringify(item.qType));
functionsModel.clear();
var functionIndex = -1;
var functions = codeModel.code.contract.functions;
@ -70,8 +72,6 @@ Window {
}
function loadParameters() {
console.log("opening3 ...");
console.log(JSON.stringify(itemParams));
if (!paramsModel)
return;
if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) {
@ -81,8 +81,7 @@ Window {
var pname = parameters[p].name;
var varComponent;
var type = parameters[p].type;
console.log("type : " + type);
console.log("name : " + pname);
if (type.indexOf("int") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QIntType.qml");
else if (type.indexOf("real") !== -1)
@ -91,14 +90,16 @@ Window {
varComponent = Qt.createComponent("qrc:/qml/QStringType.qml");
else if (type.indexOf("hash") !== -1 || type.indexOf("address") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QHashType.qml");
else if (type.indexOf("bool") !== -1)
varComponent = Qt.createComponent("qrc:/qml/QBoolType.qml");
var param = varComponent.createObject(modalTransactionDialog);
var value = itemParams[pname] !== undefined ? itemParams[pname].value : "";
var value = itemParams[pname] !== undefined ? itemParams[pname] : "";
console.log("loading parameters");
console.log(JSON.stringify(itemParams));
param.setValue(value);
param.setDeclaration(parameters[p]);
paramsModel.append({ internalValue: param, name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value : "" });
qType.push({ name: pname, value: param });
paramsModel.append({ name: pname, type: parameters[p].type, value: value });
}
}
}
@ -108,6 +109,15 @@ Window {
visible = false;
}
function getqTypeParam(name)
{
for (var k in qType)
{
if (qType[k].name === name)
return qType[k].value;
}
}
function getItem()
{
var item;
@ -132,18 +142,15 @@ Window {
if (isConstructorTransaction)
item.functionId = qsTr("Constructor");
var orderedQType = [];
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);
//param.setValue(parameter.value);
//parameter.internalValue.setValue(parameter.value);
console.log("onget");
console.log(JSON.stringify(parameter));
item.parameters[parameter.name] = parameter;
getqTypeParam(parameter.name).setValue(parameter.value);
orderedQType.push(getqTypeParam(parameter.name));
item.parameters[parameter.name] = parameter.value;
}
console.log("return item");
console.log(JSON.stringify(item));
console.log(JSON.stringify(qType));
item.qType = orderedQType;
return item;
}
@ -247,7 +254,6 @@ Window {
TableView {
model: paramsModel
Layout.fillWidth: true
TableViewColumn {
role: "name"
title: "Name"
@ -264,7 +270,13 @@ Window {
width: 120
}
itemDelegate: {
rowDelegate:
{
return rowDelegate
}
itemDelegate:
{
return editableDelegate;
}
}
@ -295,19 +307,15 @@ Window {
}
Component {
id: editableDelegate
id: rowDelegate
Item {
height: 100
}
}
Text {
width: parent.width
anchors.margins: 4
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
elide: styleData.elideMode
text: styleData.value !== undefined ? styleData.value : ""
color: styleData.textColor
visible: !styleData.selected
}
Component {
id: editableDelegate
Item {
Loader {
id: loaderEditor
anchors.fill: parent
@ -319,11 +327,73 @@ Window {
paramsModel.setProperty(styleData.row, styleData.role, loaderEditor.item.text);
}
}
sourceComponent: (styleData.selected) ? editor : null
sourceComponent:
{
if (styleData.role === "value")
{
if (paramsModel.get(styleData.row) === 'undefined')
return null;
if (paramsModel.get(styleData.row).type.indexOf("int") !== -1)
return intViewComp;
else if (paramsModel.get(styleData.row).type.indexOf("bool") !== -1)
return boolViewComp;
else if (paramsModel.get(styleData.row).type.indexOf("string") !== -1)
return stringViewComp;
else if (paramsModel.get(styleData.row).type.indexOf("hash") !== -1)
return hashViewComp;
}
else
return editor;
}
Component
{
id: intViewComp
QIntTypeView
{
id: intView
text: styleData.value
}
}
Component
{
id: boolViewComp
QBoolTypeView
{
id: boolView
text: styleData.value
}
}
Component
{
id: stringViewComp
QStringTypeView
{
id: stringView
text: styleData.value
}
}
Component
{
id: hashViewComp
QHashTypeView
{
id: hashView
text: styleData.value
}
}
Component {
id: editor
TextInput {
id: textinput
readOnly: true
color: styleData.textColor
text: styleData.value
MouseArea {

Loading…
Cancel
Save