github.com/cosmos/cosmos-sdk@v0.50.10/x/gov/migrations/v5/store.go (about) 1 package v5 2 3 import ( 4 "cosmossdk.io/collections" 5 corestoretypes "cosmossdk.io/core/store" 6 7 "github.com/cosmos/cosmos-sdk/codec" 8 sdk "github.com/cosmos/cosmos-sdk/types" 9 v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" 10 govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" 11 ) 12 13 var ( 14 // ParamsKey is the key of x/gov params 15 ParamsKey = []byte{0x30} 16 // ConstitutionKey is the key of x/gov constitution 17 ConstitutionKey = collections.NewPrefix(49) 18 ) 19 20 // MigrateStore performs in-place store migrations from v4 (v0.47) to v5 (v0.50). The 21 // migration includes: 22 // 23 // Addition of the new proposal expedited parameters that are set to 0 by default. 24 // Set of default chain constitution. 25 func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec, constitutionCollection collections.Item[string]) error { 26 store := storeService.OpenKVStore(ctx) 27 paramsBz, err := store.Get(v4.ParamsKey) 28 if err != nil { 29 return err 30 } 31 32 var params govv1.Params 33 err = cdc.Unmarshal(paramsBz, ¶ms) 34 if err != nil { 35 return err 36 } 37 38 defaultParams := govv1.DefaultParams() 39 params.ExpeditedMinDeposit = defaultParams.ExpeditedMinDeposit 40 params.ExpeditedVotingPeriod = defaultParams.ExpeditedVotingPeriod 41 params.ExpeditedThreshold = defaultParams.ExpeditedThreshold 42 params.ProposalCancelRatio = defaultParams.ProposalCancelRatio 43 params.ProposalCancelDest = defaultParams.ProposalCancelDest 44 params.MinDepositRatio = defaultParams.MinDepositRatio 45 46 bz, err := cdc.Marshal(¶ms) 47 if err != nil { 48 return err 49 } 50 51 if err := store.Set(ParamsKey, bz); err != nil { 52 return err 53 } 54 55 // Set the default consisitution if it is not set 56 if ok, err := constitutionCollection.Has(ctx); !ok || err != nil { 57 if err := constitutionCollection.Set(ctx, "This chain has no constitution."); err != nil { 58 return err 59 } 60 } 61 62 return nil 63 }