From 4f868d8d9407047893f89cfc35a34bf412de50c3 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Thu, 5 May 2022 14:58:47 +0300 Subject: [PATCH] fix: (pkg) revert to untrimmed address, panic on failed dial - TODO: cicnet should be initialized at job handler level --- pkg/cicnet/cicnet.go | 9 ++++++--- pkg/cicnet/token_index.go | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/cicnet/cicnet.go b/pkg/cicnet/cicnet.go index c91d37a..0161c64 100644 --- a/pkg/cicnet/cicnet.go +++ b/pkg/cicnet/cicnet.go @@ -10,13 +10,16 @@ type CicNet struct { tokenIndex common.Address } -func NewCicNet(rpcEndpoint string, tokenIndex common.Address) *CicNet { - ethClient := w3.MustDial(rpcEndpoint) +func NewCicNet(rpcEndpoint string, tokenIndex common.Address) (*CicNet, error) { + ethClient, err := w3.Dial(rpcEndpoint) + if err != nil { + return nil, err + } return &CicNet{ ethClient: ethClient, tokenIndex: tokenIndex, - } + }, nil } func (c *CicNet) Close() error { diff --git a/pkg/cicnet/token_index.go b/pkg/cicnet/token_index.go index 7d139cb..c598b42 100644 --- a/pkg/cicnet/token_index.go +++ b/pkg/cicnet/token_index.go @@ -6,7 +6,6 @@ import ( "github.com/lmittmann/w3" "github.com/lmittmann/w3/module/eth" "math/big" - "strings" ) func (c *CicNet) EntryCount(ctx context.Context) (big.Int, error) { @@ -34,6 +33,5 @@ func (c *CicNet) AddressAtIndex(ctx context.Context, index *big.Int) (string, er return "", err } - // strip 0x at pkg level - return strings.Trim(address.String(), "0x"), nil + return address.String(), nil }