accounts: simplify code with new api(SubscribeFilterLogs)

This commit is contained in:
cuiweixie 2025-08-08 20:38:04 +08:00
parent c3ef6c77c2
commit ac580b3427

View file

@ -473,23 +473,11 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]any
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 { if err != nil {
return nil, nil, err return nil, nil, err
} }
sub := event.NewSubscription(func(quit <-chan struct{}) error {
for _, log := range buff {
select {
case logs <- log:
case <-quit:
return nil
}
}
return nil
})
return logs, sub, nil return logs, sub, nil
} }