From 907c9ae55ebb38e7aa1f2612dcc1d7f26decf9ce Mon Sep 17 00:00:00 2001 From: David Muthy Date: Fri, 24 Jan 2025 13:32:05 +0800 Subject: [PATCH] refactor: using slices.Contains to simplify the code (#13544) This is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains) added in the go1.21 standard library, which can make the code more concise and easy to read. Signed-off-by: damuzhi0810 --- erigon-lib/chain/networkname/network_name.go | 9 --------- erigon-lib/downloader/downloadercfg/downloadercfg.go | 3 ++- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/erigon-lib/chain/networkname/network_name.go b/erigon-lib/chain/networkname/network_name.go index 3d03ffc984a..a1a675f9113 100644 --- a/erigon-lib/chain/networkname/network_name.go +++ b/erigon-lib/chain/networkname/network_name.go @@ -41,12 +41,3 @@ var All = []string{ Chiado, Test, } - -func IsKnownNetwork(s string) bool { - for _, n := range All { - if n == s { - return true - } - } - return false -} diff --git a/erigon-lib/downloader/downloadercfg/downloadercfg.go b/erigon-lib/downloader/downloadercfg/downloadercfg.go index b52f29c4ffb..43a7666fff0 100644 --- a/erigon-lib/downloader/downloadercfg/downloadercfg.go +++ b/erigon-lib/downloader/downloadercfg/downloadercfg.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "strings" "time" @@ -240,7 +241,7 @@ func New(ctx context.Context, dirs datadir.Dirs, version string, verbosity lg.Le // LoadSnapshotsHashes checks local preverified.toml. If file exists, used local hashes. // If there are no such file, try to fetch hashes from the web and create local file. func LoadSnapshotsHashes(ctx context.Context, dirs datadir.Dirs, chainName string) (*snapcfg.Cfg, error) { - if !networkname.IsKnownNetwork(chainName) { + if !slices.Contains(networkname.All, chainName) { log.Root().Warn("No snapshot hashes for chain", "chain", chainName) return snapcfg.NewNonSeededCfg(chainName), nil }