accounts/abi/bind: use SubscribeFilterLogs to simplify code

This commit is contained in:
buddh0 2024-03-04 11:11:24 +08:00
parent 00905f7dc4
commit 8cbff17baa

View file

@ -454,24 +454,7 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int
if opts.End != nil { if opts.End != nil {
config.ToBlock = new(big.Int).SetUint64(*opts.End) config.ToBlock = new(big.Int).SetUint64(*opts.End)
} }
/* TODO(karalabe): Replace the rest of the method below with this when supported
sub, err := c.filterer.SubscribeFilterLogs(ensureContext(opts.Context), config, logs) sub, err := c.filterer.SubscribeFilterLogs(ensureContext(opts.Context), config, logs)
*/
buff, err := c.filterer.FilterLogs(ensureContext(opts.Context), config)
if err != nil {
return nil, nil, err
}
sub, err := event.NewSubscription(func(quit <-chan struct{}) error {
for _, log := range buff {
select {
case logs <- log:
case <-quit:
return nil
}
}
return nil
}), nil
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }