github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/native/client/ethclient.go (about)

     1  package native
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/unicornultrafoundation/go-u2u/ethclient"
     7  	"github.com/unicornultrafoundation/go-u2u/rpc"
     8  )
     9  
    10  // Client extends Ethereum API client with typed wrappers for the Backend API.
    11  type Client struct {
    12  	ethclient.Client
    13  	c *rpc.Client
    14  }
    15  
    16  // Dial connects a client to the given URL.
    17  func Dial(rawurl string) (*Client, error) {
    18  	return DialContext(context.Background(), rawurl)
    19  }
    20  
    21  func DialContext(ctx context.Context, rawurl string) (*Client, error) {
    22  	c, err := rpc.DialContext(ctx, rawurl)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return NewClient(c), nil
    27  }
    28  
    29  // NewClient creates a client that uses the given RPC client.
    30  func NewClient(c *rpc.Client) *Client {
    31  	return &Client{
    32  		Client: *ethclient.NewClient(c),
    33  		c:      c,
    34  	}
    35  }