wtxmgr/db: remove LatestVersion const in favor of getLatestVersion

In this commit, we can remove the LatestVersion constant as it's no
longer needed. Instead, we'll now define the latest version as the last
entry in the slice of versions previously defined.
This commit is contained in:
Wilmer Paulino 2018-11-02 18:43:09 -07:00
parent ec1213aeab
commit c523ccd192
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F

View file

@ -52,13 +52,6 @@ import (
// keys iterating in order. // keys iterating in order.
var byteOrder = binary.BigEndian var byteOrder = binary.BigEndian
// Database versions. Versions start at 1 and increment for each database
// change.
const (
// LatestVersion is the most recent store version.
LatestVersion = 1
)
// This package makes assumptions that the width of a chainhash.Hash is always // This package makes assumptions that the width of a chainhash.Hash is always
// 32 bytes. If this is ever changed (unlikely for bitcoin, possible for alts), // 32 bytes. If this is ever changed (unlikely for bitcoin, possible for alts),
// offsets have to be rewritten. Use a compile-time assertion that this // offsets have to be rewritten. Use a compile-time assertion that this
@ -1269,14 +1262,15 @@ func openStore(ns walletdb.ReadBucket) error {
return err return err
} }
if version < LatestVersion { latestVersion := getLatestVersion()
if version < latestVersion {
str := fmt.Sprintf("a database upgrade is required to upgrade "+ str := fmt.Sprintf("a database upgrade is required to upgrade "+
"wtxmgr from recorded version %d to the latest version %d", "wtxmgr from recorded version %d to the latest version %d",
version, LatestVersion) version, latestVersion)
return storeError(ErrNeedsUpgrade, str, nil) return storeError(ErrNeedsUpgrade, str, nil)
} }
if version > LatestVersion { if version > latestVersion {
str := fmt.Sprintf("version recorded version %d is newer that "+ str := fmt.Sprintf("version recorded version %d is newer that "+
"latest understood version %d", version, latestVersion) "latest understood version %d", version, latestVersion)
return storeError(ErrUnknownVersion, str, nil) return storeError(ErrUnknownVersion, str, nil)