erigon-pulse/common/sorted.go
Andrew Ashikhmin 0fc2022a0e
Extend fork ID to timestamp-based forks (#6324)
Starting from
[Shanghai](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md),
forks are based on timestamps rather than block heights (see PR #6238).
This PR extends [EIP-2124](https://eips.ethereum.org/EIPS/eip-2124) Fork
ID to include timestamp-based blocks. See also
https://github.com/ethereum/go-ethereum/pull/25878.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2022-12-16 12:08:54 +01:00

28 lines
475 B
Go

package common
import (
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
)
func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
keys := make([]K, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
slices.Sort(keys)
return keys
}
func RemoveDuplicatesFromSorted[T constraints.Ordered](slice []T) []T {
for i := 1; i < len(slice); i++ {
if slice[i] == slice[i-1] {
slice = append(slice[:i], slice[i+1:]...)
i--
}
}
return slice
}