Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
98 lines
2.5 KiB
Go
98 lines
2.5 KiB
Go
package v3
|
|
|
|
import (
|
|
corestoretypes "cosmossdk.io/core/store"
|
|
"cosmossdk.io/store/prefix"
|
|
storetypes "cosmossdk.io/store/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/runtime"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1"
|
|
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
)
|
|
|
|
// migrateProposals migrates all legacy proposals into MsgExecLegacyContent
|
|
// proposals.
|
|
func migrateProposals(store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
|
propStore := prefix.NewStore(store, v1.ProposalsKeyPrefix)
|
|
|
|
iter := propStore.Iterator(nil, nil)
|
|
defer iter.Close()
|
|
|
|
for ; iter.Valid(); iter.Next() {
|
|
var oldProp govv1beta1.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
|
|
}
|
|
|
|
// migrateVotes migrates all v1beta1 weighted votes (with sdk.Dec as weight)
|
|
// to v1 weighted votes (with string as weight)
|
|
func migrateVotes(store storetypes.KVStore, cdc codec.BinaryCodec) error {
|
|
votesStore := prefix.NewStore(store, v1.VotesKeyPrefix)
|
|
|
|
iter := votesStore.Iterator(nil, nil)
|
|
defer iter.Close()
|
|
|
|
for ; iter.Valid(); iter.Next() {
|
|
var oldVote govv1beta1.Vote
|
|
err := cdc.Unmarshal(iter.Value(), &oldVote)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
newVote := govv1.Vote{
|
|
ProposalId: oldVote.ProposalId,
|
|
Voter: oldVote.Voter,
|
|
}
|
|
newOptions := make([]*govv1.WeightedVoteOption, len(oldVote.Options))
|
|
for i, o := range oldVote.Options {
|
|
newOptions[i] = &govv1.WeightedVoteOption{
|
|
Option: govv1.VoteOption(o.Option),
|
|
Weight: o.Weight.String(), // Convert to decimal string
|
|
}
|
|
}
|
|
newVote.Options = newOptions
|
|
bz, err := cdc.Marshal(&newVote)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set new value on store.
|
|
votesStore.Set(iter.Key(), bz)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MigrateStore performs in-place store migrations from v2 (v0.43) to v3 (v0.46). The
|
|
// migration includes:
|
|
//
|
|
// - Migrate proposals to be Msg-based.
|
|
func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, cdc codec.BinaryCodec) error {
|
|
store := storeService.OpenKVStore(ctx)
|
|
|
|
if err := migrateVotes(runtime.KVStoreAdapter(store), cdc); err != nil {
|
|
return err
|
|
}
|
|
|
|
return migrateProposals(runtime.KVStoreAdapter(store), cdc)
|
|
}
|