Browse Source

- bug fix with encoding bytes and string.

- bug fix when using String type QML control
- bytes parameter: stop trying to get ASCII value (as String as been
reimported)
cl-refactor
yann300 10 years ago
parent
commit
cbe3f80d6f
  1. 36
      mix/ContractCallDataEncoder.cpp
  2. 1
      mix/QVariableDeclaration.h
  3. 3
      mix/qml/QIntTypeView.qml
  4. 33
      mix/qml/QStringTypeView.qml
  5. 2
      mix/qml/StructView.qml
  6. 19
      mix/qml/js/InputValidator.js

36
mix/ContractCallDataEncoder.cpp

@ -97,37 +97,34 @@ void ContractCallDataEncoder::encodeArray(QJsonArray const& _array, QList<int> _
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<byte> 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<int> 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<byte> 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);
}
}

1
mix/QVariableDeclaration.h

@ -60,6 +60,7 @@ public:
Bool,
Address,
Bytes,
String,
Enum,
Struct
};

3
mix/qml/QIntTypeView.qml

@ -33,6 +33,3 @@ Item
}
}
}

33
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()
}
}
}

2
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");

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

Loading…
Cancel
Save