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

Method createMetadata

libsolidity/interface/CompilerStack.cpp:1746–1876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1744}
1745
1746std::string CompilerStack::createMetadata(Contract const& _contract, bool _forIR) const
1747{
1748 Json meta;
1749 meta["version"] = 1;
1750 std::string sourceType;
1751 switch (m_compilationSourceType)
1752 {
1753 case CompilationSourceType::Solidity:
1754 sourceType = "Solidity";
1755 break;
1756 case CompilationSourceType::SolidityAST:
1757 sourceType = "SolidityAST";
1758 break;
1759 }
1760 meta["language"] = sourceType;
1761 meta["compiler"]["version"] = VersionStringStrict;
1762
1763 /// All the source files (including self), which should be included in the metadata.
1764 std::set<std::string> referencedSources;
1765 referencedSources.insert(*_contract.contract->sourceUnit().annotation().path);
1766 for (auto const sourceUnit: _contract.contract->sourceUnit().referencedSourceUnits(true))
1767 referencedSources.insert(*sourceUnit->annotation().path);
1768
1769 meta["sources"] = Json::object();
1770 for (auto const& s: m_sources)
1771 {
1772 if (!referencedSources.count(s.first))
1773 continue;
1774
1775 solAssert(s.second.charStream, "Character stream not available");
1776 meta["sources"][s.first]["keccak256"] = "0x" + util::toHex(s.second.keccak256().asBytes());
1777 if (std::optional<std::string> licenseString = s.second.ast->licenseString())
1778 meta["sources"][s.first]["license"] = *licenseString;
1779 if (m_metadataLiteralSources)
1780 meta["sources"][s.first]["content"] = s.second.charStream->source();
1781 else
1782 {
1783 meta["sources"][s.first]["urls"] = Json::array();
1784 meta["sources"][s.first]["urls"].emplace_back("bzz-raw://" + util::toHex(s.second.swarmHash().asBytes()));
1785 meta["sources"][s.first]["urls"].emplace_back(s.second.ipfsUrl());
1786 }
1787 }
1788
1789 static_assert(sizeof(m_optimiserSettings.expectedExecutionsPerDeployment) <= sizeof(Json::number_integer_t), "Invalid word size.");
1790 solAssert(static_cast<Json::number_integer_t>(m_optimiserSettings.expectedExecutionsPerDeployment) < std::numeric_limits<Json::number_integer_t>::max(), "");
1791 meta["settings"]["optimizer"]["runs"] = Json::number_integer_t(m_optimiserSettings.expectedExecutionsPerDeployment);
1792
1793 /// Backwards compatibility: If set to one of the default settings, do not provide details.
1794 OptimiserSettings settingsWithoutRuns = m_optimiserSettings;
1795 // reset to default
1796 settingsWithoutRuns.expectedExecutionsPerDeployment = OptimiserSettings::minimal().expectedExecutionsPerDeployment;
1797 if (settingsWithoutRuns == OptimiserSettings::minimal())
1798 meta["settings"]["optimizer"]["enabled"] = false;
1799 else if (settingsWithoutRuns == OptimiserSettings::standard())
1800 meta["settings"]["optimizer"]["enabled"] = true;
1801 else
1802 {
1803 Json details = Json::object();

Callers

nothing calls this directly

Calls 10

toHexFunction · 0.85
revertStringsToStringFunction · 0.85
jsonCompactPrintFunction · 0.85
insertMethod · 0.80
referencedSourceUnitsMethod · 0.80
asBytesMethod · 0.80
atMethod · 0.80
sourceUnitNameMethod · 0.80
countMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected