Merge pull request #6190 from ethereum/allowEncodeDecodeWithZeroParameters

Allow encoding and decoding functions with empty type list.
This commit is contained in:
chriseth 2019-03-06 11:57:21 +01:00 committed by GitHub
commit 449141db2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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