accounts/abi: add support for anonymous events

This commit is contained in:
Bas van Kervel 2016-12-19 11:10:38 +01:00
parent 38827dd9ca
commit bcfa8136be
3 changed files with 31 additions and 15 deletions

View file

@ -349,6 +349,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
Name string Name string
Constant bool Constant bool
Indexed bool Indexed bool
Anonymous bool
Inputs []Argument Inputs []Argument
Outputs []Argument Outputs []Argument
} }
@ -376,6 +377,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
case "event": case "event":
abi.Events[field.Name] = Event{ abi.Events[field.Name] = Event{
Name: field.Name, Name: field.Name,
Anonymous: field.Anonymous,
Inputs: field.Inputs, Inputs: field.Inputs,
} }
} }

View file

@ -752,23 +752,35 @@ func TestDefaultFunctionParsing(t *testing.T) {
func TestBareEvents(t *testing.T) { func TestBareEvents(t *testing.T) {
const definition = `[ const definition = `[
{ "type" : "event", "name" : "balance" }, { "type" : "event", "name" : "balance" },
{ "type" : "event", "name" : "name" }]` { "type" : "event", "name" : "name" },
{ "type" : "event", "name" : "anon", "anonymous" : true}]`
abi, err := JSON(strings.NewReader(definition)) abi, err := JSON(strings.NewReader(definition))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if len(abi.Events) != 2 { if len(abi.Events) != 3 {
t.Error("expected 2 events") t.Error("expected 3 events")
} }
if _, ok := abi.Events["balance"]; !ok { if _, ok := abi.Events["balance"]; !ok {
t.Error("expected 'balance' event to be present") t.Error("expected 'balance' event to be present")
} }
if _, ok := abi.Events["name"]; !ok { if ev, ok := abi.Events["name"]; !ok {
t.Error("expected 'name' event to be present") t.Error("expected 'name' event to be present")
} else if ev.Anonymous {
t.Errorf("expected 'name' to have the Anonymous field set to false")
}
anonEvent, ok := abi.Events["anon"]
if ok {
if !anonEvent.Anonymous {
t.Errorf("expected anon event to have the Anonymous field set to true")
}
} else {
t.Errorf("expected 'anon' event to be present")
} }
} }

View file

@ -25,9 +25,11 @@ import (
) )
// Event is an event potentially triggered by the EVM's LOG mechanism. The Event // Event is an event potentially triggered by the EVM's LOG mechanism. The Event
// holds type information (inputs) about the yielded output // holds type information (inputs) about the yielded output. Anonymous events
// don't get the signature canonical representation as the first LOG topic.
type Event struct { type Event struct {
Name string Name string
Anonymous bool
Inputs []Argument Inputs []Argument
} }