mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/era: simplify clauses
This commit is contained in:
parent
235d413c2f
commit
1000755740
1 changed files with 15 additions and 15 deletions
|
|
@ -53,6 +53,7 @@ func Filename(network string, epoch int, root common.Hash) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadDir reads all the era1 files in a directory for a given network.
|
// ReadDir reads all the era1 files in a directory for a given network.
|
||||||
|
// Format: <network>-<epoch>-<hexroot>.era1
|
||||||
func ReadDir(dir, network string) ([]string, error) {
|
func ReadDir(dir, network string) ([]string, error) {
|
||||||
entries, err := os.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -63,14 +64,15 @@ func ReadDir(dir, network string) ([]string, error) {
|
||||||
eras []string
|
eras []string
|
||||||
)
|
)
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
if path.Ext(entry.Name()) == ".era1" {
|
if path.Ext(entry.Name()) != ".era1" {
|
||||||
n := strings.Split(entry.Name(), "-")
|
continue
|
||||||
if len(n) != 3 {
|
}
|
||||||
|
parts := strings.Split(entry.Name(), "-")
|
||||||
|
if len(parts) != 3 || parts[0] != network {
|
||||||
// invalid era1 filename, skip
|
// invalid era1 filename, skip
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if n[0] == network {
|
if epoch, err := strconv.ParseUint(parts[1], 10, 64); err != nil {
|
||||||
if epoch, err := strconv.ParseUint(n[1], 10, 64); err != nil {
|
|
||||||
return nil, fmt.Errorf("malformed era1 filename: %s", entry.Name())
|
return nil, fmt.Errorf("malformed era1 filename: %s", entry.Name())
|
||||||
} else if epoch != next {
|
} else if epoch != next {
|
||||||
return nil, fmt.Errorf("missing epoch %d", next)
|
return nil, fmt.Errorf("missing epoch %d", next)
|
||||||
|
|
@ -78,8 +80,6 @@ func ReadDir(dir, network string) ([]string, error) {
|
||||||
next += 1
|
next += 1
|
||||||
eras = append(eras, entry.Name())
|
eras = append(eras, entry.Name())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return eras, nil
|
return eras, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue