diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 8f5f3ecc7..e67ce9cea 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -80,10 +80,7 @@ void ContractCallDataEncoder::encodeArray(QJsonArray const& _array, QList _ if (c.isArray()) { if (_dim[0] == -1) - { - m_dynamicOffsetMap.push_back(std::make_pair(m_dynamicData.size() + offsetStart + 32 + k * 32, - m_dynamicData.size() + _content.size())); - } + m_dynamicOffsetMap.push_back(std::make_pair(m_dynamicData.size() + offsetStart + 32 + k * 32, m_dynamicData.size() + _content.size())); encodeArray(c.toArray(), _dim, _type, _content); } else @@ -183,6 +180,11 @@ 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); } } @@ -249,7 +251,11 @@ dev::bytes ContractCallDataEncoder::decodeBytes(dev::bytes const& _rawValue) QString ContractCallDataEncoder::toString(dev::bytes const& _b) { - return QString::fromStdString(dev::toJS(_b)); + QString str; + if (asString(_b, str)) + return "\"" + str + "\" " + QString::fromStdString(dev::toJS(_b)); + else + return QString::fromStdString(dev::toJS(_b)); } QString ContractCallDataEncoder::toChar(dev::bytes const& _b) diff --git a/mix/qml/QStringTypeView.qml b/mix/qml/QStringTypeView.qml index 080c49282..101863421 100644 --- a/mix/qml/QStringTypeView.qml +++ b/mix/qml/QStringTypeView.qml @@ -2,11 +2,15 @@ import QtQuick 2.0 Item { - property alias value: textinput.text + property string value property alias readOnly: textinput.readOnly id: editRoot height: 20 width: readOnly ? textinput.implicitWidth : 150 + onValueChanged: + { + textinput.text = value + } SourceSansProBold { @@ -18,12 +22,19 @@ Item radius: 4 TextInput { id: textinput - text: value 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 + } } } } diff --git a/mix/qml/js/InputValidator.js b/mix/qml/js/InputValidator.js index 8a8ef1715..aa3b90150 100644 --- a/mix/qml/js/InputValidator.js +++ b/mix/qml/js/InputValidator.js @@ -187,7 +187,15 @@ function validateAddress(_type, _value) function validateBytes(_type, _value) { var ret = { valid: true, message: "" } - if (_value.length > parseInt(_type.replace("bytes", "")) ) + 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; ret.message = _type + " should not contains more than " + _type.replace("bytes", "") + " characters";