diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index e92970556a..5adfcda1b0 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -148,13 +148,12 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { return nil, fmt.Errorf("no method with id: %#x", sigdata[:4]) } -// EventById looks up a event by the topic hash -// returns nil if none found -func (abi *ABI) EventById(topic common.Hash) (*Event, error) { +// EventById looks up for events by the topic hash +func (abi *ABI) EventById(topic common.Hash) *Event { for _, event := range abi.Events { if event.Id() == topic { - return &event, nil + return &event } } - return nil, fmt.Errorf("no event with topic: %#x", topic.Hex()) + return nil } diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index cbd7940380..0ca1b6ba82 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -762,10 +762,9 @@ func TestABI_EventById(t *testing.T) { topic := "received(address,uint256,bytes)" topicID := crypto.Keccak256Hash([]byte(topic)) - - event, err := abi.EventById(topicID) - if err != nil { - t.Fatalf("Failed to look up ABI event: %v", err) + event := abi.EventById(topicID) + if event == nil { + t.Fatalf("Failed to look up ABI event for topic %s", topicID.Hex()) } if event.Id() != topicID { @@ -773,7 +772,8 @@ func TestABI_EventById(t *testing.T) { } unknowntopicID := crypto.Keccak256Hash([]byte("unknownEvent")) - if _, err := abi.EventById(unknowntopicID); err == nil { - t.Errorf("Expected error, no matching event id") + unknownEvent := abi.EventById(unknowntopicID) + if unknownEvent != nil { + t.Fatalf("We should not find any event for the topic %s", unknowntopicID.Hex()) } }