Browse Source

new abi

cl-refactor
arkpar 10 years ago
parent
commit
d24b48853d
  1. 18
      mix/ContractCallDataEncoder.cpp
  2. 1
      mix/ContractCallDataEncoder.h

18
mix/ContractCallDataEncoder.cpp

@ -36,6 +36,14 @@ using namespace dev::mix;
bytes ContractCallDataEncoder::encodedData()
{
bytes r(m_encodedData);
size_t headerSize = m_encodedData.size() & ~0x1fUL; //ignore any prefix that is not 32-byte aligned
//apply offsets
for (auto const& p: m_offsetMap)
{
vector_ref<byte> offsetRef(r.data() + p.first, 32);
toBigEndian<size_t, vector_ref<byte>>(p.second + headerSize, offsetRef); //add header size minus signature hash
}
r.insert(r.end(), m_dynamicData.begin(), m_dynamicData.end());
return r;
}
@ -64,6 +72,9 @@ void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const&
if (_type.dynamicSize)
{
bytes empty(32);
size_t sizePos = m_dynamicData.size();
m_dynamicData.insert(m_dynamicData.end(), empty.begin(), empty.end()); //reserve space for count
if (_type.type == SolidityType::Type::Bytes)
count = encodeSingleItem(_data.toString(), _type, m_dynamicData);
else
@ -72,9 +83,10 @@ void ContractCallDataEncoder::encode(QVariant const& _data, SolidityType const&
for (auto const& item: strList)
encodeSingleItem(item, _type, m_dynamicData);
}
bytes sizeEnc(32);
toBigEndian(count, sizeEnc);
m_encodedData.insert(m_encodedData.end(), sizeEnc.begin(), sizeEnc.end());
vector_ref<byte> sizeRef(m_dynamicData.data() + sizePos, 32);
toBigEndian(count, sizeRef);
m_offsetMap.push_back(std::make_pair(m_encodedData.size(), sizePos));
m_encodedData.insert(m_encodedData.end(), empty.begin(), empty.end()); //reserve space for offset
}
else
{

1
mix/ContractCallDataEncoder.h

@ -73,6 +73,7 @@ private:
private:
bytes m_encodedData;
bytes m_dynamicData;
std::vector<std::pair<size_t, size_t>> m_offsetMap;
};
}

Loading…
Cancel
Save