Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions internal/common/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package common

import (
"fmt"
"io"
"net/http"
"regexp"
"strings"
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down