github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/migrations/v5/migrate.go (about) 1 package v5 2 3 import ( 4 "context" 5 6 "github.com/cosmos/gogoproto/types" 7 8 "cosmossdk.io/collections" 9 storetypes "cosmossdk.io/core/store" 10 ) 11 12 var LegacyGlobalAccountNumberKey = []byte("globalAccountNumber") 13 14 func Migrate(ctx context.Context, storeService storetypes.KVStoreService, sequence collections.Sequence) error { 15 store := storeService.OpenKVStore(ctx) 16 b, err := store.Get(LegacyGlobalAccountNumberKey) 17 if err != nil { 18 return err 19 } 20 if b == nil { 21 // this would mean no account was ever created in this chain which is being migrated? 22 // we're doing nothing as the collections.Sequence already handles the non-existing value. 23 return nil 24 } 25 26 // get old value 27 v := new(types.UInt64Value) 28 err = v.Unmarshal(b) 29 if err != nil { 30 return err 31 } 32 33 // set the old value in the collection 34 err = sequence.Set(ctx, v.Value) 35 if err != nil { 36 return err 37 } 38 39 // remove the value from the old prefix. 40 err = store.Delete(LegacyGlobalAccountNumberKey) 41 if err != nil { 42 return err 43 } 44 45 return nil 46 }