Ref: #9810 Moves all legacy gov code to `v1beta1`. This preserves all existing behavior (i.e. everything still uses v1beta1). It's merely moving things around to get everything in the right place logistically (hence the large diff still) --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package utils
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
)
|
|
|
|
// NormalizeVoteOption - normalize user specified vote option
|
|
func NormalizeVoteOption(option string) string {
|
|
switch option {
|
|
case "Yes", "yes":
|
|
return v1beta1.OptionYes.String()
|
|
|
|
case "Abstain", "abstain":
|
|
return v1beta1.OptionAbstain.String()
|
|
|
|
case "No", "no":
|
|
return v1beta1.OptionNo.String()
|
|
|
|
case "NoWithVeto", "no_with_veto":
|
|
return v1beta1.OptionNoWithVeto.String()
|
|
|
|
default:
|
|
return option
|
|
}
|
|
}
|
|
|
|
// NormalizeWeightedVoteOptions - normalize vote options param string
|
|
func NormalizeWeightedVoteOptions(options string) string {
|
|
newOptions := []string{}
|
|
for _, option := range strings.Split(options, ",") {
|
|
fields := strings.Split(option, "=")
|
|
fields[0] = NormalizeVoteOption(fields[0])
|
|
if len(fields) < 2 {
|
|
fields = append(fields, "1")
|
|
}
|
|
newOptions = append(newOptions, strings.Join(fields, "="))
|
|
}
|
|
return strings.Join(newOptions, ",")
|
|
}
|
|
|
|
// NormalizeProposalType - normalize user specified proposal type.
|
|
func NormalizeProposalType(proposalType string) string {
|
|
switch proposalType {
|
|
case "Text", "text":
|
|
return v1beta1.ProposalTypeText
|
|
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
// NormalizeProposalStatus - normalize user specified proposal status.
|
|
func NormalizeProposalStatus(status string) string {
|
|
switch status {
|
|
case "DepositPeriod", "deposit_period":
|
|
return v1beta1.StatusDepositPeriod.String()
|
|
case "VotingPeriod", "voting_period":
|
|
return v1beta1.StatusVotingPeriod.String()
|
|
case "Passed", "passed":
|
|
return v1beta1.StatusPassed.String()
|
|
case "Rejected", "rejected":
|
|
return v1beta1.StatusRejected.String()
|
|
default:
|
|
return status
|
|
}
|
|
}
|