Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove deprecated vote option #10854

Merged
merged 16 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 85 additions & 151 deletions api/cosmos/gov/v1beta2/gov.pulsar.go

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions orm/internal/testpb/bank.pulsar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package testpb

import (
fmt "fmt"
io "io"
reflect "reflect"
sync "sync"

runtime "github.com/cosmos/cosmos-proto/runtime"
_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"

_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
io "io"
reflect "reflect"
sync "sync"
)

var (
Expand Down
5 changes: 1 addition & 4 deletions proto/cosmos/gov/v1beta2/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ message TallyResult {
message Vote {
uint64 proposal_id = 1;
string voter = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Deprecated: Prefer to use `options` instead. This field is set in queries
// if and only if `len(options) == 1` and that option has weight 1. In all
// other cases, this field will default to VOTE_OPTION_UNSPECIFIED.
VoteOption option = 3 [deprecated = true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a reserved 3

reserved 3;
repeated WeightedVoteOption options = 4;
}

Expand Down
1 change: 0 additions & 1 deletion x/gov/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (q Keeper) Votes(c context.Context, req *v1beta2.QueryVotesRequest) (*v1bet
if err := q.cdc.Unmarshal(value, &vote); err != nil {
return err
}
populateLegacyOption(&vote)

votes = append(votes, &vote)
return nil
Expand Down
13 changes: 0 additions & 13 deletions x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (keeper Keeper) AddVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A
// GetAllVotes returns all the votes from the store
func (keeper Keeper) GetAllVotes(ctx sdk.Context) (votes v1beta2.Votes) {
keeper.IterateAllVotes(ctx, func(vote v1beta2.Vote) bool {
populateLegacyOption(&vote)
votes = append(votes, &vote)
return false
})
Expand All @@ -55,7 +54,6 @@ func (keeper Keeper) GetAllVotes(ctx sdk.Context) (votes v1beta2.Votes) {
// GetVotes returns all the votes from a proposal
func (keeper Keeper) GetVotes(ctx sdk.Context, proposalID uint64) (votes v1beta2.Votes) {
keeper.IterateVotes(ctx, proposalID, func(vote v1beta2.Vote) bool {
populateLegacyOption(&vote)
votes = append(votes, &vote)
return false
})
Expand All @@ -71,7 +69,6 @@ func (keeper Keeper) GetVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.A
}

keeper.cdc.MustUnmarshal(bz, &vote)
populateLegacyOption(&vote)

return vote, true
}
Expand Down Expand Up @@ -101,7 +98,6 @@ func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1beta2.Vote)
for ; iterator.Valid(); iterator.Next() {
var vote v1beta2.Vote
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
populateLegacyOption(&vote)

if cb(vote) {
break
Expand All @@ -118,7 +114,6 @@ func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vo
for ; iterator.Valid(); iterator.Next() {
var vote v1beta2.Vote
keeper.cdc.MustUnmarshal(iterator.Value(), &vote)
populateLegacyOption(&vote)

if cb(vote) {
break
Expand All @@ -131,11 +126,3 @@ func (keeper Keeper) deleteVote(ctx sdk.Context, proposalID uint64, voterAddr sd
store := ctx.KVStore(keeper.storeKey)
store.Delete(types.VoteKey(proposalID, voterAddr))
}

// populateLegacyOption adds graceful fallback of deprecated `Option` field, in case
// there's only 1 VoteOption.
func populateLegacyOption(vote *v1beta2.Vote) {
if len(vote.Options) == 1 && sdk.MustNewDecFromStr(vote.Options[0].Weight).Equal(sdk.MustNewDecFromStr("1.0")) {
vote.Option = vote.Options[0].Option // nolint
}
}
178 changes: 69 additions & 109 deletions x/gov/types/v1beta2/gov.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.