aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-01-15 08:37:52 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-01-15 08:37:52 +0800
commit1515f140b3bc2882aa8e2495155c775d05883ed1 (patch)
tree80b5e2e564fa9924cbf4a6b4fac7dfde938d603d
parent1a4280de35d118493e11bc8272d2d7127adaa50c (diff)
parent895a2852f47c456579ba6d9b4fa03659ed0a3af1 (diff)
downloaddexon-solidity-1515f140b3bc2882aa8e2495155c775d05883ed1.tar.gz
dexon-solidity-1515f140b3bc2882aa8e2495155c775d05883ed1.tar.zst
dexon-solidity-1515f140b3bc2882aa8e2495155c775d05883ed1.zip
Merge pull request #798 from LefterisJP/natspec_OnContractCreation
Natspec Popup Authentication on transaction
-rw-r--r--Compiler.cpp5
-rw-r--r--Compiler.h2
-rw-r--r--CompilerStack.cpp13
-rw-r--r--CompilerStack.h8
-rw-r--r--InterfaceHandler.cpp4
5 files changed, 27 insertions, 5 deletions
diff --git a/Compiler.cpp b/Compiler.cpp
index 782a7efe..bd6571b9 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -50,10 +50,9 @@ void Compiler::compileContract(ContractDefinition const& _contract, vector<Magic
function->accept(*this);
// Swap the runtime context with the creation-time context
- CompilerContext runtimeContext;
- swap(m_context, runtimeContext);
+ swap(m_context, m_runtimeContext);
initializeContext(_contract, _magicGlobals, _contracts);
- packIntoContractCreator(_contract, runtimeContext);
+ packIntoContractCreator(_contract, m_runtimeContext);
}
void Compiler::initializeContext(ContractDefinition const& _contract, vector<MagicVariableDeclaration const*> const& _magicGlobals,
diff --git a/Compiler.h b/Compiler.h
index e83d1ed3..c229a7a8 100644
--- a/Compiler.h
+++ b/Compiler.h
@@ -35,6 +35,7 @@ public:
void compileContract(ContractDefinition const& _contract, std::vector<MagicVariableDeclaration const*> const& _magicGlobals,
std::map<ContractDefinition const*, bytes const*> const& _contracts);
bytes getAssembledBytecode() { return m_context.getAssembledBytecode(m_optimize); }
+ bytes getRuntimeBytecode() { return m_runtimeContext.getAssembledBytecode(m_optimize);}
void streamAssembly(std::ostream& _stream) const { m_context.streamAssembly(_stream); }
private:
@@ -70,6 +71,7 @@ private:
bool const m_optimize;
CompilerContext m_context;
+ CompilerContext m_runtimeContext;
std::vector<eth::AssemblyItem> m_breakTags; ///< tag to jump to for a "break" statement
std::vector<eth::AssemblyItem> m_continueTags; ///< tag to jump to for a "continue" statement
eth::AssemblyItem m_returnTag; ///< tag to jump to for a "return" statement
diff --git a/CompilerStack.cpp b/CompilerStack.cpp
index 904c77c5..5532d74b 100644
--- a/CompilerStack.cpp
+++ b/CompilerStack.cpp
@@ -30,6 +30,8 @@
#include <libsolidity/CompilerStack.h>
#include <libsolidity/InterfaceHandler.h>
+#include <libdevcrypto/SHA3.h>
+
using namespace std;
namespace dev
@@ -117,6 +119,7 @@ void CompilerStack::compile(bool _optimize)
contractBytecode);
Contract& compiledContract = m_contracts[contract->getName()];
compiledContract.bytecode = compiler->getAssembledBytecode();
+ compiledContract.runtimeBytecode = compiler->getRuntimeBytecode();
compiledContract.compiler = move(compiler);
contractBytecode[compiledContract.contract] = &compiledContract.bytecode;
}
@@ -134,6 +137,16 @@ bytes const& CompilerStack::getBytecode(string const& _contractName) const
return getContract(_contractName).bytecode;
}
+bytes const& CompilerStack::getRuntimeBytecode(string const& _contractName) const
+{
+ return getContract(_contractName).runtimeBytecode;
+}
+
+dev::h256 CompilerStack::getContractCodeHash(string const& _contractName) const
+{
+ return dev::sha3(getRuntimeBytecode(_contractName));
+}
+
void CompilerStack::streamAssembly(ostream& _outStream, string const& _contractName) const
{
getContract(_contractName).compiler->streamAssembly(_outStream);
diff --git a/CompilerStack.h b/CompilerStack.h
index afc9a516..aa55abe5 100644
--- a/CompilerStack.h
+++ b/CompilerStack.h
@@ -28,6 +28,7 @@
#include <memory>
#include <boost/noncopyable.hpp>
#include <libdevcore/Common.h>
+#include <libdevcore/FixedHash.h>
namespace dev {
namespace solidity {
@@ -75,7 +76,13 @@ public:
/// @returns the compiled bytecode
bytes const& compile(std::string const& _sourceCode, bool _optimize = false);
+ /// @returns the assembled bytecode for a contract.
bytes const& getBytecode(std::string const& _contractName = "") const;
+ /// @returns the runtime bytecode for the contract, i.e. the code that is returned by the constructor.
+ bytes const& getRuntimeBytecode(std::string const& _contractName = "") const;
+ /// @returns hash of the runtime bytecode for the contract, i.e. the code that is returned by the constructor.
+ dev::h256 getContractCodeHash(std::string const& _contractName = "") const;
+
/// Streams a verbose version of the assembly to @a _outStream.
/// Prerequisite: Successful compilation.
void streamAssembly(std::ostream& _outStream, std::string const& _contractName = "") const;
@@ -121,6 +128,7 @@ private:
ContractDefinition const* contract = nullptr;
std::shared_ptr<Compiler> compiler;
bytes bytecode;
+ bytes runtimeBytecode;
std::shared_ptr<InterfaceHandler> interfaceHandler;
mutable std::unique_ptr<std::string const> interface;
mutable std::unique_ptr<std::string const> solidityInterface;
diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp
index a5c6f4a1..4c7ae5f4 100644
--- a/InterfaceHandler.cpp
+++ b/InterfaceHandler.cpp
@@ -106,7 +106,7 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
if (!m_notice.empty())
{// since @notice is the only user tag if missing function should not appear
user["notice"] = Json::Value(m_notice);
- methods[it.second->getName()] = user;
+ methods[it.second->getCanonicalSignature()] = user;
}
}
}
@@ -162,7 +162,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
method["return"] = m_return;
if (!method.empty()) // add the function, only if we have any documentation to add
- methods[it.second->getName()] = method;
+ methods[it.second->getCanonicalSignature()] = method;
}
}
doc["methods"] = methods;