Skip to content

Commit

Permalink
feat: use a custom HTTP client for the RPC provider
Browse files Browse the repository at this point in the history
* sla set to 5 seconds
  • Loading branch information
kamikazechaser committed Mar 25, 2024
1 parent d8b99a9 commit 80067cc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package celoutils

import (
"math/big"
"net/http"
"time"

"github.com/celo-org/celo-blockchain/core/types"
"github.com/celo-org/celo-blockchain/rpc"
"github.com/grassrootseconomics/w3-celo"
)

const (
slaTimeout = 5 * time.Second

MainnetChainId int64 = 42220
TestnetChainId int64 = 44787
)
Expand All @@ -24,14 +29,20 @@ type Provider struct {
}

func NewProvider(o ProviderOpts) (*Provider, error) {
client, err := w3.Dial(o.RpcEndpoint)
rpcClient, err := rpc.DialHTTPWithClient(o.RpcEndpoint, customHTTPClient())
if err != nil {
return nil, err
}

return &Provider{
ChainId: o.ChainId,
Client: client,
Client: w3.NewClient(rpcClient),
Signer: types.NewLondonSigner(big.NewInt(o.ChainId)),
}, nil
}

func customHTTPClient() *http.Client {
return &http.Client{
Timeout: slaTimeout,
}
}

0 comments on commit 80067cc

Please sign in to comment.