Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
awskii committed Oct 22, 2024
1 parent ce27540 commit 395701a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getURLByChain(chain string) string {
return fmt.Sprintf("https://raw.githubusercontent.com/erigontech/erigon-snapshot/%s/%s.toml", branchReference, chain)
}

func LoadSnapshots() (couldFetch bool) {
func LoadSnapshots() (fetched bool, err error) {
var (
mainnetUrl = getURLByChain("mainnet")
sepoliaUrl = getURLByChain("sepolia")
Expand All @@ -56,52 +56,51 @@ func LoadSnapshots() (couldFetch bool) {
holeskyUrl = getURLByChain("holesky")
)
var hashes []byte
var err error
// Try to fetch the latest snapshot hashes from the web
if hashes, err = fetchSnapshotHashes(mainnetUrl); err != nil {
couldFetch = false
fetched = false
return
}
Mainnet = hashes

if hashes, err = fetchSnapshotHashes(sepoliaUrl); err != nil {
couldFetch = false
fetched = false
return
}
Sepolia = hashes

if hashes, err = fetchSnapshotHashes(amoyUrl); err != nil {
couldFetch = false
fetched = false
return
}
Amoy = hashes

if hashes, err = fetchSnapshotHashes(borMainnetUrl); err != nil {
couldFetch = false
fetched = false
return
}
BorMainnet = hashes

if hashes, err = fetchSnapshotHashes(gnosisUrl); err != nil {
couldFetch = false
fetched = false
return
}
Gnosis = hashes

if hashes, err = fetchSnapshotHashes(chiadoUrl); err != nil {
couldFetch = false
fetched = false
return
}
Chiado = hashes

if hashes, err = fetchSnapshotHashes(holeskyUrl); err != nil {
couldFetch = false
fetched = false
return
}
Holesky = hashes

couldFetch = true
return
fetched = true
return fetched, nil
}

func fetchSnapshotHashes(url string) ([]byte, error) {
Expand All @@ -110,6 +109,9 @@ func fetchSnapshotHashes(url string) ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to fetch snapshot hashes by %q: status code %d %s", url, resp.StatusCode, resp.Status)
}
res, err := io.ReadAll(resp.Body)
if len(res) == 0 {
return nil, fmt.Errorf("empty response from %s", url)
Expand Down

0 comments on commit 395701a

Please sign in to comment.