forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.go
48 lines (38 loc) · 1.05 KB
/
migrate.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
package v5
import (
"context"
"github.com/cosmos/gogoproto/types"
"cosmossdk.io/collections"
storetypes "cosmossdk.io/core/store"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
var LegacyGlobalAccountNumberKey = authtypes.LegacyGlobalAccountNumberKey
func Migrate(ctx context.Context, storeService storetypes.KVStoreService, sequence collections.Sequence) error {
store := storeService.OpenKVStore(ctx)
b, err := store.Get(LegacyGlobalAccountNumberKey)
if err != nil {
return err
}
if b == nil {
// this would mean no account was ever created in this chain which is being migrated?
// we're doing nothing as the collections.Sequence already handles the non-existing value.
return nil
}
// get old value
v := new(types.UInt64Value)
err = v.Unmarshal(b)
if err != nil {
return err
}
// set the old value in the collection
err = sequence.Set(ctx, v.Value)
if err != nil {
return err
}
// remove the value from the old prefix.
err = store.Delete(LegacyGlobalAccountNumberKey)
if err != nil {
return err
}
return nil
}