ethclient: ensure returned subscription is nil on error (#26976)
This commit is contained in:
parent
792d893ed0
commit
df383addee
@ -320,7 +320,14 @@ func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, err
|
||||
// SubscribeNewHead subscribes to notifications about the current blockchain head
|
||||
// on the given channel.
|
||||
func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
|
||||
return ec.c.EthSubscribe(ctx, ch, "newHeads")
|
||||
sub, err := ec.c.EthSubscribe(ctx, ch, "newHeads")
|
||||
if err != nil {
|
||||
// Defensively prefer returning nil interface explicitly on error-path, instead
|
||||
// of letting default golang behavior wrap it with non-nil interface that stores
|
||||
// nil concrete type value.
|
||||
return nil, err
|
||||
}
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
// State Access
|
||||
@ -389,7 +396,14 @@ func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ec.c.EthSubscribe(ctx, ch, "logs", arg)
|
||||
sub, err := ec.c.EthSubscribe(ctx, ch, "logs", arg)
|
||||
if err != nil {
|
||||
// Defensively prefer returning nil interface explicitly on error-path, instead
|
||||
// of letting default golang behavior wrap it with non-nil interface that stores
|
||||
// nil concrete type value.
|
||||
return nil, err
|
||||
}
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user