From 80067cc4575e2f50bf397341058ccd09f2ef44bc Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Mon, 25 Mar 2024 17:30:02 +0800 Subject: [PATCH] feat: use a custom HTTP client for the RPC provider * sla set to 5 seconds --- provider.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/provider.go b/provider.go index 3e764ab..054a301 100644 --- a/provider.go +++ b/provider.go @@ -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 ) @@ -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, + } +}