@@ -31,21 +31,28 @@ func NewContractInstance(backend ContractBackend, addr common.Address, abi abi.A
3131 return NewBoundContract (addr , abi , backend , backend , backend )
3232}
3333
34+ // ContractEvent is a type constraint for ABI event types.
35+ type ContractEvent interface {
36+ ContractEventName () string
37+ }
38+
3439// FilterEvents returns an EventIterator instance for filtering historical events based on the event id and a block range.
35- func FilterEvents [T any ](c * BoundContract , opts * FilterOpts , eventName string , unpack func (* types.Log ) (* T , error ), topics ... []any ) (* EventIterator [T ], error ) {
36- logs , sub , err := c .FilterLogs (opts , eventName , topics ... )
40+ func FilterEvents [Ev ContractEvent ](c * BoundContract , opts * FilterOpts , unpack func (* types.Log ) (* Ev , error ), topics ... []any ) (* EventIterator [Ev ], error ) {
41+ var e Ev
42+ logs , sub , err := c .FilterLogs (opts , e .ContractEventName (), topics ... )
3743 if err != nil {
3844 return nil , err
3945 }
40- return & EventIterator [T ]{unpack : unpack , logs : logs , sub : sub }, nil
46+ return & EventIterator [Ev ]{unpack : unpack , logs : logs , sub : sub }, nil
4147}
4248
4349// WatchEvents causes logs emitted with a given event id from a specified
4450// contract to be intercepted, unpacked, and forwarded to sink. If
4551// unpack returns an error, the returned subscription is closed with the
4652// error.
47- func WatchEvents [T any ](c * BoundContract , opts * WatchOpts , eventName string , unpack func (* types.Log ) (* T , error ), sink chan <- * T , topics ... []any ) (event.Subscription , error ) {
48- logs , sub , err := c .WatchLogs (opts , eventName , topics ... )
53+ func WatchEvents [Ev ContractEvent ](c * BoundContract , opts * WatchOpts , unpack func (* types.Log ) (* Ev , error ), sink chan <- * Ev , topics ... []any ) (event.Subscription , error ) {
54+ var e Ev
55+ logs , sub , err := c .WatchLogs (opts , e .ContractEventName (), topics ... )
4956 if err != nil {
5057 return nil , err
5158 }
0 commit comments