From cbabb84560c62c9d2336d31a78b7387780a7b887 Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Wed, 14 Mar 2018 21:40:26 +0100 Subject: [PATCH 1/3] ethclient: add DialContext function Allows users to pass a Context object for cancellation. --- ethclient/ethclient.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 87a912901af5..e065972cbc57 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -46,6 +46,14 @@ func Dial(rawurl string) (*Client, error) { return NewClient(c), nil } +func DialContext(ctx context.Context, rawurl string) (*Client, error) { + c, err := rpc.DialContext(ctx, rawurl) + if err != nil { + return nil, err + } + return NewClient(c), nil +} + // NewClient creates a client that uses the given RPC client. func NewClient(c *rpc.Client) *Client { return &Client{c} From ea4ced5bb02e9d25b59b5221f29ee94bbe880c79 Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Wed, 14 Mar 2018 21:42:13 +0100 Subject: [PATCH 2/3] ethclient: implement Dial in terms of DialContext --- ethclient/ethclient.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index e065972cbc57..8daf982f3cbe 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -39,11 +39,7 @@ type Client struct { // Dial connects a client to the given URL. func Dial(rawurl string) (*Client, error) { - c, err := rpc.Dial(rawurl) - if err != nil { - return nil, err - } - return NewClient(c), nil + return DialContext(context.Background(), rawurl) } func DialContext(ctx context.Context, rawurl string) (*Client, error) { From cbe882a20ed8aa708845bf806315772701b12c59 Mon Sep 17 00:00:00 2001 From: Lorenzo Manacorda Date: Wed, 14 Mar 2018 21:45:37 +0100 Subject: [PATCH 3/3] ethclient: add Close method Closes the underlying RPC connection. --- ethclient/ethclient.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 8daf982f3cbe..31047fc20af4 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -55,6 +55,10 @@ func NewClient(c *rpc.Client) *Client { return &Client{c} } +func (ec *Client) Close() { + ec.c.Close() +} + // Blockchain Access // BlockByHash returns the given full block.