From bcfa8136be3037c96c5670b3dfd564b8db1feed6 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 19 Dec 2016 11:10:38 +0100 Subject: [PATCH] accounts/abi: add support for anonymous events --- accounts/abi/abi.go | 18 ++++++++++-------- accounts/abi/abi_test.go | 20 ++++++++++++++++---- accounts/abi/event.go | 8 +++++--- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 2efac1307d..4e02ae5f19 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -345,12 +345,13 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) error { func (abi *ABI) UnmarshalJSON(data []byte) error { var fields []struct { - Type string - Name string - Constant bool - Indexed bool - Inputs []Argument - Outputs []Argument + Type string + Name string + Constant bool + Indexed bool + Anonymous bool + Inputs []Argument + Outputs []Argument } if err := json.Unmarshal(data, &fields); err != nil { @@ -375,8 +376,9 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { } case "event": abi.Events[field.Name] = Event{ - Name: field.Name, - Inputs: field.Inputs, + Name: field.Name, + Anonymous: field.Anonymous, + Inputs: field.Inputs, } } } diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 85e25f9ea8..ccfd0ebd1d 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -752,23 +752,35 @@ func TestDefaultFunctionParsing(t *testing.T) { func TestBareEvents(t *testing.T) { const definition = `[ { "type" : "event", "name" : "balance" }, - { "type" : "event", "name" : "name" }]` + { "type" : "event", "name" : "name" }, + { "type" : "event", "name" : "anon", "anonymous" : true}]` abi, err := JSON(strings.NewReader(definition)) if err != nil { t.Fatal(err) } - if len(abi.Events) != 2 { - t.Error("expected 2 events") + if len(abi.Events) != 3 { + t.Error("expected 3 events") } if _, ok := abi.Events["balance"]; !ok { 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") + } 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") } } diff --git a/accounts/abi/event.go b/accounts/abi/event.go index e74c7c732c..51ab842418 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -25,10 +25,12 @@ import ( ) // 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 { - Name string - Inputs []Argument + Name string + Anonymous bool + Inputs []Argument } // Id returns the canonical representation of the event's signature used by the