Skip to content

Commit

Permalink
add http error handling and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jterzis committed Sep 8, 2024
1 parent 8762fd7 commit caf96b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions scripts/bytecode-diff/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ func executeEnvrionmentDiff(
originFacets := make(map[string][]utils.Facet)

for diamondName, diamondAddress := range originDiamonds {
if verbose {
log.Info().
Str("diamondName", fmt.Sprintf("%s", diamondName)).
Str("diamondAddress", diamondAddress).
Msg("Origin Diamond Address")
}
facets, err := utils.ReadAllFacets(clients[originEnvironment], diamondAddress, baseConfig.BasescanAPIKey)
if err != nil {
log.Error().Err(err).Msgf("Error reading all facets for origin diamond %s", diamondName)
Expand Down
11 changes: 9 additions & 2 deletions scripts/bytecode-diff/utils/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type Facet struct {
FacetAddress common.Address
Selectors [][4]byte `json:",omitempty"`
SelectorsHex []string ` abi:"-"`
SelectorsHex []string `abi:"-"`
ContractName string `json:",omitempty"`
BytecodeHash string `json:",omitempty"`
}
Expand Down Expand Up @@ -132,7 +132,10 @@ func ReadAllFacets(client *ethclient.Client, contractAddress string, basescanAPI
}

func CreateEthereumClients(
baseRpcUrl, baseSepoliaRpcUrl, originEnvironment, targetEnvironment string,
baseRpcUrl string,
baseSepoliaRpcUrl string,
originEnvironment string,
targetEnvironment string,
verbose bool,
) (map[string]*ethclient.Client, error) {
clients := make(map[string]*ethclient.Client)
Expand Down Expand Up @@ -187,6 +190,10 @@ func GetContractNameFromBasescan(baseURL, address, apiKey string) (string, error
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("Basescan API returned non-200 status code: %d", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %w", err)
Expand Down

0 comments on commit caf96b2

Please sign in to comment.