-
Notifications
You must be signed in to change notification settings - Fork 1
/
v8_to_v9.go
38 lines (33 loc) · 1.12 KB
/
v8_to_v9.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
package migrations
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/fibonacci-chain/core/x/dex/keeper"
"github.com/fibonacci-chain/core/x/dex/types"
)
func V8ToV9(ctx sdk.Context, dexkeeper keeper.Keeper) error {
dexkeeper.CreateModuleAccount(ctx)
contractStore := prefix.NewStore(ctx.KVStore(dexkeeper.GetStoreKey()), []byte(keeper.ContractPrefixKey))
iterator := sdk.KVStorePrefixIterator(contractStore, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
contract := types.ContractInfo{}
if err := contract.Unmarshal(iterator.Value()); err != nil {
return err
}
contractV2 := types.ContractInfoV2{
CodeId: contract.CodeId,
ContractAddr: contract.ContractAddr,
NeedHook: contract.NeedHook,
NeedOrderMatching: contract.NeedOrderMatching,
Dependencies: contract.Dependencies,
NumIncomingDependencies: contract.NumIncomingDependencies,
}
bz, err := contractV2.Marshal()
if err != nil {
return err
}
contractStore.Set(iterator.Key(), bz)
}
return nil
}