Merge pull request #5941 from ethereum/metadata-compilerstack

Metadata should not require compilation
This commit is contained in:
chriseth
2019-03-04 18:53:07 +01:00
committed by GitHub
7 changed files with 117 additions and 19 deletions
+18 -7
View File
@@ -631,10 +631,24 @@ Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const
string const& CompilerStack::metadata(string const& _contractName) const
{
if (m_stackState != CompilationSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful."));
if (m_stackState < AnalysisSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Analysis was not successful."));
return contract(_contractName).metadata;
return metadata(contract(_contractName));
}
string const& CompilerStack::metadata(Contract const& _contract) const
{
if (m_stackState < AnalysisSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Analysis was not successful."));
solAssert(_contract.contract, "");
// cache the result
if (!_contract.metadata)
_contract.metadata.reset(new string(createMetadata(_contract)));
return *_contract.metadata;
}
Scanner const& CompilerStack::scanner(string const& _sourceName) const
@@ -848,11 +862,8 @@ void CompilerStack::compileContract(
shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_optimiserSettings);
compiledContract.compiler = compiler;
string metadata = createMetadata(compiledContract);
compiledContract.metadata = metadata;
bytes cborEncodedMetadata = createCBORMetadata(
metadata,
metadata(compiledContract),
!onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)
);
+5 -1
View File
@@ -276,7 +276,7 @@ private:
std::shared_ptr<Compiler> compiler;
eth::LinkerObject object; ///< Deployment object (includes the runtime sub-object).
eth::LinkerObject runtimeObject; ///< Runtime object.
std::string metadata; ///< The metadata json that will be hashed into the chain.
mutable std::unique_ptr<std::string const> metadata; ///< The metadata json that will be hashed into the chain.
mutable std::unique_ptr<Json::Value const> abi;
mutable std::unique_ptr<Json::Value const> userDocumentation;
mutable std::unique_ptr<Json::Value const> devDocumentation;
@@ -339,6 +339,10 @@ private:
/// This will generate the JSON object and store it in the Contract object if it is not present yet.
Json::Value const& natspecDev(Contract const&) const;
/// @returns the Contract Metadata
/// This will generate the metadata and store it in the Contract object if it is not present yet.
std::string const& metadata(Contract const&) const;
/// @returns the offset of the entry point of the given function into the list of assembly items
/// or zero if it is not found or does not exist.
size_t functionEntryPoint(
+1 -2
View File
@@ -201,7 +201,6 @@ bool isBinaryRequested(Json::Value const& _outputSelection)
// This does not inculde "evm.methodIdentifiers" on purpose!
static vector<string> const outputsThatRequireBinaries{
"*",
"metadata", // This is only generated at the end of compilation, but could be generated earlier.
"evm.deployedBytecode", "evm.deployedBytecode.object", "evm.deployedBytecode.opcodes",
"evm.deployedBytecode.sourceMap", "evm.deployedBytecode.linkReferences",
"evm.bytecode", "evm.bytecode.object", "evm.bytecode.opcodes", "evm.bytecode.sourceMap",
@@ -777,7 +776,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
Json::Value contractData(Json::objectValue);
if (isArtifactRequested(outputSelection, file, name, "abi"))
contractData["abi"] = m_compilerStack.contractABI(contractName);
if (compilationSuccess && isArtifactRequested(outputSelection, file, name, "metadata"))
if (isArtifactRequested(outputSelection, file, name, "metadata"))
contractData["metadata"] = m_compilerStack.metadata(contractName);
if (isArtifactRequested(outputSelection, file, name, "userdoc"))
contractData["userdoc"] = m_compilerStack.natspecUser(contractName);