@@ -2,9 +2,11 @@ package app
22
33import (
44 "context"
5+ "fmt"
6+ "strings"
7+
58 storetypes "cosmossdk.io/store/types"
69 upgradetypes "cosmossdk.io/x/upgrade/types"
7- "fmt"
810 sdk "github.com/cosmos/cosmos-sdk/types"
911 m "github.com/cosmos/cosmos-sdk/types/module"
1012 "github.com/cosmos/cosmos-sdk/version"
@@ -16,7 +18,38 @@ const (
1618
1719// generate upgrade version from the current version (v999999.999999.999999 => v999999)
1820func generateUpgradeVersion () string {
19- return "v6.5"
21+ currentVersion := version .Version
22+ // if current version empty then override it with localnet version
23+ if currentVersion == "v" {
24+ currentVersion = "v999999.999999.999999"
25+ }
26+ parts := strings .Split (currentVersion , "." )
27+ // Needed for devnet
28+ if len (parts ) == 1 {
29+ return currentVersion
30+ }
31+ if len (parts ) != 3 {
32+ panic (fmt .Sprintf ("Invalid version format: %s. Expected format: vX.Y.Z" , currentVersion ))
33+ }
34+ majorVersion := strings .TrimPrefix (parts [0 ], "v" )
35+ minorVersion := parts [1 ]
36+ // required for testnet
37+ patchParts := strings .Split (parts [2 ], "-" )
38+ rcVersion := ""
39+ if len (patchParts ) > 1 {
40+ rcVersion = strings .Join (patchParts [1 :], "-" )
41+ }
42+ // testnet
43+ if rcVersion != "" {
44+ if minorVersion != "0" && minorVersion != "999999" {
45+ return fmt .Sprintf ("v%s.%s-%s" , majorVersion , minorVersion , rcVersion )
46+ }
47+ return fmt .Sprintf ("v%s-%s" , majorVersion , rcVersion )
48+ }
49+ if minorVersion != "0" && minorVersion != "999999" {
50+ return fmt .Sprintf ("v%s.%s" , majorVersion , parts [1 ])
51+ }
52+ return fmt .Sprintf ("v%s" , majorVersion )
2053}
2154
2255func (app * ElysApp ) setUpgradeHandler () {
0 commit comments