Browse Source

Merge pull request #1457 from yann300/bugFix

Mix - Bug fixes
cl-refactor
Arkadiy Paronyan 10 years ago
parent
commit
31d2449f6f
  1. 1
      mix/CodeModel.cpp
  2. 44
      mix/ContractCallDataEncoder.cpp
  3. 1
      mix/ContractCallDataEncoder.h
  4. 7
      mix/qml/TransactionDialog.qml

1
mix/CodeModel.cpp

@ -342,6 +342,7 @@ SolidityType CodeModel::nodeType(dev::solidity::Type const* _type)
r.type = SolidityType::Type::Bytes; r.type = SolidityType::Type::Bytes;
r.size = static_cast<unsigned>(b->getNumBytes()); r.size = static_cast<unsigned>(b->getNumBytes());
} }
break;
case Type::Category::Contract: case Type::Category::Contract:
r.type = SolidityType::Type::Address; r.type = SolidityType::Type::Address;
break; break;

44
mix/ContractCallDataEncoder.cpp

@ -80,28 +80,32 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QVariant const& _data, Solidi
if ((src.startsWith("\"") && src.endsWith("\"")) || (src.startsWith("\'") && src.endsWith("\'"))) if ((src.startsWith("\"") && src.endsWith("\"")) || (src.startsWith("\'") && src.endsWith("\'")))
src = src.remove(src.length() - 1, 1).remove(0, 1); src = src.remove(src.length() - 1, 1).remove(0, 1);
QRegExp rx("[a-z]+");
if (src.startsWith("0x")) if (src.startsWith("0x"))
{ {
result = fromHex(src.toStdString().substr(2)); result = fromHex(src.toStdString().substr(2));
if (_type.type != SolidityType::Type::Bytes) if (_type.type != SolidityType::Type::Bytes)
result = padded(result, alignSize); result = padded(result, alignSize);
} }
else if (rx.indexIn(src.toLower(), 0) != -1)
{
QByteArray bytesAr = src.toLocal8Bit();
result = bytes(bytesAr.begin(), bytesAr.end());
}
else else
{ {
bigint i(src.toStdString()); try
result = bytes(alignSize); {
toBigEndian((u256)i, result); 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; unsigned dataSize = _type.dynamicSize ? result.size() : alignSize;
_dest.insert(_dest.end(), result.begin(), result.end()); _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); _dest.resize((_dest.size() & ~(alignSize - 1)) + alignSize);
return dataSize; return dataSize;
} }
@ -158,7 +162,11 @@ dev::bytes ContractCallDataEncoder::decodeBytes(dev::bytes const& _rawValue)
QString ContractCallDataEncoder::toString(dev::bytes const& _b) 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<QVariableDeclaration*> const&
} }
return r; 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;
}

1
mix/ContractCallDataEncoder.h

@ -66,6 +66,7 @@ private:
dev::bytes encodeBytes(QString const& _str); dev::bytes encodeBytes(QString const& _str);
dev::bytes decodeBytes(dev::bytes const& _rawValue); dev::bytes decodeBytes(dev::bytes const& _rawValue);
QString toString(dev::bytes const& _b); QString toString(dev::bytes const& _b);
bool asString(dev::bytes const& _b, QString& _str);
private: private:
bytes m_encodedData; bytes m_encodedData;

7
mix/qml/TransactionDialog.qml

@ -81,6 +81,7 @@ Window {
loadParameter(params[p]); loadParameter(params[p]);
} }
} }
initTypeLoader();
modalTransactionDialog.setX((Screen.width - width) / 2); modalTransactionDialog.setX((Screen.width - width) / 2);
modalTransactionDialog.setY((Screen.height - height) / 2); modalTransactionDialog.setY((Screen.height - height) / 2);
@ -126,11 +127,15 @@ Window {
} }
} }
} }
initTypeLoader();
}
function initTypeLoader()
{
typeLoader.value = {} typeLoader.value = {}
typeLoader.members = [] typeLoader.members = []
typeLoader.value = paramValues; typeLoader.value = paramValues;
typeLoader.members = paramsModel; typeLoader.members = paramsModel;
} }
function close() function close()

Loading…
Cancel
Save