diff --git a/internal/common/abi.go b/internal/common/abi.go index 825a06f..0394aff 100644 --- a/internal/common/abi.go +++ b/internal/common/abi.go @@ -2,7 +2,6 @@ package common import ( "fmt" - "io" "net/http" "regexp" "strings" @@ -12,13 +11,11 @@ import ( config "github.com/thirdweb-dev/indexer/configs" "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/rs/zerolog/log" ) var ( - httpClient *http.Client - httpClientOnce sync.Once - jsonDecodeMutex sync.Mutex + httpClient *http.Client + httpClientOnce sync.Once ) func getHTTPClient() *http.Client { @@ -69,23 +66,11 @@ func GetABIForContract(chainId string, contract string) (*abi.ABI, error) { return nil, fmt.Errorf("failed to get contract abi: unexpected status code %d", resp.StatusCode) } - // Read the entire response body - body, err := io.ReadAll(resp.Body) + abi, err := abi.JSON(resp.Body) if err != nil { - return nil, fmt.Errorf("failed to read contract abi response: %v", err) - } - - // Protect JSON decoding with a mutex - jsonDecodeMutex.Lock() - defer jsonDecodeMutex.Unlock() - - // Parse the ABI - parsedABI, err := abi.JSON(strings.NewReader(string(body))) - if err != nil { - log.Warn().Err(err).Str("contract", contract).Str("chainId", chainId).Msg("Failed to parse contract ABI") return nil, fmt.Errorf("failed to load contract abi: %v", err) } - return &parsedABI, nil + return &abi, nil } func ConstructEventABI(signature string) (*abi.Event, error) {