Browse Source

Added anonymous flag to event.

added test
cl-refactor
Liana Husikyan 10 years ago
parent
commit
0b14d26f6b
  1. 7
      libsolidity/AST.h
  2. 9
      libsolidity/ExpressionCompiler.cpp
  3. 1
      libsolidity/InterfaceHandler.cpp
  4. 8
      libsolidity/Parser.cpp
  5. 1
      libsolidity/Token.h
  6. 2
      test/SolidityEndToEndTest.cpp

7
libsolidity/AST.h

@ -556,14 +556,16 @@ public:
EventDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<ParameterList> const& _parameters):
Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters) {}
ASTPointer<ParameterList> const& _parameters,
bool _anonymous = false):
Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters) , m_anonymous(_anonymous){}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters->getParameters(); }
ParameterList const& getParameterList() const { return *m_parameters; }
bool IsAnonymous() const { return m_anonymous; }
virtual TypePointer getType(ContractDefinition const* = nullptr) const override
{
@ -574,6 +576,7 @@ public:
private:
ASTPointer<ParameterList> m_parameters;
bool m_anonymous;
};
/**

9
libsolidity/ExpressionCompiler.cpp

@ -542,9 +542,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
appendTypeConversion(*arguments[arg - 1]->getType(),
*function.getParameterTypes()[arg - 1], true);
}
m_context << u256(h256::Arith(dev::sha3(function.getCanonicalSignature(event.getName()))));
++numIndexed;
solAssert(numIndexed <= 4, "Too many indexed arguments.");
if (!event.IsAnonymous())
{
m_context << u256(h256::Arith(dev::sha3(function.getCanonicalSignature(event.getName()))));
++numIndexed;
}
solAssert(numIndexed <= 4 - (event.IsAnonymous() ? 1 : 0), "Too many indexed arguments.");
// Copy all non-indexed arguments to memory (data)
m_context << u256(0);
for (unsigned arg = 0; arg < arguments.size(); ++arg)

1
libsolidity/InterfaceHandler.cpp

@ -70,6 +70,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
Json::Value event;
event["type"] = "event";
event["name"] = it->getName();
//todo add anonymous!;
Json::Value params(Json::arrayValue);
for (auto const& p: it->getParameters())
{

8
libsolidity/Parser.cpp

@ -388,6 +388,12 @@ ASTPointer<EventDefinition> Parser::parseEventDefinition()
docstring = make_shared<ASTString>(m_scanner->getCurrentCommentLiteral());
expectToken(Token::Event);
bool anonymous = false;
if (m_scanner->getCurrentToken() == Token::Anonymous)
{
anonymous = true;
m_scanner->next();
}
ASTPointer<ASTString> name(expectIdentifierToken());
ASTPointer<ParameterList> parameters;
if (m_scanner->getCurrentToken() == Token::LParen)
@ -396,7 +402,7 @@ ASTPointer<EventDefinition> Parser::parseEventDefinition()
parameters = createEmptyParameterList();
nodeFactory.markEndPosition();
expectToken(Token::Semicolon);
return nodeFactory.createNode<EventDefinition>(name, docstring, parameters);
return nodeFactory.createNode<EventDefinition>(name, docstring, parameters, anonymous);
}
ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()

1
libsolidity/Token.h

@ -145,6 +145,7 @@ namespace solidity
K(Break, "break", 0) \
K(Case, "case", 0) \
K(Const, "constant", 0) \
K(Anonymous, "anonymous", 0) \
K(Continue, "continue", 0) \
K(Contract, "contract", 0) \
K(Default, "default", 0) \

2
test/SolidityEndToEndTest.cpp

@ -2214,7 +2214,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous)
)";
compileAndRun(sourceCode);
callContractFunction("deposit()");
BOOST_REQUIRE_EQUAL(m_logs.size(), 0);
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 0);
}
BOOST_AUTO_TEST_CASE(event_lots_of_data)

Loading…
Cancel
Save