From 5bfff8fcac49c1b4f21a60d02006c2f72bf36465 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Mar 2015 12:39:01 +0200 Subject: [PATCH 1/5] - Fix for #1448, #1447 --- mix/CodeModel.cpp | 1 + mix/ContractCallDataEncoder.cpp | 3 ++- mix/qml/StructView.qml | 1 + mix/qml/TransactionDialog.qml | 7 ++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 27c79e0a0..a96ab8791 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -342,6 +342,7 @@ SolidityType CodeModel::nodeType(dev::solidity::Type const* _type) r.type = SolidityType::Type::Bytes; r.size = static_cast(b->getNumBytes()); } + break; case Type::Category::Contract: r.type = SolidityType::Type::Address; break; diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 6553244dc..3ca133aab 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -91,6 +91,7 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QVariant const& _data, Solidi { QByteArray bytesAr = src.toLocal8Bit(); result = bytes(bytesAr.begin(), bytesAr.end()); + result = paddedRight(result, alignSize); } else { @@ -101,7 +102,7 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QVariant const& _data, Solidi unsigned dataSize = _type.dynamicSize ? result.size() : alignSize; _dest.insert(_dest.end(), result.begin(), result.end()); - if (_dest.size() % alignSize != 0) + if ((_dest.size() - 4) % alignSize != 0) _dest.resize((_dest.size() & ~(alignSize - 1)) + alignSize); return dataSize; } diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index 045b2eabc..42ec5b046 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -44,6 +44,7 @@ Column anchors.verticalCenter: parent.verticalCenter sourceComponent: { + console.log("loading param"); var t = modelData.type.category; if (t === QSolidityType.SignedInteger || t === QSolidityType.UnsignedInteger) return Qt.createComponent("qrc:/qml/QIntTypeView.qml"); diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 5d98d3dbd..33ab8c5d0 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -81,6 +81,7 @@ Window { loadParameter(params[p]); } } + initTypeLoader(); modalTransactionDialog.setX((Screen.width - width) / 2); modalTransactionDialog.setY((Screen.height - height) / 2); @@ -126,11 +127,15 @@ Window { } } } + initTypeLoader(); + } + + function initTypeLoader() + { typeLoader.value = {} typeLoader.members = [] typeLoader.value = paramValues; typeLoader.members = paramsModel; - } function close() From 7274ac735270a7a65000fdc97de8745dba9490a6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Mar 2015 16:17:03 +0200 Subject: [PATCH 2/5] Display ascii char in return value. --- mix/ContractCallDataEncoder.cpp | 21 ++++++++++++++++++++- mix/ContractCallDataEncoder.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 3ca133aab..b2bc888a9 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -159,7 +159,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 (isString(_b, str)) + return "- " + str + " - " + QString::fromStdString(dev::toJS(_b)); + else + return QString::fromStdString(dev::toJS(_b)); } @@ -197,3 +201,18 @@ QStringList ContractCallDataEncoder::decode(QList const& } return r; } + + +bool ContractCallDataEncoder::isString(dev::bytes const& _b, QString& _str) +{ + dev::bytes bunPad = unpadded(_b); + for (unsigned i = 0; i < bunPad.size(); i++) + { + u256 value(bunPad.at(i)); + if (value > 127) + return false; + else + _str += QString::fromStdString(dev::toJS(bunPad.at(i))).replace("0x", ""); + } + return true; +} diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 3fa165d3f..178cdcdf8 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -66,6 +66,7 @@ private: dev::bytes encodeBytes(QString const& _str); dev::bytes decodeBytes(dev::bytes const& _rawValue); QString toString(dev::bytes const& _b); + bool isString(dev::bytes const& _b, QString& _str); private: bytes m_encodedData; From 1855b63a955f0a9db931c87799a06efec8d5d6eb Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Mar 2015 16:18:27 +0200 Subject: [PATCH 3/5] small changes --- mix/qml/StructView.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index 42ec5b046..045b2eabc 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -44,7 +44,6 @@ Column anchors.verticalCenter: parent.verticalCenter sourceComponent: { - console.log("loading param"); var t = modelData.type.category; if (t === QSolidityType.SignedInteger || t === QSolidityType.UnsignedInteger) return Qt.createComponent("qrc:/qml/QIntTypeView.qml"); From 2a57a78f6480192a31d1a34da50e5fb94a2e9c03 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Mar 2015 17:29:08 +0200 Subject: [PATCH 4/5] changes on encode input parameters. --- mix/ContractCallDataEncoder.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index b2bc888a9..7a48263a0 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -80,24 +80,27 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QVariant const& _data, Solidi if ((src.startsWith("\"") && src.endsWith("\"")) || (src.startsWith("\'") && src.endsWith("\'"))) src = src.remove(src.length() - 1, 1).remove(0, 1); - QRegExp rx("[a-z]+"); if (src.startsWith("0x")) { result = fromHex(src.toStdString().substr(2)); if (_type.type != SolidityType::Type::Bytes) result = padded(result, alignSize); } - else if (rx.indexIn(src.toLower(), 0) != -1) - { - QByteArray bytesAr = src.toLocal8Bit(); - result = bytes(bytesAr.begin(), bytesAr.end()); - result = paddedRight(result, alignSize); - } else { - bigint i(src.toStdString()); - result = bytes(alignSize); - toBigEndian((u256)i, result); + try + { + bigint i(src.toStdString()); + result = bytes(alignSize); + toBigEndian((u256)i, result); + } + catch (std::exception const& ex) + { + // manage input as a string. + QByteArray bytesAr = src.toLocal8Bit(); + result = bytes(bytesAr.begin(), bytesAr.end()); + result = paddedRight(result, alignSize); + } } unsigned dataSize = _type.dynamicSize ? result.size() : alignSize; @@ -161,7 +164,7 @@ QString ContractCallDataEncoder::toString(dev::bytes const& _b) { QString str; if (isString(_b, str)) - return "- " + str + " - " + QString::fromStdString(dev::toJS(_b)); + return "\"" + str + "\" " + QString::fromStdString(dev::toJS(_b)); else return QString::fromStdString(dev::toJS(_b)); } @@ -208,8 +211,7 @@ bool ContractCallDataEncoder::isString(dev::bytes const& _b, QString& _str) dev::bytes bunPad = unpadded(_b); for (unsigned i = 0; i < bunPad.size(); i++) { - u256 value(bunPad.at(i)); - if (value > 127) + if (bunPad.at(i) < 9 || bunPad.at(i) > 127) return false; else _str += QString::fromStdString(dev::toJS(bunPad.at(i))).replace("0x", ""); From ad1e8454735ccf0a01c1f3efe40441b1704de743 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Mar 2015 17:34:05 +0200 Subject: [PATCH 5/5] small changes --- mix/ContractCallDataEncoder.cpp | 4 ++-- mix/ContractCallDataEncoder.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 7a48263a0..f1283f433 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -163,7 +163,7 @@ dev::bytes ContractCallDataEncoder::decodeBytes(dev::bytes const& _rawValue) QString ContractCallDataEncoder::toString(dev::bytes const& _b) { QString str; - if (isString(_b, str)) + if (asString(_b, str)) return "\"" + str + "\" " + QString::fromStdString(dev::toJS(_b)); else return QString::fromStdString(dev::toJS(_b)); @@ -206,7 +206,7 @@ QStringList ContractCallDataEncoder::decode(QList const& } -bool ContractCallDataEncoder::isString(dev::bytes const& _b, QString& _str) +bool ContractCallDataEncoder::asString(dev::bytes const& _b, QString& _str) { dev::bytes bunPad = unpadded(_b); for (unsigned i = 0; i < bunPad.size(); i++) diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 178cdcdf8..e225158c7 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -66,7 +66,7 @@ private: dev::bytes encodeBytes(QString const& _str); dev::bytes decodeBytes(dev::bytes const& _rawValue); QString toString(dev::bytes const& _b); - bool isString(dev::bytes const& _b, QString& _str); + bool asString(dev::bytes const& _b, QString& _str); private: bytes m_encodedData;