Add function to find event by log topic (aka. id)

This commit is contained in:
Victor Tran 2018-10-19 02:26:22 +07:00 committed by GitHub
parent cdf5982cfc
commit fc21f62a31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -147,3 +147,14 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
} }
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4]) 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)
}