Allow encoding and decoding functions with empty type list.

This commit is contained in:
chriseth 2019-03-04 23:26:46 +01:00
parent eb5bde95b3
commit a27ef3489c

View File

@ -54,8 +54,6 @@ string ABIFunctions::tupleEncoder(
functionName += options.toFunctionNameSuffix(); functionName += options.toFunctionNameSuffix();
return createExternallyUsedFunction(functionName, [&]() { return createExternallyUsedFunction(functionName, [&]() {
solAssert(!_givenTypes.empty(), "");
// Note that the values are in reverse due to the difference in calling semantics. // Note that the values are in reverse due to the difference in calling semantics.
Whiskers templ(R"( Whiskers templ(R"(
function <functionName>(headStart <valueParams>) -> tail { function <functionName>(headStart <valueParams>) -> tail {
@ -183,15 +181,13 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory)
if (_fromMemory) if (_fromMemory)
functionName += "_fromMemory"; functionName += "_fromMemory";
solAssert(!_types.empty(), "");
return createExternallyUsedFunction(functionName, [&]() { return createExternallyUsedFunction(functionName, [&]() {
TypePointers decodingTypes; TypePointers decodingTypes;
for (auto const& t: _types) for (auto const& t: _types)
decodingTypes.emplace_back(t->decodingType()); decodingTypes.emplace_back(t->decodingType());
Whiskers templ(R"( Whiskers templ(R"(
function <functionName>(headStart, dataEnd) -> <valueReturnParams> { function <functionName>(headStart, dataEnd) <arrow> <valueReturnParams> {
if slt(sub(dataEnd, headStart), <minimumSize>) { revert(0, 0) } if slt(sub(dataEnd, headStart), <minimumSize>) { revert(0, 0) }
<decodeElements> <decodeElements>
} }
@ -242,6 +238,7 @@ string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMemory)
headPos += dynamic ? 0x20 : decodingTypes[i]->calldataEncodedSize(); headPos += dynamic ? 0x20 : decodingTypes[i]->calldataEncodedSize();
} }
templ("valueReturnParams", boost::algorithm::join(valueReturnParams, ", ")); templ("valueReturnParams", boost::algorithm::join(valueReturnParams, ", "));
templ("arrow", valueReturnParams.empty() ? "" : "->");
templ("decodeElements", decodeElements); templ("decodeElements", decodeElements);
return templ.render(); return templ.render();