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) void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const& _type)
{ {
QStringList strList; if (_type.dynamicSize && (_type.type == SolidityType::Type::Bytes || _type.type == SolidityType::Type::String))
if (_type.array) {
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); QList<int> dim = extractDimension(_type. name);
bytes content; bytes content;
QJsonDocument jsonResponse = QJsonDocument::fromJson(_data.toString().toUtf8());
QJsonArray jsonObject = jsonResponse.array();
size_t size = m_encodedData.size(); size_t size = m_encodedData.size();
if (dim[0] == -1) if (dim.front() == -1)
{ {
m_encodedData += bytes(32); // reserve space for offset m_encodedData += bytes(32); // reserve space for offset
m_staticOffsetMap.push_back(std::make_pair(size, m_dynamicData.size())); 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) if (!_type.dynamicSize)
m_encodedData.insert(m_encodedData.end(), content.begin(), content.end()); m_encodedData.insert(m_encodedData.end(), content.begin(), content.end());
else else
m_dynamicData.insert(m_dynamicData.end(), content.begin(), content.end()); 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 else
encodeSingleItem(_data.toString(), _type, m_encodedData); encodeSingleItem(_data.toString(), _type, m_encodedData);
} }
@ -179,11 +176,6 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QString const& _data, Solidit
catch (std::exception const&) catch (std::exception const&)
{ {
// manage input as a string. // 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); result = encodeStringParam(src, alignSize);
} }
} }

1
mix/QVariableDeclaration.h

@ -60,6 +60,7 @@ public:
Bool, Bool,
Address, Address,
Bytes, Bytes,
String,
Enum, Enum,
Struct 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 Item
{ {
property string value property alias value: textinput.text
property alias readOnly: textinput.readOnly property alias readOnly: textinput.readOnly
id: editRoot id: editRoot
height: 20
width: readOnly ? textinput.implicitWidth : 150 width: readOnly ? textinput.implicitWidth : 150
onValueChanged:
{
textinput.text = value
}
SourceSansProBold DebuggerPaneStyle {
{ id: dbgStyle
id: boldFont
} }
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
radius: 4 radius: 4
TextInput { TextInput {
anchors.verticalCenter: parent.verticalCenter
id: textinput id: textinput
font.family: dbgStyle.general.basicFont
clip: true clip: true
anchors.fill: parent
wrapMode: Text.WrapAnywhere
font.family: boldFont.name
selectByMouse: true selectByMouse: true
onTextChanged: { text: value
var stringRegEx = new RegExp('"^\\"*', "g") anchors.fill: parent
var str = stringRegEx.exec(text) font.pointSize: dbgStyle.general.basicFontSize
if (str && str.length > 0) color: dbgStyle.general.basicColor
value = str[0] MouseArea {
else id: mouseArea
value = text 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"); return Qt.createComponent("qrc:/qml/QIntTypeView.qml");
else if (t === QSolidityType.Bool) else if (t === QSolidityType.Bool)
return Qt.createComponent("qrc:/qml/QBoolTypeView.qml"); 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"); return Qt.createComponent("qrc:/qml/QStringTypeView.qml");
else if (t === QSolidityType.Hash) else if (t === QSolidityType.Hash)
return Qt.createComponent("qrc:/qml/QHashTypeView.qml"); return Qt.createComponent("qrc:/qml/QHashTypeView.qml");

19
mix/qml/js/InputValidator.js

@ -1,8 +1,8 @@
Qt.include("QEtherHelper.js") Qt.include("QEtherHelper.js")
var nbRegEx = new RegExp('^[0-9]+$'); var nbRegEx;
var arrayRegEx = new RegExp('\\[[^\\]]*\\]', "g"); var arrayRegEx;
var capturenbRegEx = new RegExp("[0-9]+"); var capturenbRegEx;
function validate(model, values) function validate(model, values)
{ {
@ -54,10 +54,7 @@ function check(type, value)
function isArray(_type) function isArray(_type)
{ {
if (!arrayRegEx.test(_type)) return arrayRegEx.test(_type);
return false
else
return (_type.indexOf("int") !== -1 || _type.indexOf("bytes") !== -1 || _type.indexOf("bool") !== -1 || _type.indexOf("adress") !== -1)
} }
function checkArrayRecursively(_type, _dim, _array) function checkArrayRecursively(_type, _dim, _array)
@ -186,14 +183,6 @@ function validateAddress(_type, _value)
function validateBytes(_type, _value) function validateBytes(_type, _value)
{ {
var ret = { valid: true, message: "" } 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", "")) ) if (_type !== "bytes" && _value.length > parseInt(_type.replace("bytes", "")) )
{ {
ret.valid = false; ret.valid = false;

Loading…
Cancel
Save