MCPcopy Create free account
hub / github.com/ethstorage/es-node / NewClient

Function NewClient

ethstorage/eth/polling_client.go:70–106  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

68
69// NewClient creates a client that uses the given RPC client.
70func 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.
109func (w *PollingClient) Close() {

Callers 2

DialContextFunction · 0.85
DialRandaoSourceFunction · 0.85

Calls 1

pollHeadsMethod · 0.95

Tested by

no test coverage detected