2018-11-19 09:02:34 -08:00
|
|
|
package utils
|
2018-10-24 06:19:48 -07:00
|
|
|
|
2020-10-29 02:26:51 -07:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
)
|
2019-04-30 09:31:38 -07:00
|
|
|
|
2018-10-24 06:19:48 -07:00
|
|
|
// NormalizeVoteOption - normalize user specified vote option
|
|
|
|
func NormalizeVoteOption(option string) string {
|
|
|
|
switch option {
|
|
|
|
case "Yes", "yes":
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.OptionYes.String()
|
2019-04-30 09:31:38 -07:00
|
|
|
|
2018-10-24 06:19:48 -07:00
|
|
|
case "Abstain", "abstain":
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.OptionAbstain.String()
|
2019-04-30 09:31:38 -07:00
|
|
|
|
2018-10-24 06:19:48 -07:00
|
|
|
case "No", "no":
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.OptionNo.String()
|
2019-04-30 09:31:38 -07:00
|
|
|
|
2018-10-24 06:19:48 -07:00
|
|
|
case "NoWithVeto", "no_with_veto":
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.OptionNoWithVeto.String()
|
2019-04-30 09:31:38 -07:00
|
|
|
|
|
|
|
default:
|
2020-08-13 06:20:02 -07:00
|
|
|
return option
|
2018-10-24 06:19:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 06:14:39 -07:00
|
|
|
// NormalizeWeightedVoteOptions - normalize normalize vote options param string
|
|
|
|
func NormalizeWeightedVoteOptions(options string) string {
|
|
|
|
newOptions := []string{}
|
|
|
|
for _, option := range strings.Split(options, ",") {
|
|
|
|
fields := strings.Split(option, "=")
|
2020-10-29 02:26:51 -07:00
|
|
|
fields[0] = NormalizeVoteOption(fields[0])
|
|
|
|
if len(fields) < 2 {
|
|
|
|
fields = append(fields, "1")
|
|
|
|
}
|
2020-10-30 06:14:39 -07:00
|
|
|
newOptions = append(newOptions, strings.Join(fields, "="))
|
2020-10-29 02:26:51 -07:00
|
|
|
}
|
2020-10-30 06:14:39 -07:00
|
|
|
return strings.Join(newOptions, ",")
|
2020-10-29 02:26:51 -07:00
|
|
|
}
|
|
|
|
|
2018-10-24 06:19:48 -07:00
|
|
|
//NormalizeProposalType - normalize user specified proposal type
|
|
|
|
func NormalizeProposalType(proposalType string) string {
|
|
|
|
switch proposalType {
|
|
|
|
case "Text", "text":
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.ProposalTypeText
|
2019-04-30 09:31:38 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
return ""
|
2018-10-24 06:19:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//NormalizeProposalStatus - normalize user specified proposal status
|
|
|
|
func NormalizeProposalStatus(status string) string {
|
|
|
|
switch status {
|
|
|
|
case "DepositPeriod", "deposit_period":
|
|
|
|
return "DepositPeriod"
|
|
|
|
case "VotingPeriod", "voting_period":
|
|
|
|
return "VotingPeriod"
|
|
|
|
case "Passed", "passed":
|
|
|
|
return "Passed"
|
|
|
|
case "Rejected", "rejected":
|
|
|
|
return "Rejected"
|
2020-08-11 07:22:30 -07:00
|
|
|
default:
|
|
|
|
return status
|
2018-10-24 06:19:48 -07:00
|
|
|
}
|
|
|
|
}
|