ethclient: add DialContext and Close #16318 (#1357)

This commit is contained in:
Daniel Liu 2025-08-20 14:36:52 +08:00 committed by GitHub
parent 71608abda8
commit df837a0c8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.