ethclient: set from block to nil if q.from is nil

This commit is contained in:
jsvisa 2025-09-11 15:58:46 +08:00
parent 2079198ce2
commit 7f90a0fff7

View file

@ -479,6 +479,10 @@ func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer
// TODO(s1na): Log subscription prohibits ToBlock being set. // TODO(s1na): Log subscription prohibits ToBlock being set.
// This will be later re-allowed once it supports historical-only queries. // This will be later re-allowed once it supports historical-only queries.
arg["toBlock"] = nil arg["toBlock"] = nil
// For subscriptions, if FromBlock is nil, we want only live logs, not historical logs from genesis
if q.FromBlock == nil {
arg["fromBlock"] = "latest"
}
sub, err := ec.c.EthSubscribe(ctx, ch, "logs", arg) sub, err := ec.c.EthSubscribe(ctx, ch, "logs", arg)
if err != nil { if err != nil {
// Defensively prefer returning nil interface explicitly on error-path, instead // Defensively prefer returning nil interface explicitly on error-path, instead