From 89a4e43b561052ed780161c5047ad21b663c46b3 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Wed, 13 May 2026 01:21:35 +0800 Subject: [PATCH] accounts/abi: checkout whether event exists --- accounts/abi/bind/v2/base.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/accounts/abi/bind/v2/base.go b/accounts/abi/bind/v2/base.go index 862175ee32..11a6f86933 100644 --- a/accounts/abi/bind/v2/base.go +++ b/accounts/abi/bind/v2/base.go @@ -463,8 +463,12 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]any if opts == nil { opts = new(FilterOpts) } + ev, ok := c.abi.Events[name] + if !ok { + return nil, nil, fmt.Errorf("event %q not found in the ABI", name) + } // Append the event selector to the query parameters and construct the topic set - query = append([][]any{{c.abi.Events[name].ID}}, query...) + query = append([][]any{{ev.ID}}, query...) topics, err := abi.MakeTopics(query...) if err != nil { return nil, nil, err @@ -508,8 +512,12 @@ func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]any) if opts == nil { opts = new(WatchOpts) } + ev, ok := c.abi.Events[name] + if !ok { + return nil, nil, fmt.Errorf("event %q not found in the ABI", name) + } // Append the event selector to the query parameters and construct the topic set - query = append([][]any{{c.abi.Events[name].ID}}, query...) + query = append([][]any{{ev.ID}}, query...) topics, err := abi.MakeTopics(query...) if err != nil {