52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
|
package v046
|
||
|
|
||
|
import (
|
||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
v040 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v040"
|
||
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||
|
)
|
||
|
|
||
|
// migrateProposals migrates all legacy proposals into MsgExecLegacyContent
|
||
|
// proposals.
|
||
|
func migrateProposals(store sdk.KVStore, cdc codec.BinaryCodec) error {
|
||
|
propStore := prefix.NewStore(store, v040.ProposalsKeyPrefix)
|
||
|
|
||
|
iter := propStore.Iterator(nil, nil)
|
||
|
defer iter.Close()
|
||
|
|
||
|
for ; iter.Valid(); iter.Next() {
|
||
|
var oldProp v1beta1.Proposal
|
||
|
err := cdc.Unmarshal(iter.Value(), &oldProp)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
newProp, err := convertToNewProposal(oldProp)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
bz, err := cdc.Marshal(&newProp)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// Set new value on store.
|
||
|
propStore.Set(iter.Key(), bz)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// MigrateStore performs in-place store migrations from v0.43 to v0.46. The
|
||
|
// migration includes:
|
||
|
//
|
||
|
// - Migrate proposals to be Msg-based.
|
||
|
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
|
||
|
store := ctx.KVStore(storeKey)
|
||
|
|
||
|
return migrateProposals(store, cdc)
|
||
|
}
|