From df837a0c8bbf77c5c2eeafd590f827f7214b8a0c Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 20 Aug 2025 14:36:52 +0800 Subject: [PATCH] ethclient: add DialContext and Close #16318 (#1357) --- ethclient/ethclient.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 2cbfb0684e..0e918b8bcd 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -39,7 +39,12 @@ type Client struct { // Dial connects a client to the given URL. func Dial(rawurl string) (*Client, error) { - c, err := rpc.Dial(rawurl) + return DialContext(context.Background(), rawurl) +} + +// DialContext connects a client to the given URL with context. +func DialContext(ctx context.Context, rawurl string) (*Client, error) { + c, err := rpc.DialContext(ctx, rawurl) if err != nil { return nil, err } @@ -51,6 +56,11 @@ func NewClient(c *rpc.Client) *Client { return &Client{c} } +// Close closes the underlying RPC connection. +func (ec *Client) Close() { + ec.c.Close() +} + // Blockchain Access // BlockByHash returns the given full block.