Browse Source

Alethzero: Showing a contract's function's hashes at creation

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
3b207c26e9
  1. 1
      alethzero/MainWin.cpp
  2. 18
      libsolidity/CompilerStack.cpp
  3. 3
      libsolidity/CompilerStack.h

1
alethzero/MainWin.cpp

@ -1657,6 +1657,7 @@ void Main::on_data_textChanged()
solidity = "<h4>Solidity</h4>"; solidity = "<h4>Solidity</h4>";
solidity += "<pre>" + QString::fromStdString(compiler.getInterface()).replace(QRegExp("\\s"), "").toHtmlEscaped() + "</pre>"; solidity += "<pre>" + QString::fromStdString(compiler.getInterface()).replace(QRegExp("\\s"), "").toHtmlEscaped() + "</pre>";
solidity += "<pre>" + QString::fromStdString(compiler.getSolidityInterface()).toHtmlEscaped() + "</pre>"; solidity += "<pre>" + QString::fromStdString(compiler.getSolidityInterface()).toHtmlEscaped() + "</pre>";
solidity += "<pre>" + QString::fromStdString(compiler.getFunctionHashes()).toHtmlEscaped() + "</pre>";
} }
catch (dev::Exception const& exception) catch (dev::Exception const& exception)
{ {

18
libsolidity/CompilerStack.cpp

@ -179,6 +179,24 @@ string const& CompilerStack::getMetadata(string const& _contractName, Documentat
return *(*doc); return *(*doc);
} }
std::string const CompilerStack::getFunctionHashes(std::string const& _contractName)
{
if (!m_parseSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful."));
std::string ret = "";
Contract const& contract = getContract(_contractName);
auto interfaceFunctions = contract.contract->getInterfaceFunctions();
for (auto const& it: interfaceFunctions)
{
ret += it.first.abridged();
ret += " :";
ret += it.second->getName() + "\n";
}
return ret;
}
Scanner const& CompilerStack::getScanner(string const& _sourceName) const Scanner const& CompilerStack::getScanner(string const& _sourceName) const
{ {
return *getSource(_sourceName).scanner; return *getSource(_sourceName).scanner;

3
libsolidity/CompilerStack.h

@ -93,6 +93,9 @@ public:
/// Can be one of 4 types defined at @c DocumentationType /// Can be one of 4 types defined at @c DocumentationType
std::string const& getMetadata(std::string const& _contractName, DocumentationType _type) const; std::string const& getMetadata(std::string const& _contractName, DocumentationType _type) const;
/// Convenience function to return all contract method hashes in a string
std::string const getFunctionHashes(std::string const& _contractName = "");
/// @returns the previously used scanner, useful for counting lines during error reporting. /// @returns the previously used scanner, useful for counting lines during error reporting.
Scanner const& getScanner(std::string const& _sourceName = "") const; Scanner const& getScanner(std::string const& _sourceName = "") const;
/// @returns the parsed source unit with the supplied name. /// @returns the parsed source unit with the supplied name.

Loading…
Cancel
Save