2022-05-06 12:19:17 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
//go:generate stringer -type=Hardfork -linecomment
|
|
|
|
|
|
|
|
// Hardfork represents the application hard-fork identifier.
|
|
|
|
type Hardfork byte
|
|
|
|
|
2024-04-08 11:29:44 +00:00
|
|
|
// HFDefault is a default value of Hardfork enum. It's a special constant
|
|
|
|
// aimed to denote the node code enabled by default starting from the
|
|
|
|
// genesis block. HFDefault is not a hard-fork, but this constant can be used for
|
|
|
|
// convenient hard-forks comparison and to refer to the default hard-fork-less
|
|
|
|
// node behaviour.
|
|
|
|
const HFDefault Hardfork = 0 // Default
|
|
|
|
|
2022-05-06 12:19:17 +00:00
|
|
|
const (
|
2022-05-26 11:04:23 +00:00
|
|
|
// HFAspidochelone represents hard-fork introduced in #2469 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2712) and #2519 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2749).
|
2022-06-03 08:38:03 +00:00
|
|
|
HFAspidochelone Hardfork = 1 << iota // Aspidochelone
|
2023-08-03 16:48:55 +00:00
|
|
|
// HFBasilisk represents hard-fork introduced in #3056 (ported from
|
2023-08-10 11:05:32 +00:00
|
|
|
// https://github.com/neo-project/neo/pull/2881), #3080 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2883) and #3085 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2810).
|
2023-08-03 16:48:55 +00:00
|
|
|
HFBasilisk // Basilisk
|
2024-04-08 16:19:34 +00:00
|
|
|
// HFCockatrice represents hard-fork introduced in #3402 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2942), #3301 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/2925) and #3362 (ported from
|
|
|
|
// https://github.com/neo-project/neo/pull/3154).
|
|
|
|
HFCockatrice // Cockatrice
|
2023-08-24 16:24:34 +00:00
|
|
|
// hfLast denotes the end of hardforks enum. Consider adding new hardforks
|
|
|
|
// before hfLast.
|
|
|
|
hfLast
|
2022-05-06 12:19:17 +00:00
|
|
|
)
|
|
|
|
|
2023-08-24 16:24:34 +00:00
|
|
|
// Hardforks represents the ordered slice of all possible hardforks.
|
|
|
|
var Hardforks []Hardfork
|
|
|
|
|
2022-05-06 12:19:17 +00:00
|
|
|
// hardforks holds a map of Hardfork string representation to its type.
|
|
|
|
var hardforks map[string]Hardfork
|
|
|
|
|
|
|
|
func init() {
|
2023-08-24 16:24:34 +00:00
|
|
|
for i := HFAspidochelone; i < hfLast; i = i << 1 {
|
|
|
|
Hardforks = append(Hardforks, i)
|
|
|
|
}
|
|
|
|
hardforks = make(map[string]Hardfork, len(Hardforks))
|
|
|
|
for _, hf := range Hardforks {
|
2022-05-06 12:19:17 +00:00
|
|
|
hardforks[hf.String()] = hf
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-27 17:48:14 +00:00
|
|
|
// Cmp returns the result of hardforks comparison. It returns:
|
|
|
|
//
|
|
|
|
// -1 if hf < other
|
|
|
|
// 0 if hf == other
|
|
|
|
// +1 if hf > other
|
|
|
|
func (hf Hardfork) Cmp(other Hardfork) int {
|
|
|
|
switch {
|
|
|
|
case hf == other:
|
|
|
|
return 0
|
|
|
|
case hf < other:
|
|
|
|
return -1
|
|
|
|
default:
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 11:29:44 +00:00
|
|
|
// Prev returns the previous hardfork for the given one. Calling Prev for the default hardfork is a no-op.
|
|
|
|
func (hf Hardfork) Prev() Hardfork {
|
|
|
|
if hf == HFDefault {
|
|
|
|
panic("unexpected call to Prev for the default hardfork")
|
|
|
|
}
|
|
|
|
return hf >> 1
|
|
|
|
}
|
|
|
|
|
2022-05-06 12:19:17 +00:00
|
|
|
// IsHardforkValid denotes whether the provided string represents a valid
|
|
|
|
// Hardfork name.
|
|
|
|
func IsHardforkValid(s string) bool {
|
|
|
|
_, ok := hardforks[s]
|
|
|
|
return ok
|
|
|
|
}
|
2024-03-27 17:48:14 +00:00
|
|
|
|
|
|
|
// LatestHardfork returns latest known hardfork.
|
|
|
|
func LatestHardfork() Hardfork {
|
|
|
|
return hfLast >> 1
|
|
|
|
}
|