@@ -35,6 +35,7 @@ using namespace dev::mix;
3535
3636bytes ContractCallDataEncoder::encodedData ()
3737{
38+ qDebug () << " encoded data " << QString::fromStdString (toJS (m_encodedData));
3839 return m_encodedData;
3940}
4041
@@ -62,96 +63,16 @@ QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QVariableDecla
6263 def = new QIntType (dec, QString ());
6364 else if (dec->type ().contains (" real" ))
6465 def = new QRealType (dec, QString ());
66+ else if (dec->type ().contains (" bool" ))
67+ def = new QBoolType (dec, QString ());
6568 else if (dec->type ().contains (" string" ) || dec->type ().contains (" text" ))
6669 def = new QStringType (dec, QString ());
6770 else if (dec->type ().contains (" hash" ) || dec->type ().contains (" address" ))
6871 def = new QHashType (dec, QString ());
69-
7072 def->decodeValue (returnValue);
7173 r.push_back (def);
72- returnValue = returnValue.substr (def->length (), returnValue.length () - 1 );
73-
74- /* QStringList tLength = typeLength(dec->type());
75-
76- QRegExp intTest("(uint|int|hash|address)");
77- QRegExp stringTest("(string|text)");
78- QRegExp realTest("(real|ureal)");
79- if (intTest.indexIn(dec->type()) != -1)
80- {
81- std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2);
82- QString value = resolveNumber(QString::fromStdString(rawParam));
83- r.append(new QVariableDefinition(dec, value));
84- returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
85- }
86- else if (dec->type() == "bool")
87- {
88- std::string rawParam = returnValue.substr(0, 2);
89- std::string unpadded = unpadLeft(rawParam);
90- r.append(new QVariableDefinition(dec, QString::fromStdString(unpadded)));
91- returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
92- }
93- else if (stringTest.indexIn(dec->type()) != -1)
94- {
95- if (tLength.length() == 0)
96- {
97- QString strLength = QString::fromStdString(returnValue.substr(0, 2));
98- returnValue = returnValue.substr(2, returnValue.length() - 1);
99- QString strValue = QString::fromStdString(returnValue.substr(0, strLength.toInt()));
100- r.append(new QVariableDefinition(dec, strValue));
101- returnValue = returnValue.substr(strValue.length(), returnValue.length() - 1);
102- }
103- else
104- {
105- std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2);
106- r.append(new QVariableDefinition(dec, QString::fromStdString(rawParam)));
107- returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
108- }
109- }
110- else if (realTest.indexIn(dec->type()) != -1)
111- {
112- QString value;
113- for (QString str: tLength)
114- {
115- std::string rawParam = returnValue.substr(0, (str.toInt() / 8) * 2);
116- QString value = resolveNumber(QString::fromStdString(rawParam));
117- value += value + "x";
118- returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
119- }
120- r.append(new QVariableDefinition(dec, value));
121- }*/
74+ returnValue = returnValue.substr (32 * 2 , returnValue.length () - 1 );
75+ qDebug () << " decoded return value : " << dec->type () << " " << def->value ();
12276 }
12377 return r;
12478}
125-
126- QString ContractCallDataEncoder::resolveNumber (QString const & _rawParam)
127- {
128- std::string unPadded = unpadLeft (_rawParam.toStdString ());
129- int x = std::stol (unPadded, nullptr , 16 );
130- std::stringstream ss;
131- ss << std::dec << x;
132- return QString::fromStdString (ss.str ());
133- }
134-
135- QString ContractCallDataEncoder::convertToReadable (std::string _v, QVariableDeclaration* _dec)
136- {
137- if (_dec->type ().indexOf (" int" ) != -1 )
138- return convertToInt (_v);
139- else if (_dec->type ().indexOf (" bool" ) != -1 )
140- return convertToBool (_v);
141- else
142- return QString::fromStdString (_v);
143- }
144-
145- QString ContractCallDataEncoder::convertToBool (std::string _v)
146- {
147- return _v == " 1" ? " true" : " false" ;
148- }
149-
150- QString ContractCallDataEncoder::convertToInt (std::string _v)
151- {
152- // TO DO to be improve to manage all int, uint size (128, 256, ...) in ethereum QML types task #612.
153- int x = std::stol (_v, nullptr , 16 );
154- std::stringstream ss;
155- ss << std::dec << x;
156- return QString::fromStdString (ss.str ());
157- }
0 commit comments