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

Method fromJSON

libevmasm/Assembly.cpp:588–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586}
587
588std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSON(
589 Json const& _json,
590 std::vector<std::string> const& _sourceList,
591 size_t _level,
592 std::optional<uint8_t> _eofVersion
593)
594{
595 solRequire(_json.is_object(), AssemblyImportException, "Supplied JSON is not an object.");
596 static std::set<std::string> const validMembers{".code", ".data", ".auxdata", "sourceList"};
597 for (auto const& [attribute, _]: _json.items())
598 solRequire(validMembers.count(attribute), AssemblyImportException, "Unknown attribute '" + attribute + "'.");
599
600 if (_level == 0)
601 {
602 if (_json.contains("sourceList"))
603 {
604 solRequire(_json["sourceList"].is_array(), AssemblyImportException, "Optional member 'sourceList' is not an array.");
605 for (Json const& sourceName: _json["sourceList"])
606 {
607 solRequire(!sourceName.is_null(), AssemblyImportException, "The 'sourceList' array contains invalid 'null' item.");
608 solRequire(
609 sourceName.is_string(),
610 AssemblyImportException,
611 "The 'sourceList' array contains an item that is not a string."
612 );
613 }
614 }
615 }
616 else
617 solRequire(
618 !_json.contains("sourceList"),
619 AssemblyImportException,
620 "Member 'sourceList' may only be present in the root JSON object."
621 );
622
623 auto result = std::make_shared<Assembly>(EVMVersion{}, _level == 0 /* _creation */, _eofVersion, "" /* _name */);
624 std::vector<std::string> parsedSourceList;
625 if (_json.contains("sourceList"))
626 {
627 solAssert(_level == 0);
628 solAssert(_sourceList.empty());
629 for (Json const& sourceName: _json["sourceList"])
630 {
631 solRequire(
632 std::find(parsedSourceList.begin(), parsedSourceList.end(), sourceName.get<std::string>()) == parsedSourceList.end(),
633 AssemblyImportException,
634 "Items in 'sourceList' array are not unique."
635 );
636 parsedSourceList.emplace_back(sourceName.get<std::string>());
637 }
638 }
639
640 solRequire(_json.contains(".code"), AssemblyImportException, "Member '.code' is missing.");
641 solRequire(_json[".code"].is_array(), AssemblyImportException, "Member '.code' is not an array.");
642 for (Json const& codeItem: _json[".code"])
643 solRequire(codeItem.is_object(), AssemblyImportException, "The '.code' array contains an item that is not an object.");
644
645 result->importAssemblyItemsFromJSON(_json[".code"], _level == 0 ? parsedSourceList : _sourceList);

Callers

nothing calls this directly

Calls 8

countMethod · 0.45
containsMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected