diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index a1aae3f79..3c635b8b0 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -97,37 +97,34 @@ void ContractCallDataEncoder::encodeArray(QJsonArray const& _array, QList _ void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const& _type) { - QStringList strList; - if (_type.array) + if (_type.dynamicSize && (_type.type == SolidityType::Type::Bytes || _type.type == SolidityType::Type::String)) + { + bytes empty(32); + size_t sizePos = m_dynamicData.size(); + m_dynamicData += empty; //reserve space for count + u256 count = encodeSingleItem(_data.toString(), _type, m_dynamicData); + vector_ref sizeRef(m_dynamicData.data() + sizePos, 32); + toBigEndian(count, sizeRef); + m_staticOffsetMap.push_back(std::make_pair(m_encodedData.size(), sizePos)); + m_encodedData += empty; //reserve space for offset + } + else if (_type.array) { QList dim = extractDimension(_type. name); bytes content; - QJsonDocument jsonResponse = QJsonDocument::fromJson(_data.toString().toUtf8()); - QJsonArray jsonObject = jsonResponse.array(); size_t size = m_encodedData.size(); - if (dim[0] == -1) + if (dim.front() == -1) { m_encodedData += bytes(32); // reserve space for offset m_staticOffsetMap.push_back(std::make_pair(size, m_dynamicData.size())); } - encodeArray(jsonObject, dim, _type, content); + encodeArray(_data.toJsonArray(), dim, _type, content); if (!_type.dynamicSize) m_encodedData.insert(m_encodedData.end(), content.begin(), content.end()); else m_dynamicData.insert(m_dynamicData.end(), content.begin(), content.end()); } - else if (_type.dynamicSize && _type.type == SolidityType::Type::Bytes) - { - bytes empty(32); - size_t sizePos = m_dynamicData.size(); - m_dynamicData += empty; //reserve space for count - u256 count = encodeSingleItem(_data.toString(), _type, m_dynamicData); - vector_ref sizeRef(m_dynamicData.data() + sizePos, 32); - toBigEndian(count, sizeRef); - m_staticOffsetMap.push_back(std::make_pair(m_encodedData.size(), sizePos)); - m_encodedData += empty; //reserve space for offset - } else encodeSingleItem(_data.toString(), _type, m_encodedData); } @@ -179,11 +176,6 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QString const& _data, Solidit catch (std::exception const&) { // manage input as a string. - QRegExp strExtract("\"(.*)\""); //check if contains both string and hex value, keep the string. - int i = strExtract.indexIn(src); - if (i != -1) - src = strExtract.cap(0); - src = src.replace("\"", ""); result = encodeStringParam(src, alignSize); } } diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 85c719987..583847b44 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -60,6 +60,7 @@ public: Bool, Address, Bytes, + String, Enum, Struct }; diff --git a/mix/qml/QIntTypeView.qml b/mix/qml/QIntTypeView.qml index c42e65654..ec54d6409 100644 --- a/mix/qml/QIntTypeView.qml +++ b/mix/qml/QIntTypeView.qml @@ -33,6 +33,3 @@ Item } } } - - - diff --git a/mix/qml/QStringTypeView.qml b/mix/qml/QStringTypeView.qml index 101863421..c42e65654 100644 --- a/mix/qml/QStringTypeView.qml +++ b/mix/qml/QStringTypeView.qml @@ -2,38 +2,33 @@ import QtQuick 2.0 Item { - property string value + property alias value: textinput.text property alias readOnly: textinput.readOnly id: editRoot - height: 20 width: readOnly ? textinput.implicitWidth : 150 - onValueChanged: - { - textinput.text = value - } - SourceSansProBold - { - id: boldFont + DebuggerPaneStyle { + id: dbgStyle } Rectangle { anchors.fill: parent radius: 4 TextInput { + anchors.verticalCenter: parent.verticalCenter id: textinput + font.family: dbgStyle.general.basicFont clip: true - anchors.fill: parent - wrapMode: Text.WrapAnywhere - font.family: boldFont.name selectByMouse: true - onTextChanged: { - var stringRegEx = new RegExp('"^\\"*', "g") - var str = stringRegEx.exec(text) - if (str && str.length > 0) - value = str[0] - else - value = text + text: value + anchors.fill: parent + font.pointSize: dbgStyle.general.basicFontSize + color: dbgStyle.general.basicColor + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() } } } diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index 880f22057..6b9edc755 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -72,7 +72,7 @@ Column return Qt.createComponent("qrc:/qml/QIntTypeView.qml"); else if (t === QSolidityType.Bool) return Qt.createComponent("qrc:/qml/QBoolTypeView.qml"); - else if (t === QSolidityType.Bytes) + else if (t === QSolidityType.Bytes || t === QSolidityType.String) return Qt.createComponent("qrc:/qml/QStringTypeView.qml"); else if (t === QSolidityType.Hash) return Qt.createComponent("qrc:/qml/QHashTypeView.qml"); diff --git a/mix/qml/js/InputValidator.js b/mix/qml/js/InputValidator.js index 46b23274d..7190ae291 100644 --- a/mix/qml/js/InputValidator.js +++ b/mix/qml/js/InputValidator.js @@ -1,8 +1,8 @@ Qt.include("QEtherHelper.js") -var nbRegEx = new RegExp('^[0-9]+$'); -var arrayRegEx = new RegExp('\\[[^\\]]*\\]', "g"); -var capturenbRegEx = new RegExp("[0-9]+"); +var nbRegEx; +var arrayRegEx; +var capturenbRegEx; function validate(model, values) { @@ -54,10 +54,7 @@ function check(type, value) function isArray(_type) { - if (!arrayRegEx.test(_type)) - return false - else - return (_type.indexOf("int") !== -1 || _type.indexOf("bytes") !== -1 || _type.indexOf("bool") !== -1 || _type.indexOf("adress") !== -1) + return arrayRegEx.test(_type); } function checkArrayRecursively(_type, _dim, _array) @@ -186,14 +183,6 @@ function validateAddress(_type, _value) function validateBytes(_type, _value) { var ret = { valid: true, message: "" } - if (_value.indexOf("\"") === 0 && _value.indexOf("0x") !== -1) - { - //this is a different fomatting - var stringRegEx = new RegExp('".*"', "g"); - var matches = _value.match(stringRegEx); - if (matches.length === 1) - _value = matches[0] - } if (_type !== "bytes" && _value.length > parseInt(_type.replace("bytes", "")) ) { ret.valid = false;