2021-03-08 14:36:06 -08:00
|
|
|
package v043
|
2021-02-25 02:43:31 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/address"
|
2022-04-07 06:04:03 -07:00
|
|
|
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
|
2021-02-25 02:43:31 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// MigratePrefixAddress is a helper function that migrates all keys of format:
|
|
|
|
// prefix_bytes | address_bytes
|
|
|
|
// into format:
|
|
|
|
// prefix_bytes | address_len (1 byte) | address_bytes
|
|
|
|
func MigratePrefixAddress(store sdk.KVStore, prefixBz []byte) {
|
|
|
|
oldStore := prefix.NewStore(store, prefixBz)
|
|
|
|
|
|
|
|
oldStoreIter := oldStore.Iterator(nil, nil)
|
|
|
|
defer oldStoreIter.Close()
|
|
|
|
|
|
|
|
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
|
|
|
addr := oldStoreIter.Key()
|
2021-10-30 06:43:04 -07:00
|
|
|
var newStoreKey = prefixBz
|
2021-06-08 09:27:39 -07:00
|
|
|
newStoreKey = append(newStoreKey, address.MustLengthPrefix(addr)...)
|
2021-02-25 02:43:31 -08:00
|
|
|
|
|
|
|
// Set new key on store. Values don't change.
|
|
|
|
store.Set(newStoreKey, oldStoreIter.Value())
|
|
|
|
oldStore.Delete(oldStoreIter.Key())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MigratePrefixAddressBytes is a helper function that migrates all keys of format:
|
|
|
|
// prefix_bytes | address_bytes | arbitrary_bytes
|
|
|
|
// into format:
|
|
|
|
// prefix_bytes | address_len (1 byte) | address_bytes | arbitrary_bytes
|
|
|
|
func MigratePrefixAddressBytes(store sdk.KVStore, prefixBz []byte) {
|
|
|
|
oldStore := prefix.NewStore(store, prefixBz)
|
|
|
|
|
|
|
|
oldStoreIter := oldStore.Iterator(nil, nil)
|
|
|
|
defer oldStoreIter.Close()
|
|
|
|
|
|
|
|
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
2022-04-07 06:04:03 -07:00
|
|
|
addr := oldStoreIter.Key()[:v042auth.AddrLen]
|
|
|
|
endBz := oldStoreIter.Key()[v042auth.AddrLen:]
|
2021-02-25 02:43:31 -08:00
|
|
|
newStoreKey := append(append(prefixBz, address.MustLengthPrefix(addr)...), endBz...)
|
|
|
|
|
|
|
|
// Set new key on store. Values don't change.
|
|
|
|
store.Set(newStoreKey, oldStoreIter.Value())
|
|
|
|
oldStore.Delete(oldStoreIter.Key())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MigratePrefixAddressAddress is a helper function that migrates all keys of format:
|
|
|
|
// prefix_bytes | address_1_bytes | address_2_bytes
|
|
|
|
// into format:
|
|
|
|
// prefix_bytes | address_1_len (1 byte) | address_1_bytes | address_2_len (1 byte) | address_2_bytes
|
|
|
|
func MigratePrefixAddressAddress(store sdk.KVStore, prefixBz []byte) {
|
|
|
|
oldStore := prefix.NewStore(store, prefixBz)
|
|
|
|
|
|
|
|
oldStoreIter := oldStore.Iterator(nil, nil)
|
|
|
|
defer oldStoreIter.Close()
|
|
|
|
|
|
|
|
for ; oldStoreIter.Valid(); oldStoreIter.Next() {
|
2022-04-07 06:04:03 -07:00
|
|
|
addr1 := oldStoreIter.Key()[:v042auth.AddrLen]
|
|
|
|
addr2 := oldStoreIter.Key()[v042auth.AddrLen:]
|
2021-02-25 02:43:31 -08:00
|
|
|
newStoreKey := append(append(prefixBz, address.MustLengthPrefix(addr1)...), address.MustLengthPrefix(addr2)...)
|
|
|
|
|
|
|
|
// Set new key on store. Values don't change.
|
|
|
|
store.Set(newStoreKey, oldStoreIter.Value())
|
|
|
|
oldStore.Delete(oldStoreIter.Key())
|
|
|
|
}
|
|
|
|
}
|