Skip to content

Commit a8249dd

Browse files
committed
clean-up
1 parent 0f9b2ab commit a8249dd

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

ethreceipts/ethreceipts_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func TestFetchTransactionReceiptBasic(t *testing.T) {
111111
provider := testchain.Provider
112112

113113
monitorOptions := ethmonitor.DefaultOptions
114-
monitorOptions.StartBlockNumber = big.NewInt(1)
115114
monitorOptions.Logger = log
116115
monitorOptions.WithLogs = true
117116
monitorOptions.BlockRetentionLimit = 1000

ethreceipts/subscription.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ func (s *subscriber) retryPendingReceipts(ctx context.Context) {
331331
s.retryMu.Unlock()
332332

333333
if len(toRetry) == 0 {
334-
s.listener.log.Debug("ethreceipts: no pending receipts to retry")
335334
return
336335
}
337336

ethrpc/ethrpc.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import (
2626
)
2727

2828
type Provider struct {
29-
log *slog.Logger // TODO: not used..
30-
nodeURL string
31-
nodeWSURL string
32-
httpClient httpClient
29+
log *slog.Logger // TODO: not used..
30+
nodeURL string
31+
nodeWSURL string
32+
33+
httpClient atomic.Value // stores an object that satisfies the httpClient interface
34+
3335
br breaker.Breaker
3436
jwtToken string // optional
3537
streamClosers []StreamCloser
@@ -56,7 +58,7 @@ func NewProvider(nodeURL string, options ...Option) (*Provider, error) {
5658
opt(p)
5759
}
5860

59-
if p.httpClient == nil {
61+
if p.httpClient.Load() == nil {
6062
httpTransport := &http.Transport{
6163
Proxy: http.ProxyFromEnvironment,
6264
DialContext: (&net.Dialer{
@@ -72,11 +74,11 @@ func NewProvider(nodeURL string, options ...Option) (*Provider, error) {
7274
ExpectContinueTimeout: 1 * time.Second,
7375
ResponseHeaderTimeout: 30 * time.Second,
7476
}
75-
httpClient := &http.Client{
77+
client := &http.Client{
7678
Transport: httpTransport,
7779
Timeout: 35 * time.Second,
7880
}
79-
p.httpClient = httpClient
81+
p.httpClient.Store(client)
8082
}
8183

8284
return p, nil
@@ -106,8 +108,12 @@ type StreamUnsubscriber interface {
106108
Unsubscribe()
107109
}
108110

109-
func (s *Provider) SetHTTPClient(httpClient *http.Client) {
110-
s.httpClient = httpClient
111+
func (s *Provider) SetHTTPClient(client httpClient) {
112+
s.httpClient.Store(client)
113+
}
114+
115+
func (p *Provider) getHTTPClient() httpClient {
116+
return p.httpClient.Load().(httpClient)
111117
}
112118

113119
func (p *Provider) StrictnessLevel() StrictnessLevel {
@@ -147,7 +153,8 @@ func (p *Provider) Do(ctx context.Context, calls ...Call) ([]byte, error) {
147153
req.Header.Set("Authorization", fmt.Sprintf("BEARER %s", p.jwtToken))
148154
}
149155

150-
res, err := p.httpClient.Do(req)
156+
httpClient := p.getHTTPClient()
157+
res, err := httpClient.Do(req)
151158
if err != nil {
152159
return nil, superr.Wrap(ErrRequestFail, fmt.Errorf("failed to send request: %w", err))
153160
}

ethrpc/option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func WithStreaming(nodeWebsocketURL string) Option {
2525

2626
func WithHTTPClient(c httpClient) Option {
2727
return func(p *Provider) {
28-
p.httpClient = c
28+
p.SetHTTPClient(c)
2929
}
3030
}
3131

0 commit comments

Comments
 (0)