From e18f42fefb8d5ac396037687e2873e257c3bacc7 Mon Sep 17 00:00:00 2001 From: DEV Mac Mini Date: Fri, 24 Jul 2015 18:14:18 +0200 Subject: [PATCH 1/3] enum as input parameter --- mix/ContractCallDataEncoder.cpp | 6 ++++++ mix/ContractCallDataEncoder.h | 2 ++ mix/qml/StructView.qml | 2 ++ mix/qml/js/InputValidator.js | 2 ++ 4 files changed, 12 insertions(+) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index ff858efbf..264b66359 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -298,10 +298,16 @@ QVariant ContractCallDataEncoder::decode(SolidityType const& _type, bytes const& return QVariant::fromValue(QString("struct")); //TODO else if (type == QSolidityType::Type::Address) return QVariant::fromValue(toString(decodeBytes(unpadLeft(rawParam)))); + else if (type == QSolidityType::Type::Enum) + return QVariant::fromValue(decodeEnum(rawParam)); else BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Parameter declaration not found")); } +QString ContractCallDataEncoder::decodeEnum(bytes _value){ + return toChar(decodeBytes(_value)); +} + QString ContractCallDataEncoder::decode(QVariableDeclaration* const& _param, bytes _value) { SolidityType const& type = _param->type()->type(); diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 8eb1569e4..d62b65187 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -64,6 +64,8 @@ public: QJsonArray decodeArray(SolidityType const& _type, bytes const& _value, int& pos); /// Decode array items QJsonValue decodeArrayContent(SolidityType const& _type, bytes const& _value, int& pos); + /// Decode enum + QString decodeEnum(bytes _value); private: unsigned encodeSingleItem(QString const& _data, SolidityType const& _type, bytes& _dest); diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index bd2cbf598..95ae3705b 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -60,6 +60,8 @@ Column return Qt.createComponent("qrc:/qml/QHashTypeView.qml"); else if (t === QSolidityType.Struct) return Qt.createComponent("qrc:/qml/StructView.qml"); + else if (t === QSolidityType.Enum) + return Qt.createComponent("qrc:/qml/QStringTypeView.qml"); else if (t === QSolidityType.Address) return Qt.createComponent("qrc:/qml/QAddressView.qml"); else diff --git a/mix/qml/js/InputValidator.js b/mix/qml/js/InputValidator.js index 7190ae291..c0626e0f1 100644 --- a/mix/qml/js/InputValidator.js +++ b/mix/qml/js/InputValidator.js @@ -38,6 +38,8 @@ function check(type, value) res = validateArray(type, value); else if (type.indexOf("int") !== -1) res = validateInt(type, value); + else if (type.indexOf("enum") !== -1) + res = validateInt(type, value); else if (type.indexOf("bytes") !== -1) res = validateBytes(type, value); else if (type.indexOf("bool") !== -1) From 1a082e4c327b7560e8ddf4fd4fc55d54f01ccc81 Mon Sep 17 00:00:00 2001 From: DEV Mac Mini Date: Fri, 24 Jul 2015 18:27:50 +0200 Subject: [PATCH 2/3] enum as output parameter --- mix/ContractCallDataEncoder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 264b66359..57b35f038 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -305,7 +305,7 @@ QVariant ContractCallDataEncoder::decode(SolidityType const& _type, bytes const& } QString ContractCallDataEncoder::decodeEnum(bytes _value){ - return toChar(decodeBytes(_value)); + return toString(decodeInt(_value)); } QString ContractCallDataEncoder::decode(QVariableDeclaration* const& _param, bytes _value) From 5e88e734e02aad3ab141ee07f949e17c362a8292 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sat, 25 Jul 2015 11:08:07 +0200 Subject: [PATCH 3/3] small changes --- mix/ContractCallDataEncoder.cpp | 3 ++- mix/qml/StructView.qml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 57b35f038..5ed014088 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -304,7 +304,8 @@ QVariant ContractCallDataEncoder::decode(SolidityType const& _type, bytes const& BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Parameter declaration not found")); } -QString ContractCallDataEncoder::decodeEnum(bytes _value){ +QString ContractCallDataEncoder::decodeEnum(bytes _value) +{ return toString(decodeInt(_value)); } diff --git a/mix/qml/StructView.qml b/mix/qml/StructView.qml index 95ae3705b..96a828eba 100644 --- a/mix/qml/StructView.qml +++ b/mix/qml/StructView.qml @@ -61,7 +61,7 @@ Column else if (t === QSolidityType.Struct) return Qt.createComponent("qrc:/qml/StructView.qml"); else if (t === QSolidityType.Enum) - return Qt.createComponent("qrc:/qml/QStringTypeView.qml"); + return Qt.createComponent("qrc:/qml/QIntTypeView.qml"); else if (t === QSolidityType.Address) return Qt.createComponent("qrc:/qml/QAddressView.qml"); else