NewClient creates a client that uses the given RPC client.
( ctx context.Context, c *ethclient.Client, isHTTP bool, esContract common.Address, pollRate uint64, qh func() (*types.Header, error), lg log.Logger, )
| 68 | |
| 69 | // NewClient creates a client that uses the given RPC client. |
| 70 | func NewClient( |
| 71 | ctx context.Context, |
| 72 | c *ethclient.Client, |
| 73 | isHTTP bool, |
| 74 | esContract common.Address, |
| 75 | pollRate uint64, |
| 76 | qh func() (*types.Header, error), |
| 77 | lg log.Logger, |
| 78 | ) *PollingClient { |
| 79 | ctx, cancel := context.WithCancel(ctx) |
| 80 | networkID, err := c.NetworkID(ctx) |
| 81 | if err != nil { |
| 82 | lg.Crit("Failed to get network id", "err", err) |
| 83 | } |
| 84 | res := &PollingClient{ |
| 85 | Client: c, |
| 86 | isHTTP: isHTTP, |
| 87 | lg: lg, |
| 88 | pollRate: time.Duration(pollRate) * time.Second, |
| 89 | ctx: ctx, |
| 90 | cancel: cancel, |
| 91 | esContract: esContract, |
| 92 | pollReqCh: make(chan struct{}, 1), |
| 93 | subs: make(map[int]chan *types.Header), |
| 94 | closedCh: make(chan struct{}), |
| 95 | NetworkID: networkID, |
| 96 | } |
| 97 | if qh == nil { |
| 98 | res.queryHeader = res.getLatestHeader |
| 99 | } else { |
| 100 | res.queryHeader = qh |
| 101 | } |
| 102 | if isHTTP { |
| 103 | go res.pollHeads() |
| 104 | } |
| 105 | return res |
| 106 | } |
| 107 | |
| 108 | // Close closes the PollingClient and the underlying RPC client it talks to. |
| 109 | func (w *PollingClient) Close() { |
no test coverage detected