Browse Source

- Coding Standards.

- Encode/Decode bigint behavior.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
ccb6b58e71
  1. 3
      mix/ClientModel.cpp
  2. 17
      mix/QVariableDefinition.cpp

3
mix/ClientModel.cpp

@ -215,7 +215,6 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
encoder.push(transaction.parameterValues.at(p)->encodeValue()); encoder.push(transaction.parameterValues.at(p)->encodeValue());
} }
if (transaction.functionId.isEmpty()) if (transaction.functionId.isEmpty())
{ {
Address newAddress = deployContract(contractCode, transaction); Address newAddress = deployContract(contractCode, transaction);
@ -226,9 +225,7 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
} }
} }
else else
{
callContract(m_contractAddress, encoder.encodedData(), transaction); callContract(m_contractAddress, encoder.encodedData(), transaction);
}
} }
onNewTransaction(); onNewTransaction();
} }

17
mix/QVariableDefinition.cpp

@ -70,19 +70,18 @@ void QIntType::setValue(dev::bigint _value)
dev::bytes QIntType::encodeValue() dev::bytes QIntType::encodeValue()
{ {
dev::bigint i(value().toStdString()); dev::bigint i(value().toStdString());
if (i < 0)
i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1;
bytes ret(32); bytes ret(32);
toBigEndian(i, ret); toBigEndian((u256)i, ret);
return ret; return ret;
} }
void QIntType::decodeValue(dev::bytes const& _rawValue) void QIntType::decodeValue(dev::bytes const& _rawValue)
{ {
dev::bigint bigint = dev::fromBigEndian<dev::bigint>(_rawValue); dev::u256 un = dev::fromBigEndian<dev::u256>(_rawValue);
if (((bigint >> 32) & 1) == 1) if (un >> 255)
bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1; setValue(-s256(~un + 1));
setValue(bigint); else
setValue(un);
} }
/* /*
@ -90,8 +89,8 @@ void QIntType::decodeValue(dev::bytes const& _rawValue)
*/ */
dev::bytes QHashType::encodeValue() dev::bytes QHashType::encodeValue()
{ {
QByteArray b = value().toUtf8(); QByteArray bytesAr = value().toLocal8Bit();
bytes r = bytes(b.begin(), b.end()); bytes r = bytes(bytesAr.begin(), bytesAr.end());
return padded(r, 32); return padded(r, 32);
} }

Loading…
Cancel
Save