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..f1283f433 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -80,28 +80,32 @@ 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()); - } 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; _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; } @@ -158,7 +162,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)); } @@ -196,3 +204,17 @@ QStringList ContractCallDataEncoder::decode(QList const& } return r; } + + +bool ContractCallDataEncoder::asString(dev::bytes const& _b, QString& _str) +{ + dev::bytes bunPad = unpadded(_b); + for (unsigned i = 0; i < bunPad.size(); i++) + { + if (bunPad.at(i) < 9 || bunPad.at(i) > 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..e225158c7 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 asString(dev::bytes const& _b, QString& _str); private: bytes m_encodedData; 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()