From 5789eaa78d0e00f6289101e02f7de5e9decdc7e5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 14 Nov 2016 11:46:43 +0100 Subject: Metadata stamp. --- solc/CommandLineInterface.cpp | 23 ++++++++++++++++++++--- solc/CommandLineInterface.h | 1 + solc/jsonCompiler.cpp | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'solc') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 49fac51c..fdfcabb4 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -78,6 +78,7 @@ static string const g_argCloneBinaryStr = "clone-bin"; static string const g_argOpcodesStr = "opcodes"; static string const g_argNatspecDevStr = "devdoc"; static string const g_argNatspecUserStr = "userdoc"; +static string const g_argMetadata = "metadata"; static string const g_argAddStandard = "add-std"; static string const g_stdinFileName = ""; @@ -91,6 +92,7 @@ static set const g_combinedJsonArgs{ "opcodes", "abi", "interface", + "metadata", "asm", "ast", "userdoc", @@ -117,6 +119,7 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) for (string const& arg: { g_argAbiStr, g_argSignatureHashes, + g_argMetadata, g_argNatspecUserStr, g_argAstJson, g_argNatspecDevStr, @@ -202,6 +205,18 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract) cout << "Function signatures: " << endl << out; } +void CommandLineInterface::handleOnChainMetadata(string const& _contract) +{ + if (!m_args.count(g_argMetadata)) + return; + + string data = m_compiler->onChainMetadata(_contract); + if (m_args.count("output-dir")) + createFile(_contract + ".meta", data); + else + cout << "Metadata: " << endl << data << endl; +} + void CommandLineInterface::handleMeta(DocumentationType _type, string const& _contract) { std::string argName; @@ -467,6 +482,7 @@ Allowed options)", (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argNatspecUserStr.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecDevStr.c_str(), "Natspec developer documentation of all contracts.") + (g_argMetadata.c_str(), "Combined metadata JSON whose swarm hash is stored on-chain.") ("formal", "Translated source suitable for formal analysis."); desc.add(outputComponents); @@ -581,9 +597,7 @@ bool CommandLineInterface::processInput() // TODO: Perhaps we should not compile unless requested bool optimize = m_args.count("optimize") > 0; unsigned runs = m_args["optimize-runs"].as(); - bool successful = m_compiler->compile(optimize, runs); - if (successful) - m_compiler->link(m_libraries); + bool successful = m_compiler->compile(optimize, runs, m_libraries); if (successful && m_args.count("formal")) if (!m_compiler->prepareFormalAnalysis()) @@ -659,6 +673,8 @@ void CommandLineInterface::handleCombinedJSON() Json::Value contractData(Json::objectValue); if (requests.count("abi")) contractData["abi"] = dev::jsonCompactPrint(m_compiler->interface(contractName)); + if (requests.count("metadata")) + contractData["metadata"] = m_compiler->onChainMetadata(contractName); if (requests.count("bin")) contractData["bin"] = m_compiler->object(contractName).toHex(); if (requests.count("bin-runtime")) @@ -918,6 +934,7 @@ void CommandLineInterface::outputCompilationResults() handleBytecode(contract); handleSignatureHashes(contract); + handleOnChainMetadata(contract); handleMeta(DocumentationType::ABIInterface, contract); handleMeta(DocumentationType::NatspecDev, contract); handleMeta(DocumentationType::NatspecUser, contract); diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 33ae6ee6..b8fc1823 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -63,6 +63,7 @@ private: void handleOpcode(std::string const& _contract); void handleBytecode(std::string const& _contract); void handleSignatureHashes(std::string const& _contract); + void handleOnChainMetadata(std::string const& _contract); void handleMeta(DocumentationType _type, std::string const& _contract); void handleGasEstimation(std::string const& _contract); void handleFormal(); diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index 0f95ebe5..d761b541 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -218,6 +218,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback contractData["bytecode"] = compiler.object(contractName).toHex(); contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex(); contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode); + contractData["metadata"] = compiler.onChainMetadata(contractName); contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName)); contractData["gasEstimates"] = estimateGas(compiler, contractName); auto sourceMap = compiler.sourceMapping(contractName); -- cgit From 659b635b2d8274f870ebe487a73b431a2398b741 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 23 Nov 2016 19:04:50 +0100 Subject: Make sure some keys are present. --- solc/CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'solc') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index fdfcabb4..419a1de0 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -212,7 +212,7 @@ void CommandLineInterface::handleOnChainMetadata(string const& _contract) string data = m_compiler->onChainMetadata(_contract); if (m_args.count("output-dir")) - createFile(_contract + ".meta", data); + createFile(_contract + "_meta.json", data); else cout << "Metadata: " << endl << data << endl; } -- cgit From 35325ee7c3e1af558caf0a47c8611cdfde959bb3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 30 Nov 2016 10:12:28 +0000 Subject: Update metadata documentation --- solc/CommandLineInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'solc') diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 419a1de0..6e59099a 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -482,7 +482,7 @@ Allowed options)", (g_argSignatureHashes.c_str(), "Function signature hashes of the contracts.") (g_argNatspecUserStr.c_str(), "Natspec user documentation of all contracts.") (g_argNatspecDevStr.c_str(), "Natspec developer documentation of all contracts.") - (g_argMetadata.c_str(), "Combined metadata JSON whose swarm hash is stored on-chain.") + (g_argMetadata.c_str(), "Combined Metadata JSON whose Swarm hash is stored on-chain.") ("formal", "Translated source suitable for formal analysis."); desc.add(outputComponents); -- cgit