-
Notifications
You must be signed in to change notification settings - Fork 29
/
store.go
39 lines (30 loc) · 934 Bytes
/
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
package v2
import (
"fmt"
"github.com/Finschia/finschia-sdk/codec"
storetypes "github.com/Finschia/finschia-sdk/store/types"
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/foundation"
)
// MigrateStore performs in-place store migrations from v1 to v2.
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, subspace Subspace) error {
store := ctx.KVStore(storeKey)
// migrate params
if err := migrateParams(ctx, store, cdc, subspace); err != nil {
return err
}
return nil
}
func migrateParams(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec, subspace Subspace) error {
bz := store.Get(ParamsKey)
if bz == nil {
return fmt.Errorf("params not found")
}
store.Delete(ParamsKey)
var params foundation.Params
if err := cdc.Unmarshal(bz, ¶ms); err != nil {
return err
}
subspace.SetParamSet(ctx, ¶ms)
return nil
}