| 163 | } |
| 164 | |
| 165 | Json ABI::formatType( |
| 166 | std::string const& _name, |
| 167 | Type const& _encodingType, |
| 168 | Type const& _solidityType, |
| 169 | bool _forLibrary |
| 170 | ) |
| 171 | { |
| 172 | Json ret; |
| 173 | ret["name"] = _name; |
| 174 | ret["internalType"] = _solidityType.toString(true); |
| 175 | std::string suffix = (_forLibrary && _encodingType.dataStoredIn(DataLocation::Storage)) ? " storage" : ""; |
| 176 | if (_encodingType.isValueType() || (_forLibrary && _encodingType.dataStoredIn(DataLocation::Storage))) |
| 177 | ret["type"] = _encodingType.canonicalName() + suffix; |
| 178 | else if (ArrayType const* arrayType = dynamic_cast<ArrayType const*>(&_encodingType)) |
| 179 | { |
| 180 | if (arrayType->isByteArrayOrString()) |
| 181 | ret["type"] = _encodingType.canonicalName() + suffix; |
| 182 | else |
| 183 | { |
| 184 | std::string suffix; |
| 185 | if (arrayType->isDynamicallySized()) |
| 186 | suffix = "[]"; |
| 187 | else |
| 188 | suffix = std::string("[") + arrayType->length().str() + "]"; |
| 189 | solAssert(arrayType->baseType(), ""); |
| 190 | Json subtype = formatType( |
| 191 | "", |
| 192 | *arrayType->baseType(), |
| 193 | *dynamic_cast<ArrayType const&>(_solidityType).baseType(), |
| 194 | _forLibrary |
| 195 | ); |
| 196 | if (subtype.contains("components")) |
| 197 | { |
| 198 | ret["type"] = subtype["type"].get<std::string>() + suffix; |
| 199 | ret["components"] = subtype["components"]; |
| 200 | } |
| 201 | else |
| 202 | ret["type"] = subtype["type"].get<std::string>() + suffix; |
| 203 | } |
| 204 | } |
| 205 | else if (StructType const* structType = dynamic_cast<StructType const*>(&_encodingType)) |
| 206 | { |
| 207 | ret["type"] = "tuple"; |
| 208 | ret["components"] = Json::array(); |
| 209 | for (auto const& member: structType->members(nullptr)) |
| 210 | { |
| 211 | solAssert(member.type, ""); |
| 212 | Type const* t = member.type->interfaceType(_forLibrary); |
| 213 | solAssert(t, ""); |
| 214 | ret["components"].emplace_back(formatType(member.name, *t, *member.type, _forLibrary)); |
| 215 | } |
| 216 | } |
| 217 | else |
| 218 | solAssert(false, "Invalid type."); |
| 219 | return ret; |
| 220 | } |
nothing calls this directly
no test coverage detected