2021-07-29 11:44:53 +00:00
|
|
|
package common
|
|
|
|
|
2021-11-09 10:55:21 +00:00
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
|
|
|
|
2021-07-29 11:44:53 +00:00
|
|
|
const (
|
|
|
|
major = 0
|
2024-09-30 09:37:12 +00:00
|
|
|
minor = 20
|
|
|
|
patch = 0
|
2021-11-09 10:55:21 +00:00
|
|
|
|
|
|
|
// Versions from which an update should be performed.
|
|
|
|
// These should be used in a group (so prevMinor can be equal to minor if there are
|
|
|
|
// any migration routines.
|
|
|
|
prevMajor = 0
|
2024-09-30 09:37:12 +00:00
|
|
|
prevMinor = 19
|
|
|
|
prevPatch = 3
|
2021-07-29 11:44:53 +00:00
|
|
|
|
|
|
|
Version = major*1_000_000 + minor*1_000 + patch
|
2021-11-09 10:55:21 +00:00
|
|
|
|
|
|
|
PrevVersion = prevMajor*1_000_000 + prevMinor*1_000 + prevPatch
|
|
|
|
|
|
|
|
// ErrVersionMismatch is thrown by CheckVersion in case of error.
|
|
|
|
ErrVersionMismatch = "previous version mismatch"
|
|
|
|
|
|
|
|
// ErrAlreadyUpdated is thrown by CheckVersion if current version equals to version contract
|
|
|
|
// is being updated from.
|
|
|
|
ErrAlreadyUpdated = "contract is already of the latest version"
|
2021-07-29 11:44:53 +00:00
|
|
|
)
|
2021-11-09 10:55:21 +00:00
|
|
|
|
|
|
|
// CheckVersion checks that previous version is more than PrevVersion to ensure migrating contract data
|
|
|
|
// was done successfully.
|
|
|
|
func CheckVersion(from int) {
|
|
|
|
if from < PrevVersion {
|
|
|
|
panic(ErrVersionMismatch + ": expected >=" + std.Itoa(PrevVersion, 10))
|
|
|
|
}
|
2024-08-19 08:52:01 +00:00
|
|
|
if Version <= from {
|
2021-11-09 10:55:21 +00:00
|
|
|
panic(ErrAlreadyUpdated + ": " + std.Itoa(Version, 10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendVersion appends current contract version to the list of deploy arguments.
|
2023-11-07 12:18:48 +00:00
|
|
|
func AppendVersion(data any) []interface{} {
|
2021-11-09 10:55:21 +00:00
|
|
|
if data == nil {
|
2023-11-07 12:18:48 +00:00
|
|
|
return []any{Version}
|
2021-11-09 10:55:21 +00:00
|
|
|
}
|
2023-11-07 12:18:48 +00:00
|
|
|
return append(data.([]any), Version)
|
2021-11-09 10:55:21 +00:00
|
|
|
}
|