|
|
@ -19,6 +19,7 @@ |
|
|
|
* @date 2014 |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <libdevcore/CommonData.h> |
|
|
|
#include <libdevcore/CommonJS.h> |
|
|
|
#include "QVariableDefinition.h" |
|
|
|
|
|
|
@ -60,23 +61,25 @@ QVariableDefinition* QVariableDefinitionList::val(int _idx) |
|
|
|
*/ |
|
|
|
dev::bytes QIntType::encodeValue() |
|
|
|
{ |
|
|
|
dev::bigint i(value().toStdString()); |
|
|
|
if (i < 0) |
|
|
|
i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1; |
|
|
|
std::ostringstream s; |
|
|
|
s << std::hex << "0x" << value().toStdString(); |
|
|
|
return padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); |
|
|
|
} |
|
|
|
|
|
|
|
int QIntType::length() |
|
|
|
{ |
|
|
|
return (declaration()->typeLength().first().toInt() / 8) * 2; |
|
|
|
s << std::hex << "0x" << i; |
|
|
|
qDebug() << " int input " << QString::fromStdString(toJS(padded(jsToBytes(s.str()), 32))); |
|
|
|
return padded(jsToBytes(s.str()), 32); |
|
|
|
} |
|
|
|
|
|
|
|
void QIntType::decodeValue(std::string const& _rawValue) |
|
|
|
{ |
|
|
|
std::string unPadded = unpadLeft(_rawValue); |
|
|
|
int x = std::stol(unPadded, nullptr, 16); |
|
|
|
std::stringstream ss; |
|
|
|
ss << std::dec << x; |
|
|
|
setValue(QString::fromStdString(ss.str())); |
|
|
|
std::string rawParam = _rawValue.substr(0, 32 * 2); |
|
|
|
dev::bigint bigint = dev::bigint("0x" + rawParam); |
|
|
|
if (((bigint >> 32) & 1) == 1) |
|
|
|
bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1; |
|
|
|
std::ostringstream s; |
|
|
|
s << std::dec << bigint; |
|
|
|
qDebug() << " int output " << QString::fromStdString(s.str()); |
|
|
|
setValue(QString::fromStdString(s.str())); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -84,17 +87,14 @@ void QIntType::decodeValue(std::string const& _rawValue) |
|
|
|
*/ |
|
|
|
dev::bytes QHashType::encodeValue() |
|
|
|
{ |
|
|
|
return bytes(); |
|
|
|
} |
|
|
|
|
|
|
|
int QHashType::length() |
|
|
|
{ |
|
|
|
return (declaration()->typeLength().first().toInt() / 8) * 2; |
|
|
|
return padded(asBytes(value().toStdString()), 32); |
|
|
|
} |
|
|
|
|
|
|
|
void QHashType::decodeValue(std::string const& _rawValue) |
|
|
|
{ |
|
|
|
Q_UNUSED(_rawValue); |
|
|
|
std::string rawParam = _rawValue.substr(0, 32 * 2); |
|
|
|
std::string unPadded = unpadLeft(rawParam); |
|
|
|
setValue(QString::fromStdString(unPadded)); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -102,34 +102,12 @@ void QHashType::decodeValue(std::string const& _rawValue) |
|
|
|
*/ |
|
|
|
dev::bytes QRealType::encodeValue() |
|
|
|
{ |
|
|
|
|
|
|
|
std::ostringstream s; |
|
|
|
s << std::hex << "0x" << value().split("x").first().toStdString(); |
|
|
|
bytes first = padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); |
|
|
|
s << std::hex << "0x" << value().split("x").last().toStdString(); |
|
|
|
bytes second = padded(jsToBytes(s.str()), declaration()->typeLength().last().toInt() / 8); |
|
|
|
first.insert(first.end(), second.begin(), second.end()); |
|
|
|
return first; |
|
|
|
} |
|
|
|
|
|
|
|
int QRealType::length() |
|
|
|
{ |
|
|
|
return (declaration()->typeLength().first().toInt() / 8) * 2 + (declaration()->typeLength().last().toInt() / 8) * 2; |
|
|
|
return bytes(); |
|
|
|
} |
|
|
|
|
|
|
|
void QRealType::decodeValue(std::string const& _rawValue) |
|
|
|
{ |
|
|
|
QString value; |
|
|
|
for (QString str: declaration()->typeLength()) |
|
|
|
{ |
|
|
|
std::string rawParam = _rawValue.substr(0, (str.toInt() / 8) * 2); |
|
|
|
std::string unPadded = unpadLeft(rawParam); |
|
|
|
int x = std::stol(unPadded, nullptr, 16); |
|
|
|
std::stringstream ss; |
|
|
|
ss << std::dec << x; |
|
|
|
value += QString::fromStdString(ss.str()) + "x"; |
|
|
|
} |
|
|
|
setValue(value); |
|
|
|
Q_UNUSED(_rawValue); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -137,30 +115,24 @@ void QRealType::decodeValue(std::string const& _rawValue) |
|
|
|
*/ |
|
|
|
dev::bytes QStringType::encodeValue() |
|
|
|
{ |
|
|
|
return padded(jsToBytes(value().toStdString()), declaration()->typeLength().first().toInt() / 8); |
|
|
|
} |
|
|
|
|
|
|
|
int QStringType::length() |
|
|
|
{ |
|
|
|
if (declaration()->typeLength().length() == 0) |
|
|
|
return value().length() + 2; |
|
|
|
else |
|
|
|
return (declaration()->typeLength().first().toInt() / 8) * 2; |
|
|
|
qDebug() << QString::fromStdString(toJS(paddedRight(asBytes(value().toStdString()), 32))); |
|
|
|
return paddedRight(asBytes(value().toStdString()), 32); |
|
|
|
} |
|
|
|
|
|
|
|
void QStringType::decodeValue(std::string const& _rawValue) |
|
|
|
{ |
|
|
|
if (declaration()->typeLength().first().length() == 0) |
|
|
|
std::string rawParam = _rawValue.substr(0, 32 * 2); |
|
|
|
rawParam = unpadRight(rawParam); |
|
|
|
std::string res; |
|
|
|
res.reserve(rawParam.size() / 2); |
|
|
|
for (unsigned int i = 0; i < rawParam.size(); i += 2) |
|
|
|
{ |
|
|
|
std::string strLength = _rawValue.substr(0, 2); |
|
|
|
std::string strValue = _rawValue.substr(2, std::stoi(strLength)); |
|
|
|
setValue(QString::fromStdString(strValue)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
std::string rawParam = _rawValue.substr(0, (declaration()->typeLength().first().toInt() / 8) * 2); |
|
|
|
setValue(QString::fromStdString(rawParam)); |
|
|
|
std::istringstream iss(rawParam.substr(i, 2)); |
|
|
|
int temp; |
|
|
|
iss >> std::hex >> temp; |
|
|
|
res += static_cast<char>(temp); |
|
|
|
} |
|
|
|
setValue(QString::fromStdString(res)); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -168,18 +140,13 @@ void QStringType::decodeValue(std::string const& _rawValue) |
|
|
|
*/ |
|
|
|
dev::bytes QBoolType::encodeValue() |
|
|
|
{ |
|
|
|
return padded(jsToBytes(value().toStdString()), 1); |
|
|
|
} |
|
|
|
|
|
|
|
int QBoolType::length() |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
qDebug() << QString::fromStdString(toJS(padded(jsToBytes(value().toStdString()), 32))); |
|
|
|
return padded(jsToBytes(value().toStdString()), 32); |
|
|
|
} |
|
|
|
|
|
|
|
void QBoolType::decodeValue(std::string const& _rawValue) |
|
|
|
{ |
|
|
|
std::string rawParam = _rawValue.substr(0, 2); |
|
|
|
std::string rawParam = _rawValue.substr(0, 32 * 2); |
|
|
|
std::string unpadded = unpadLeft(rawParam); |
|
|
|
setValue(QString::fromStdString(unpadded)); |
|
|
|
} |
|
|
|
|
|
|
|