diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index e3abd9e23..3e49173c8 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -56,6 +56,7 @@ #include #include +#include #include #include @@ -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()); } } diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 925557ab3..de90553cd 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -272,9 +272,11 @@ private: std::shared_ptr 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.