From a34f2f1a316d6093c14045ee8423d913ac01421d Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 18 Jun 2016 11:11:55 +0100 Subject: Support payable keyword for functions --- libsolidity/codegen/ContractCompiler.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'libsolidity/codegen/ContractCompiler.cpp') diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 9d77ccdc..eba85103 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -243,6 +243,14 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac if (fallback) { eth::AssemblyItem returnTag = m_context.pushNewTag(); + + // Reject transaction if value is not accepted, but was received + if (!fallback->isPayable()) + { + m_context << Instruction::CALLVALUE; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } + fallback->accept(*this); m_context << returnTag; appendReturnValuePacker(FunctionType(*fallback).returnParameterTypes(), _contract.isLibrary()); @@ -255,8 +263,17 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac FunctionTypePointer const& functionType = it.second; solAssert(functionType->hasDeclaration(), ""); CompilerContext::LocationSetter locationSetter(m_context, functionType->declaration()); + m_context << callDataUnpackerEntryPoints.at(it.first); eth::AssemblyItem returnTag = m_context.pushNewTag(); + + // Reject transaction if value is not accepted, but was received + if (!functionType->isPayable()) + { + m_context << Instruction::CALLVALUE; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } + m_context << CompilerUtils::dataStartOffset; appendCalldataUnpacker(functionType->parameterTypes()); m_context.appendJumpTo(m_context.functionEntryLabel(functionType->declaration())); -- cgit v1.2.3 From 962531af96a8a3ed6b28462d43c69d78fa48d511 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 26 Aug 2016 19:37:10 +0100 Subject: Merged in changes from chriseth/payable --- libsolidity/codegen/ContractCompiler.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'libsolidity/codegen/ContractCompiler.cpp') diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index eba85103..58e6847c 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -243,14 +243,6 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac if (fallback) { eth::AssemblyItem returnTag = m_context.pushNewTag(); - - // Reject transaction if value is not accepted, but was received - if (!fallback->isPayable()) - { - m_context << Instruction::CALLVALUE; - m_context.appendConditionalJumpTo(m_context.errorTag()); - } - fallback->accept(*this); m_context << returnTag; appendReturnValuePacker(FunctionType(*fallback).returnParameterTypes(), _contract.isLibrary()); @@ -265,15 +257,14 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac CompilerContext::LocationSetter locationSetter(m_context, functionType->declaration()); m_context << callDataUnpackerEntryPoints.at(it.first); - eth::AssemblyItem returnTag = m_context.pushNewTag(); - - // Reject transaction if value is not accepted, but was received if (!functionType->isPayable()) { + // Throw if function is not payable but call contained ether. m_context << Instruction::CALLVALUE; m_context.appendConditionalJumpTo(m_context.errorTag()); } + eth::AssemblyItem returnTag = m_context.pushNewTag(); m_context << CompilerUtils::dataStartOffset; appendCalldataUnpacker(functionType->parameterTypes()); m_context.appendJumpTo(m_context.functionEntryLabel(functionType->declaration())); -- cgit v1.2.3 From 9c64edf11052f2918f10ccd202bbfda628005562 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 31 Aug 2016 20:43:24 +0200 Subject: Change function type to include and propagate payable and constant modifier. --- libsolidity/codegen/ContractCompiler.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libsolidity/codegen/ContractCompiler.cpp') diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 58e6847c..33571bc0 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -242,6 +242,12 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac m_context << notFound; if (fallback) { + if (!fallback->isPayable()) + { + // Throw if function is not payable but call contained ether. + m_context << Instruction::CALLVALUE; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } eth::AssemblyItem returnTag = m_context.pushNewTag(); fallback->accept(*this); m_context << returnTag; -- cgit v1.2.3