Skip to content

Commit c31e19f

Browse files
committed
Use IPFS url in metadata for source links.
1 parent 1651cbc commit c31e19f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libsolidity/interface/CompilerStack.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <libevmasm/Exceptions.h>
5757

5858
#include <libdevcore/SwarmHash.h>
59+
#include <libdevcore/IpfsHash.h>
5960
#include <libdevcore/JSON.h>
6061

6162
#include <json/json.h>
@@ -768,6 +769,14 @@ h256 const& CompilerStack::Source::swarmHash() const
768769
return swarmHashCached;
769770
}
770771

772+
string const& CompilerStack::Source::ipfsUrl() const
773+
{
774+
if (ipfsUrlCached.empty())
775+
if (scanner->source().size() < 1025 * 256)
776+
ipfsUrlCached = "ipfs://" + dev::ipfsHashBase58(scanner->source());
777+
return ipfsUrlCached;
778+
}
779+
771780
StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
772781
{
773782
solAssert(m_stackState < ParsingSuccessful, "");
@@ -1028,6 +1037,7 @@ string CompilerStack::createMetadata(Contract const& _contract) const
10281037
{
10291038
meta["sources"][s.first]["urls"] = Json::arrayValue;
10301039
meta["sources"][s.first]["urls"].append("bzzr://" + toHex(s.second.swarmHash().asBytes()));
1040+
meta["sources"][s.first]["urls"].append(s.second.ipfsUrl());
10311041
}
10321042
}
10331043

libsolidity/interface/CompilerStack.h

+2
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ class CompilerStack: boost::noncopyable
269269
std::shared_ptr<SourceUnit> ast;
270270
h256 mutable keccak256HashCached;
271271
h256 mutable swarmHashCached;
272+
std::string mutable ipfsUrlCached;
272273
void reset() { *this = Source(); }
273274
h256 const& keccak256() const;
274275
h256 const& swarmHash() const;
276+
std::string const& ipfsUrl() const;
275277
};
276278

277279
/// The state per contract. Filled gradually during compilation.

0 commit comments

Comments
 (0)