Merge pull request #6599 from ethereum/ipfsHash

Add IPFS hash of source files to metadata.
This commit is contained in:
chriseth
2019-05-15 14:21:58 +02:00
committed by GitHub
8 changed files with 509 additions and 0 deletions
+9
View File
@@ -56,6 +56,7 @@
#include <libevmasm/Exceptions.h>
#include <libdevcore/SwarmHash.h>
#include <libdevcore/IpfsHash.h>
#include <libdevcore/JSON.h>
#include <json/json.h>
@@ -769,6 +770,13 @@ h256 const& CompilerStack::Source::swarmHash() const
return swarmHashCached;
}
string const& CompilerStack::Source::ipfsUrl() const
{
if (ipfsUrlCached.empty())
if (scanner->source().size() < 1024 * 256)
ipfsUrlCached = "dweb:/ipfs/" + dev::ipfsHashBase58(scanner->source());
return ipfsUrlCached;
}
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
{
@@ -1030,6 +1038,7 @@ string CompilerStack::createMetadata(Contract const& _contract) const
{
meta["sources"][s.first]["urls"] = Json::arrayValue;
meta["sources"][s.first]["urls"].append("bzzr://" + toHex(s.second.swarmHash().asBytes()));
meta["sources"][s.first]["urls"].append(s.second.ipfsUrl());
}
}
+2
View File
@@ -272,9 +272,11 @@ private:
std::shared_ptr<SourceUnit> ast;
h256 mutable keccak256HashCached;
h256 mutable swarmHashCached;
std::string mutable ipfsUrlCached;
void reset() { *this = Source(); }
h256 const& keccak256() const;
h256 const& swarmHash() const;
std::string const& ipfsUrl() const;
};
/// The state per contract. Filled gradually during compilation.