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