Use IPFS url in metadata for source links.

This commit is contained in:
chriseth 2019-04-30 11:07:23 +02:00
parent d753fcdb36
commit b01a8c544c
2 changed files with 12 additions and 0 deletions

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,14 @@ 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)
{
solAssert(m_stackState < ParsingSuccessful, "");
@ -1029,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());
}
}

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.