MCPcopy Create free account
hub / github.com/argotorg/solidity / formatType

Method formatType

libsolidity/interface/ABI.cpp:165–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165Json 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}

Callers

nothing calls this directly

Calls 11

isByteArrayOrStringMethod · 0.80
strMethod · 0.80
toStringMethod · 0.45
dataStoredInMethod · 0.45
isValueTypeMethod · 0.45
canonicalNameMethod · 0.45
isDynamicallySizedMethod · 0.45
lengthMethod · 0.45
baseTypeMethod · 0.45
containsMethod · 0.45
interfaceTypeMethod · 0.45

Tested by

no test coverage detected