From fc21f62a31ad294e40144129143bd7b628191c4b Mon Sep 17 00:00:00 2001 From: Victor Tran Date: Fri, 19 Oct 2018 02:26:22 +0700 Subject: [PATCH] Add function to find event by log topic (aka. id) --- accounts/abi/abi.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 535e5d78b2..e1107f6d3b 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -147,3 +147,14 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { } return nil, fmt.Errorf("no method with id: %#x", sigdata[:4]) } + +// EventById looks up an event by the first topic hash +// returns nil if none was found +func (abi *ABI) EventById(topic []byte) (*Event, error) { + for _, event := range abi.Events { + if bytes.Equal(event.Id().Bytes(), topic) { + return &event, nil + } + } + return nil, fmt.Errorf("no event with id: %#x", topic) +}