Skip to content

Commit 74de38f

Browse files
committed
Use IPFS url in metadata for source links.
1 parent d753fcd commit 74de38f

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>
@@ -769,6 +770,14 @@ h256 const& CompilerStack::Source::swarmHash() const
769770
return swarmHashCached;
770771
}
771772

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

libsolidity/interface/CompilerStack.h

+2
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,11 @@ class CompilerStack: boost::noncopyable
272272
std::shared_ptr<SourceUnit> ast;
273273
h256 mutable keccak256HashCached;
274274
h256 mutable swarmHashCached;
275+
std::string mutable ipfsUrlCached;
275276
void reset() { *this = Source(); }
276277
h256 const& keccak256() const;
277278
h256 const& swarmHash() const;
279+
std::string const& ipfsUrl() const;
278280
};
279281

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

0 commit comments

Comments
 (0)