From 8de02c777856daffc2d48cc68a15b6b6f16ce134 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 19 Apr 2017 16:45:36 +0100 Subject: [PATCH 1/2] Support URL sources in StandardCompiler --- libsolidity/interface/StandardCompiler.cpp | 35 ++++++++++++++++++++-- libsolidity/interface/StandardCompiler.h | 3 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index db89e16c0..4a8787b3e 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -162,11 +162,43 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) if (!sources) return formatFatalError("JSONError", "No input sources specified."); + Json::Value errors = Json::arrayValue; + for (auto const& sourceName: sources.getMemberNames()) if (sources[sourceName]["content"].isString()) m_compilerStack.addSource(sourceName, sources[sourceName]["content"].asString()); else if (sources[sourceName]["urls"].isArray()) - return formatFatalError("UnimplementedFeatureError", "Input URLs not supported yet."); + { + if (!m_readFile) + return formatFatalError("JSONError", "No import callback supplied, but URL is requested."); + + bool found = false; + vector failures; + + for (auto const& url: sources[sourceName]["urls"]) + { + ReadFile::Result result = m_readFile(url.asString()); + if (result.success) + { + m_compilerStack.addSource(sourceName, result.contentsOrErrorMessage); + found = true; + break; + } + else + failures.push_back("Cannot import url (\"" + url.asString() + "\"): " + result.contentsOrErrorMessage); + } + + for (auto const& failure: failures) + { + /// If the import succeeded, let mark all the others as warnings, otherwise all of them are errors. + errors.append(formatError( + found ? true : false, + "IOError", + "general", + failure + )); + } + } else return formatFatalError("JSONError", "Invalid input source specified."); @@ -196,7 +228,6 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); }; - Json::Value errors = Json::arrayValue; bool success = false; try diff --git a/libsolidity/interface/StandardCompiler.h b/libsolidity/interface/StandardCompiler.h index 12d85aada..0182027db 100644 --- a/libsolidity/interface/StandardCompiler.h +++ b/libsolidity/interface/StandardCompiler.h @@ -40,7 +40,7 @@ public: /// Creates a new StandardCompiler. /// @param _readFile callback to used to read files for import statements. Should return StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) - : m_compilerStack(_readFile) + : m_compilerStack(_readFile), m_readFile(_readFile) { } @@ -55,6 +55,7 @@ private: Json::Value compileInternal(Json::Value const& _input); CompilerStack m_compilerStack; + ReadFile::Callback const& m_readFile; }; } From c76e0a5872ddd43e42d56e42b37cc95cf773b42d Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 22 Apr 2017 01:12:38 +0200 Subject: [PATCH 2/2] Changed const reference to value. --- libsolidity/interface/StandardCompiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/interface/StandardCompiler.h b/libsolidity/interface/StandardCompiler.h index 0182027db..0b7148345 100644 --- a/libsolidity/interface/StandardCompiler.h +++ b/libsolidity/interface/StandardCompiler.h @@ -55,7 +55,7 @@ private: Json::Value compileInternal(Json::Value const& _input); CompilerStack m_compilerStack; - ReadFile::Callback const& m_readFile; + ReadFile::Callback m_readFile; }; }