Skip to content

Commit

Permalink
Use IPFS url in metadata for source links.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed May 6, 2019
1 parent 1651cbc commit c31e19f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <libevmasm/Exceptions.h>

#include <libdevcore/SwarmHash.h>
#include <libdevcore/IpfsHash.h>
#include <libdevcore/JSON.h>

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

string const& CompilerStack::Source::ipfsUrl() const
{
if (ipfsUrlCached.empty())
if (scanner->source().size() < 1025 * 256)
ipfsUrlCached = "ipfs://" + dev::ipfsHashBase58(scanner->source());
return ipfsUrlCached;
}

StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath)
{
solAssert(m_stackState < ParsingSuccessful, "");
Expand Down Expand Up @@ -1028,6 +1037,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());
}
}

Expand Down
2 changes: 2 additions & 0 deletions libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ class CompilerStack: boost::noncopyable
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.
Expand Down

0 comments on commit c31e19f

Please sign in to comment.