aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-01-26 22:20:56 +0800
committerGitHub <noreply@github.com>2017-01-26 22:20:56 +0800
commit78d70b98f79529d025b664c45a918330fa9a8204 (patch)
tree73e455d7b5f86f387224adccb52b5015d50ef950
parent2122d2d7281504aae91063f48790803549e4972d (diff)
parent4b321c653cf5f8cee2d5c1db6668d1dcffebc17b (diff)
downloaddexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar.gz
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar.bz2
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar.lz
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar.xz
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.tar.zst
dexon-solidity-78d70b98f79529d025b664c45a918330fa9a8204.zip
Merge pull request #1611 from ethereum/metadata-literal-sources
Add option to keep literal sources in metadata
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/interface/CompilerStack.cpp13
-rw-r--r--libsolidity/interface/CompilerStack.h2
-rw-r--r--solc/CommandLineInterface.cpp7
4 files changed, 18 insertions, 5 deletions
diff --git a/Changelog.md b/Changelog.md
index e50cb3bd..a8b66abc 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -6,6 +6,7 @@ Features:
* AST: Use deterministic node identifiers.
* Type system: Introduce type identifier strings.
* Metadata: Do not include platform in the version number.
+ * Metadata: Add option to store sources as literal content.
* Code generator: Extract array utils into low-level functions.
Bugfixes:
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index b26bd501..3335c40e 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -726,10 +726,15 @@ string CompilerStack::createOnChainMetadata(Contract const& _contract) const
solAssert(s.second.scanner, "Scanner not available");
meta["sources"][s.first]["keccak256"] =
"0x" + toHex(dev::keccak256(s.second.scanner->source()).asBytes());
- meta["sources"][s.first]["urls"] = Json::arrayValue;
- meta["sources"][s.first]["urls"].append(
- "bzzr://" + toHex(dev::swarmHash(s.second.scanner->source()).asBytes())
- );
+ if (m_metadataLiteralSources)
+ meta["sources"][s.first]["content"] = s.second.scanner->source();
+ else
+ {
+ meta["sources"][s.first]["urls"] = Json::arrayValue;
+ meta["sources"][s.first]["urls"].append(
+ "bzzr://" + toHex(dev::swarmHash(s.second.scanner->source()).asBytes())
+ );
+ }
}
meta["settings"]["optimizer"]["enabled"] = m_optimize;
meta["settings"]["optimizer"]["runs"] = m_optimizeRuns;
diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h
index 61edc284..9ee70215 100644
--- a/libsolidity/interface/CompilerStack.h
+++ b/libsolidity/interface/CompilerStack.h
@@ -177,6 +177,7 @@ public:
/// Can be one of 4 types defined at @c DocumentationType
Json::Value const& metadata(std::string const& _contractName, DocumentationType _type) const;
std::string const& onChainMetadata(std::string const& _contractName) const;
+ void useMetadataLiteralSources(bool _metadataLiteralSources) { m_metadataLiteralSources = _metadataLiteralSources; }
/// @returns the previously used scanner, useful for counting lines during error reporting.
Scanner const& scanner(std::string const& _sourceName = "") const;
@@ -274,6 +275,7 @@ private:
std::map<std::string const, Contract> m_contracts;
std::string m_formalTranslation;
ErrorList m_errors;
+ bool m_metadataLiteralSources = false;
};
}
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index e49e8517..d33b87a8 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -98,6 +98,7 @@ static string const g_strSrcMap = "srcmap";
static string const g_strSrcMapRuntime = "srcmap-runtime";
static string const g_strVersion = "version";
static string const g_stdinFileNameStr = "<stdin>";
+static string const g_strMetadataLiteral = "metadata-literal";
static string const g_argAbi = g_strAbi;
static string const g_argAddStandard = g_strAddStandard;
@@ -126,6 +127,7 @@ static string const g_argOutputDir = g_strOutputDir;
static string const g_argSignatureHashes = g_strSignatureHashes;
static string const g_argVersion = g_strVersion;
static string const g_stdinFileName = g_stdinFileNameStr;
+static string const g_argMetadataLiteral = g_strMetadataLiteral;
/// Possible arguments to for --combined-json
static set<string> const g_combinedJsonArgs{
@@ -511,7 +513,8 @@ Allowed options)",
g_argLink.c_str(),
"Switch to linker mode, ignoring all options apart from --libraries "
"and modify binaries in place."
- );
+ )
+ (g_argMetadataLiteral.c_str(), "Store referenced sources are literal data in the metadata output.");
po::options_description outputComponents("Output Components");
outputComponents.add_options()
(g_argAst.c_str(), "AST of all source files.")
@@ -634,6 +637,8 @@ bool CommandLineInterface::processInput()
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
try
{
+ if (m_args.count(g_argMetadataLiteral) > 0)
+ m_compiler->useMetadataLiteralSources(true);
if (m_args.count(g_argInputFile))
m_compiler->setRemappings(m_args[g_argInputFile].as<vector<string>>());
for (auto const& sourceCode: m_sourceCodes)